-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logic for the new registration (static) variables #3984
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
66f9340
[#3688] Add `StrOrPromise` as a public type hint
Viicos d3b6e28
[#3688] Refactor base static variable a bit
Viicos 6a162c7
[#3688] Add a new `get_variables_registry` method to registration plu…
Viicos 33b4fb1
[#3688] Add a new model to store temporary results
Viicos e509514
[#3688] Add registry and static variables for Objects API
Viicos 11bca9a
[#3688] Refactor registration handlers
Viicos b8e0de7
[#3688] Add endpoint to get available registration variables
Viicos 44bca03
[#3688] Add tests for new endpoint
Viicos a8a34cd
[#3688] Add test for `save_and_raise` ctxmanager
Viicos d4845fc
[#3688] PR feedback
Viicos 86401a6
[#3688] Adapt tests
Viicos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is too naive, you lose the information of which file/component the Document URL belongs too.
I'd still prefer to have the variable of a file upload explicitly mapped into the schema, e.g. something like:
so that you can make the (single) file upload "proof of employment" to
/proofOfEmployment
and the multi-file upload "bank statements" to/bankStatements
Possibly we do this in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering this requires thinking and probably some work, it will probably be part of the next PR