mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-07-04 20:11:45 +02:00
Merge pull request #97
feat(import:v1): accept list as source, first valid one will be used.
This commit is contained in:
@@ -65,7 +65,7 @@ class CSVImportSettings(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class ColumnMapping(BaseModel):
|
class ColumnMapping(BaseModel):
|
||||||
source: Optional[str] = Field(
|
source: Optional[str] | Optional[list[str]] = Field(
|
||||||
default=None,
|
default=None,
|
||||||
description="CSV column header. If None, the field will be generated from transformations",
|
description="CSV column header. If None, the field will be generated from transformations",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -486,8 +486,18 @@ class ImportService:
|
|||||||
mapped_data = {}
|
mapped_data = {}
|
||||||
|
|
||||||
for field, mapping in self.mapping.items():
|
for field, mapping in self.mapping.items():
|
||||||
# If source is None, use None as the initial value
|
value = None
|
||||||
value = row.get(mapping.source) if mapping.source else None
|
|
||||||
|
if isinstance(mapping.source, str):
|
||||||
|
value = row.get(mapping.source)
|
||||||
|
elif isinstance(mapping.source, list):
|
||||||
|
for source in mapping.source:
|
||||||
|
value = row.get(source)
|
||||||
|
if value is not None:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# If source is None, use None as the initial value
|
||||||
|
value = None
|
||||||
|
|
||||||
# Use default_value if value is None
|
# Use default_value if value is None
|
||||||
if value is None:
|
if value is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user