Skip to content

Commit

Permalink
add: allow for mapping of values
Browse files Browse the repository at this point in the history
  • Loading branch information
saemideluxe committed Aug 17, 2023
1 parent 13b925e commit 6e27f0d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
5 changes: 5 additions & 0 deletions basxbread/contrib/customforms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion basxbread/contrib/customforms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions basxbread/contrib/customforms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6e27f0d

Please sign in to comment.