Skip to content
Snippets Groups Projects
Verified Commit c8221eb1 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Allow post-processing fields with templates

parent a6ff3426
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ Added
* ZIP files with multiple CSVs and accompanying photos can now be imported
* Field types can now provide values for arbitrary alternative DB fields
* Virtual fields can be generated from literal fields using Django templates
* Field data can be post-processed using Django templates
* Fields for Group.parent_groups and Person.member_of
Fixed
......
......@@ -130,17 +130,19 @@ def import_csv(
iterator = recorder.iterate(data_as_dict) if recorder else tqdm(data_as_dict)
for row in iterator:
# Generate virtual field data
for column_name in virtual_fields:
field_type = field_types[column_name]
# Generate virtual and post-processed field data
for column_name, field_type in field_types:
# Generate field using a Django template string, and the row as context
tmpl = Template(field_type.get_template())
tmpl_str = field_type.get_template()
if not tmpl_str:
continue
tmpl = Template(tmpl_str)
ctx = Context(row)
data = tmpl.render(ctx).strip()
# Post-process field using converter
data = field_type.get_converter()(data)
if column_name in virtual_fields:
# Post-process virtual fields using converter
data = field_type.get_converter()(data)
# Store
row[column_name] = data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment