@@ -685,6 +685,7 @@ def diag_routes():
685685
686686#########################################################
687687
688+ # -- View and import (admin + Public) --
688689# -- View and import (admin + Public) --
689690@app .route ('/materials/<property_name>/<tab>' , methods = ['GET' , 'POST' ])
690691def property_detail (property_name , tab ):
@@ -713,6 +714,12 @@ def _extract_drive_id(link_or_id: str):
713714 return s
714715 return None
715716
717+ # Make sure schema exists (columns like storage/preview_url/etc.)
718+ try :
719+ ensure_uploads_log_schema ()
720+ except Exception as e :
721+ app .logger .warning ("ensure_uploads_log_schema: %s" , e )
722+
716723 # ---- admin POST handlers ----
717724 if is_admin and request .method == 'POST' :
718725 # 1) Add Drive entry
@@ -725,7 +732,7 @@ def _extract_drive_id(link_or_id: str):
725732 # Basic ext check from label to keep tabs consistent
726733 ext = (label .rsplit ('.' , 1 )[- 1 ].lower () if '.' in label else '' )
727734 if tab == 'dataset' and ext not in ALLOWED_DATASET_EXTENSIONS :
728- upload_message = f "Label must end with .csv or .npy for datasets."
735+ upload_message = "Label must end with .csv or .npy for datasets."
729736 elif tab == 'results' and ext not in ALLOWED_RESULTS_EXTENSIONS :
730737 upload_message = f"Label must be one of: { ', ' .join (sorted (ALLOWED_RESULTS_EXTENSIONS ))} ."
731738 else :
@@ -735,22 +742,23 @@ def _extract_drive_id(link_or_id: str):
735742 else :
736743 preview_url = f"https://drive.google.com/file/d/{ file_id } /preview"
737744 download_url = f"https://drive.google.com/uc?export=download&id={ file_id } "
738- # Upsert into uploads_log (Drive-first)
739745 with sqlite3 .connect (DB_NAME ) as conn :
740746 c = conn .cursor ()
741747 c .execute (
742748 """
743749 INSERT INTO uploads_log
744- (property, tab, filename, uploaded_at, storage, drive_id, preview_url, download_url, source, description)
745- VALUES (?, ?, ?, CURRENT_TIMESTAMP, 'drive', ?, ?, ?, ?, ?)
750+ (property, tab, filename, uploaded_at,
751+ storage, drive_id, preview_url, download_url, source, description)
752+ VALUES (?, ?, ?, CURRENT_TIMESTAMP,
753+ 'drive', ?, ?, ?, ?, ?)
746754 ON CONFLICT(property, tab, filename)
747755 DO UPDATE SET
748756 uploaded_at = CURRENT_TIMESTAMP,
749- storage = 'drive',
750- drive_id = excluded.drive_id,
757+ storage = 'drive',
758+ drive_id = excluded.drive_id,
751759 preview_url = excluded.preview_url,
752- download_url = excluded.download_url,
753- source = COALESCE(excluded.source, uploads_log.source),
760+ download_url= excluded.download_url,
761+ source = COALESCE(excluded.source, uploads_log.source),
754762 description = COALESCE(excluded.description, uploads_log.description)
755763 """ ,
756764 (property_name , tab , label , file_id , preview_url , download_url , new_source , new_desc ),
@@ -786,36 +794,35 @@ def _extract_drive_id(link_or_id: str):
786794 conn .commit ()
787795 edit_message = f"Updated info for { row_filename } ."
788796
789- # ---- fetch current uploads (public catalog ) ----
797+ # ---- fetch current uploads as plain dicts (so Jinja `row.filename` works ) ----
790798 with sqlite3 .connect (DB_NAME ) as conn :
791799 conn .row_factory = sqlite3 .Row
792800 c = conn .cursor ()
793801 c .execute (
794802 """
795- SELECT filename,
796- COALESCE(source,'') AS source,
797- COALESCE(description,'') AS description,
798- uploaded_at,
799- COALESCE(storage,'local') AS storage,
800- preview_url,
801- download_url
803+ SELECT
804+ filename,
805+ COALESCE(source,'') AS source,
806+ COALESCE(description,'') AS description,
807+ uploaded_at,
808+ COALESCE(storage,'local') AS storage,
809+ COALESCE(preview_url,'') AS preview_url,
810+ COALESCE(download_url,'') AS download_url
802811 FROM uploads_log
803812 WHERE property = ? AND tab = ?
804813 ORDER BY uploaded_at DESC, filename
805814 """ ,
806815 (property_name , tab ),
807816 )
808- uploads = c .fetchall ()
817+ uploads = [ dict ( r ) for r in c .fetchall ()]
809818
810- # Map local dataset filenames to SQL table names (for "View" link )
819+ # Map local dataset filenames to SQL table names (for potential view links )
811820 table_map = {}
812821 if tab == 'dataset' :
813- table_map = {}
814822 for row in uploads :
815- storage = (row ['storage' ] or 'local' )
816- if storage != 'drive' :
817- fname = row ['filename' ]
818- if fname and (fname .endswith ('.csv' ) or fname .endswith ('.npy' )):
823+ if row .get ('storage' ) != 'drive' :
824+ fname = row .get ('filename' , '' )
825+ if fname .endswith ('.csv' ) or fname .endswith ('.npy' ):
819826 table_map [fname ] = file_to_table_name (fname )
820827
821828 return render_template (
@@ -829,6 +836,7 @@ def _extract_drive_id(link_or_id: str):
829836 admin = is_admin ,
830837 table_map = table_map ,
831838 )
839+
832840
833841#########################################################
834842
0 commit comments