-
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.
✨ [#5012] Add JSON dump registration variables
- Loading branch information
1 parent
5afe627
commit 67a1ce0
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/openforms/registrations/contrib/json_dump/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,62 @@ | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from openforms.plugins.registry import BaseRegistry | ||
from openforms.submissions.models import Submission | ||
from openforms.typing import JSONObject | ||
from openforms.variables.base import BaseStaticVariable | ||
from openforms.variables.constants import FormVariableDataTypes | ||
from openforms.variables.static_variables.static_variables import Now | ||
|
||
|
||
class Registry(BaseRegistry[BaseStaticVariable]): | ||
""" | ||
A registry for the JSON Dump registration variables. | ||
""" | ||
|
||
module = "json_dump" | ||
|
||
|
||
register = Registry() | ||
"""The JSON Dump registration variables registry.""" | ||
|
||
|
||
@register("public_reference") | ||
class PublicReference(BaseStaticVariable): | ||
name = _("Public reference") | ||
data_type = FormVariableDataTypes.string | ||
|
||
def get_initial_value(self, submission: Submission | None = None) -> str: | ||
if submission is None: | ||
return "" | ||
return submission.public_registration_reference | ||
|
||
def as_json_schema(self) -> JSONObject: | ||
return {"title": "Public reference", "type": "string"} | ||
|
||
|
||
@register("form_version") | ||
class FormVersion(BaseStaticVariable): | ||
name = _("Form version") | ||
data_type = FormVariableDataTypes.string | ||
|
||
def get_initial_value(self, submission: Submission | None = None) -> str: | ||
if submission is None: | ||
return "" | ||
|
||
form_version = submission.form.formversion_set.order_by("created").last() | ||
return form_version.description if form_version else "" | ||
|
||
def as_json_schema(self) -> JSONObject: | ||
return {"title": "Form version", "type": "string"} | ||
|
||
|
||
@register("registration_timestamp") | ||
class RegistrationTimestamp(Now): | ||
name = _("Registration timestamp") | ||
|
||
def as_json_schema(self) -> JSONObject: | ||
return { | ||
"title": "Registration timestamp", | ||
"type": "string", | ||
"format": "date-time", | ||
} |