-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3984 from open-formulieren/feature/3688-registrat…
…ion-variables Add logic for the new registration (static) variables
- Loading branch information
Showing
17 changed files
with
1,968 additions
and
1,307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...openforms/registrations/contrib/objects_api/migrations/0013_objectsapiregistrationdata.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Generated by Django 4.2.10 on 2024-03-13 10:39 | ||
|
||
import django.contrib.postgres.fields | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("submissions", "0004_auto_20231128_1536"), | ||
("registrations_objects_api", "0012_fill_required_fields"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ObjectsAPIRegistrationData", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"pdf_url", | ||
models.URLField( | ||
blank=True, | ||
help_text="The PDF URL of the document on the Documents API.", | ||
verbose_name="pdf url", | ||
), | ||
), | ||
( | ||
"csv_url", | ||
models.URLField( | ||
blank=True, | ||
help_text="The CSV URL of the document on the Documents API.", | ||
verbose_name="csv url", | ||
), | ||
), | ||
( | ||
"attachment_urls", | ||
django.contrib.postgres.fields.ArrayField( | ||
base_field=models.URLField( | ||
help_text="The attachment URL on the Documents API.", | ||
verbose_name="attachment url", | ||
), | ||
blank=True, | ||
default=list, | ||
help_text="The list of attachment URLs on the Documents API.", | ||
size=None, | ||
verbose_name="attachment urls", | ||
), | ||
), | ||
( | ||
"submission", | ||
models.OneToOneField( | ||
help_text="The submission linked to the registration data.", | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="objects_api_registration_data", | ||
to="submissions.submission", | ||
verbose_name="submission", | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/openforms/registrations/contrib/objects_api/registration_variables.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from openforms.plugins.registry import BaseRegistry | ||
from openforms.variables.base import BaseStaticVariable | ||
from openforms.variables.constants import FormVariableDataTypes | ||
|
||
if TYPE_CHECKING: | ||
from openforms.submissions.models import Submission | ||
|
||
|
||
class Registry(BaseRegistry[BaseStaticVariable]): | ||
""" | ||
A registry for the Objects API registration variables. | ||
""" | ||
|
||
module = "objects_api" | ||
|
||
|
||
register = Registry() | ||
"""The Objects API registration variables registry.""" | ||
|
||
|
||
@register("pdf_url") | ||
class PdfUrl(BaseStaticVariable): | ||
name = _("PDF Url") | ||
data_type = FormVariableDataTypes.string | ||
|
||
def get_initial_value(self, submission: Submission | None = None): | ||
if submission is None: | ||
return None | ||
return submission.objects_api_registration_data.pdf_url | ||
|
||
|
||
@register("csv_url") | ||
class CsvUrl(BaseStaticVariable): | ||
name = _("CSV Url") | ||
data_type = FormVariableDataTypes.string | ||
|
||
def get_initial_value(self, submission: Submission | None = None): | ||
if submission is None: | ||
return None | ||
return submission.objects_api_registration_data.csv_url | ||
|
||
|
||
@register("attachment_urls") | ||
class AttachmentUrls(BaseStaticVariable): | ||
name = _("Attachment Urls") | ||
data_type = FormVariableDataTypes.array | ||
|
||
def get_initial_value(self, submission: Submission | None = None): | ||
if submission is None: | ||
return None | ||
return submission.objects_api_registration_data.attachment_urls | ||
|
||
|
||
@register("payment_completed") | ||
class PaymentCompleted(BaseStaticVariable): | ||
name = _("Payment completed") | ||
data_type = FormVariableDataTypes.boolean | ||
|
||
def get_initial_value(self, submission: Submission | None = None): | ||
if submission is None: | ||
return None | ||
return submission.payment_user_has_paid | ||
|
||
|
||
@register("payment_amount") | ||
class PaymentAmount(BaseStaticVariable): | ||
name = _("Payment amount") | ||
data_type = FormVariableDataTypes.string | ||
|
||
def get_initial_value(self, submission: Submission | None = None): | ||
if submission is None: | ||
return None | ||
return str(submission.payments.sum_amount()) | ||
|
||
|
||
@register("payment_public_order_ids") | ||
class PaymentPublicOrderIds(BaseStaticVariable): | ||
name = _("Payment public order IDs") | ||
data_type = FormVariableDataTypes.array | ||
|
||
def get_initial_value(self, submission: Submission | None = None): | ||
if submission is None: | ||
return None | ||
return submission.payments.get_completed_public_order_ids() |
Oops, something went wrong.