@@ -311,6 +311,7 @@ def _add_collection_fields(fields_dir: Path, collections_df: pd.DataFrame) -> pd
311311 "field_name" : [],
312312 "csv_headers" : [],
313313 "labels" : [],
314+ "positions" : [],
314315 "title_fields" : [],
315316 }
316317 for k , v in fields_dfs .items ():
@@ -328,6 +329,12 @@ def _add_collection_fields(fields_dir: Path, collections_df: pd.DataFrame) -> pd
328329 data ["labels" ].append (
329330 [{"de" : ld , "en" : le } for ld , le in zip (list (v ["label_de" ]), list (v ["label_en" ]))]
330331 )
332+
333+ # Extract position field if it exists
334+ if "position" in list (v .columns ):
335+ data ["positions" ].append (v ["position" ].values )
336+ else :
337+ data ["positions" ].append ([None ] * len (v ))
331338
332339 title_fields = {}
333340 for _ , row in v .iterrows ():
@@ -359,16 +366,19 @@ def _add_collection_fields(fields_dir: Path, collections_df: pd.DataFrame) -> pd
359366
360367 fns = row ["field_name" ]
361368 labels = row ["labels" ]
369+ positions = row ["positions" ]
362370 fields = []
363- for fn , label in zip (fns , labels ):
371+ for fn , label , pos in zip (fns , labels , positions ):
364372 ld , le = label ["de" ], label ["en" ]
373+ # Skip fields without labels (they should not be displayed)
365374 if (ld is None or ld == "" ) and (le is None or le == "" ):
366375 continue
367376 fields .append (
368377 {
369378 "name" : fn ,
370379 "label_de" : ld ,
371380 "label_en" : le ,
381+ "position" : int (pos ) if pos is not None and not pd .isna (pos ) else None ,
372382 }
373383 )
374384 data ["fields" ].append (fields )
@@ -430,6 +440,26 @@ def _resolve_image_paths(records_df: pd.DataFrame, record_pix_dir: Path, worker_
430440 return records_df
431441
432442
443+ def _filter_record_details (row , collections_df : pd .DataFrame ) -> dict [str , str ]:
444+ """
445+ Filter record details to only include fields that are visible for the collection.
446+ Fields are visible if they have a label defined in the collection's field configuration.
447+ """
448+ collection_name = row ["collection_name" ]
449+ collection = collections_df [collections_df .collection_name == collection_name ].iloc [0 ]
450+ visible_field_names = {field ["name" ] for field in collection .fields }
451+
452+ # Extract all detail fields from the row
453+ all_details = {
454+ k .replace ("details_" , "" ): v for k , v in row .items () if k .startswith ("details_" ) and v is not None and v != ""
455+ }
456+
457+ # Filter to only include visible fields
458+ filtered_details = {k : v for k , v in all_details .items () if k in visible_field_names }
459+
460+ return filtered_details
461+
462+
433463def _get_record_title (row , collections_df : pd .DataFrame ) -> str :
434464 collection_name = row ["collection_name" ]
435465 collection = collections_df [collections_df .collection_name == collection_name ].iloc [0 ]
@@ -478,6 +508,24 @@ def _create_records_df(
478508 axis = 1 ,
479509 ).drop ("details" , axis = 1 )
480510
511+ # Filter details columns to only include fields visible for each collection
512+ def filter_details_for_collection (row , collections_df ):
513+ collection_name = row ["collection_name" ]
514+ collection = collections_df [collections_df .collection_name == collection_name ].iloc [0 ]
515+ visible_field_names = {field ["name" ] for field in collection .fields }
516+
517+ # Create a new row with only visible detail fields
518+ filtered_row = {k : v for k , v in row .items () if not k .startswith ("details_" )}
519+ for k , v in row .items ():
520+ if k .startswith ("details_" ):
521+ field_name = k .replace ("details_" , "" )
522+ if field_name in visible_field_names :
523+ filtered_row [k ] = v
524+
525+ return pd .Series (filtered_row )
526+
527+ records_df = records_df .apply (lambda x : filter_details_for_collection (x , collections_df ), axis = 1 )
528+
481529 # Add title
482530 records_df ["title" ] = records_df .apply (lambda x : _get_record_title (x , collections_df ), axis = 1 )
483531 title = records_df .pop ("title" )
0 commit comments