feat(csv-import): Enhance source unit handling and custom conversion options
- Updated the source_unit_choices_for_field function to include a custom option for user-defined conversion factors, improving flexibility in unit conversions. - Modified the AdminCsvTemplateEditorPage to support custom conversion factors, allowing users to input specific scaling factors for their data. - Added tests to ensure the custom option is correctly included in the source unit choices and functions as expected in the template editor.
This commit is contained in:
1 parent
bb6eefc837
commit
fe7a69fb07
3 files changed
+120
-30
No files matched your search
@@ -68,7 +68,7 @@ def source_unit_choices_for_field(module: str, db_field: str) -> list[dict[str,
|
||||
choices = _UNIT_FAMILY.get(cu)
|
||||
if not choices:
|
||||
return []
|
||||
return [
|
||||
out: list[dict[str, Any]] = [
|
||||
{
|
||||
"id": c["id"],
|
||||
"label": c["label"],
|
||||
@@ -77,6 +77,15 @@ def source_unit_choices_for_field(module: str, db_field: str) -> list[dict[str,
|
||||
}
|
||||
for c in choices
|
||||
]
|
||||
out.append(
|
||||
{
|
||||
"id": "custom",
|
||||
"label": "Benutzerdefiniert (Konvertierungsfaktor, z. B. ml→g je nach Dichte)",
|
||||
"canonical_unit": cu,
|
||||
"is_canonical": False,
|
||||
}
|
||||
)
|
||||
return out
|
||||
|
||||
|
||||
def factor_source_to_canonical(module: str, db_field: str, source_unit: str | None) -> float:
|
||||
|
||||
Reference in new issue
Block a user