Add spreadsheet enhancements and default handling
Implemented a toggleable spreadsheet UI component for sample data, added fields such as priority and comments, and improved backend validation. Default values for "directory" are now assigned when missing, with feedback highlighted in green on the front end.
This commit is contained in:
@ -48,17 +48,6 @@ class SampleSpreadsheetImporter:
|
||||
def import_spreadsheet(self, file):
|
||||
return self.import_spreadsheet_with_errors(file)
|
||||
|
||||
def get_expected_type(self, col_name):
|
||||
type_mapping = {
|
||||
"dewarname": str,
|
||||
"puckname": str,
|
||||
"positioninpuck": int,
|
||||
"priority": int,
|
||||
"oscillation": float,
|
||||
# Add all other mappings based on model requirements
|
||||
}
|
||||
return type_mapping.get(col_name, str) # Default to `str`
|
||||
|
||||
def import_spreadsheet_with_errors(
|
||||
self, file
|
||||
) -> Tuple[List[SpreadsheetModel], List[dict], List[dict], List[str]]:
|
||||
@ -194,6 +183,20 @@ class SampleSpreadsheetImporter:
|
||||
|
||||
try:
|
||||
validated_record = SpreadsheetModel(**record)
|
||||
# Update the raw data with assigned default values
|
||||
if (
|
||||
validated_record.directory == "{sgPuck}/{sgPosition}"
|
||||
and row[7] is None
|
||||
):
|
||||
row_list = list(row)
|
||||
row_list[
|
||||
7
|
||||
] = validated_record.directory # Set the field to the default value
|
||||
raw_data[-1]["data"] = row_list
|
||||
raw_data[-1][
|
||||
"default_set"
|
||||
] = True # Mark this row as having a default value assigned
|
||||
|
||||
model.append(validated_record)
|
||||
logger.debug(f"Row {index + 4} processed and validated successfully")
|
||||
except ValidationError as e:
|
||||
|
Reference in New Issue
Block a user