diff --git a/basxbread/contrib/customforms/migrations/0004_alter_pdfformfield_unique_together_pdfformfield_join_and_more.py b/basxbread/contrib/customforms/migrations/0004_alter_pdfformfield_unique_together_pdfformfield_join_and_more.py index e0b8114d..4f281958 100644 --- a/basxbread/contrib/customforms/migrations/0004_alter_pdfformfield_unique_together_pdfformfield_join_and_more.py +++ b/basxbread/contrib/customforms/migrations/0004_alter_pdfformfield_unique_together_pdfformfield_join_and_more.py @@ -1,7 +1,7 @@ # Generated by Django 4.1.7 on 2023-08-16 11:59 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/basxbread/contrib/customforms/migrations/0005_pdfformfield_mapping.py b/basxbread/contrib/customforms/migrations/0005_pdfformfield_mapping.py new file mode 100644 index 00000000..2ffe610a --- /dev/null +++ b/basxbread/contrib/customforms/migrations/0005_pdfformfield_mapping.py @@ -0,0 +1,25 @@ +# Generated by Django 4.1.7 on 2023-08-17 05:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ( + "customforms", + "0004_alter_pdfformfield_unique_together_pdfformfield_join_and_more", + ), + ] + + operations = [ + migrations.AddField( + model_name="pdfformfield", + name="mapping", + field=models.JSONField( + blank=True, + default=dict, + help_text="Map PDF-field value", + verbose_name="Map value", + ), + ), + ] diff --git a/basxbread/contrib/customforms/models.py b/basxbread/contrib/customforms/models.py index 95f1deee..3485ddd7 100644 --- a/basxbread/contrib/customforms/models.py +++ b/basxbread/contrib/customforms/models.py @@ -127,6 +127,11 @@ class PDFFormField(models.Model): ) join.formfield_kwargs = {"strip": False} + mapping = models.JSONField( + _("Map value"), help_text=_("Map PDF-field value"), default=dict, blank=True + ) + mapping.formfield_kwargs = {"widget": forms.Textarea(attrs={"rows": 1})} + @property def fieldname(self): return self.customform_field.fieldname if self.customform_field else None diff --git a/basxbread/contrib/customforms/urls.py b/basxbread/contrib/customforms/urls.py index c2bb8293..a240b681 100644 --- a/basxbread/contrib/customforms/urls.py +++ b/basxbread/contrib/customforms/urls.py @@ -56,7 +56,7 @@ "pdf", "customform", layout.forms.Formset.as_inline_datatable( - "fields", ["pdf_field_name", "customform_field", "join"] + "fields", ["pdf_field_name", "customform_field", "join", "mapping"] ), ], default_success_page="edit", diff --git a/basxbread/contrib/customforms/views.py b/basxbread/contrib/customforms/views.py index 63f1e441..2a00646a 100644 --- a/basxbread/contrib/customforms/views.py +++ b/basxbread/contrib/customforms/views.py @@ -93,6 +93,7 @@ def pdfimportview(request, pk): initial = {} for pdf_formfield in pdfimporter.fields.exclude(customform_field=None): value = pdffields[pdf_formfield.pdf_field_name] + value = pdf_formfield.mapping.get(value, value) if "." in pdf_formfield.fieldname: ( inlinefield,