From 7672aca7a97502ea75ae872a44f4e99e0f7970c0 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 18 Dec 2018 17:21:21 -0400 Subject: [PATCH] Add button widget for forms This widget will allow displaying HTML anchor buttons inside the forms. It uses by default the navigation instance template from the navigation app. Signed-off-by: Roberto Rosario --- .../templates/common/forms/widgets/button_widget.html | 3 +++ mayan/apps/common/widgets.py | 9 +++++++++ 2 files changed, 12 insertions(+) create mode 100644 mayan/apps/common/templates/common/forms/widgets/button_widget.html diff --git a/mayan/apps/common/templates/common/forms/widgets/button_widget.html b/mayan/apps/common/templates/common/forms/widgets/button_widget.html new file mode 100644 index 0000000000..0009ff15e5 --- /dev/null +++ b/mayan/apps/common/templates/common/forms/widgets/button_widget.html @@ -0,0 +1,3 @@ +{% with widget.value as link %} + {% include 'navigation/generic_link_instance.html' %} +{% endwith %} diff --git a/mayan/apps/common/widgets.py b/mayan/apps/common/widgets.py index d65b62e137..01d4c63af7 100644 --- a/mayan/apps/common/widgets.py +++ b/mayan/apps/common/widgets.py @@ -9,6 +9,15 @@ from .icons import icon_fail as default_icon_fail from .icons import icon_ok as default_icon_ok +class ButtonWidget(forms.widgets.Widget): + template_name = 'common/forms/widgets/button_widget.html' + + def format_value(self, value): + if value == '' or value is None: + return None + return value + + class DisableableSelectWidget(forms.SelectMultiple): allow_multiple_selected = True