-
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.
✨ [#1068] Add formio.formatters module
- Loading branch information
Showing
5 changed files
with
142 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.apps import AppConfig | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class FormIOFormattersApp(AppConfig): | ||
name = "openforms.formio.formatters" | ||
label = "formio_formatters" | ||
verbose_name = _("FormIO formatters") | ||
|
||
def ready(self): | ||
# register the plugin | ||
from . import default # noqa |
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 @@ | ||
# TODO implement: iban, bsn, postcode, licenseplate, npFamilyMembers, cosign, map |
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,114 @@ | ||
from typing import Any, Dict | ||
|
||
from openforms.plugins.plugin import AbstractBasePlugin | ||
|
||
from .registry import register | ||
|
||
|
||
class FormioFormatter(AbstractBasePlugin): | ||
def __call__(self, component: dict, value: Any) -> str: | ||
return self.format(component, value) | ||
|
||
def format(self, component: dict, value: Any) -> str: | ||
raise NotImplementedError("%r must implement the 'format' method" % type(self)) | ||
|
||
|
||
@register("default") | ||
class DefaultFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
if isinstance(value, list): | ||
return value | ||
return str(value) | ||
|
||
|
||
@register("textfield") | ||
class TextFieldFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
return str(value) | ||
|
||
|
||
@register("email") | ||
class EmailFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
return str(value) | ||
|
||
|
||
@register("date") | ||
class DateFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@register("time") | ||
class TimeFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@register("phoneNumber") | ||
class PhoneNumberFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@register("file") | ||
class FileFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@register("textarea") | ||
class TextAreaFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@register("number") | ||
class NumberFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@register("password") | ||
class PasswordFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@register("checkbox") | ||
class CheckboxFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@register("selectboxes") | ||
class SelectBoxesFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
selected_labels = [ | ||
entry["label"] for entry in component["values"] if value.get(entry["value"]) | ||
] | ||
return ", ".join(selected_labels) | ||
|
||
|
||
@register("select") | ||
class SelectFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@register("currency") | ||
class CurrencyFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@register("radio") | ||
class RadioFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
# @register("signature") | ||
class SignatureFormatter(FormioFormatter): | ||
def format(self, component: Dict, value: str) -> str: | ||
raise NotImplementedError |
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,14 @@ | ||
from openforms.plugins.registry import BaseRegistry | ||
|
||
|
||
class Registry(BaseRegistry): | ||
""" | ||
A registry for the FormIO formatters. | ||
""" | ||
|
||
pass | ||
|
||
|
||
# Sentinel to provide the default registry. You an easily instantiate another | ||
# :class:`Registry` object to use as dependency injection in tests. | ||
register = Registry() |