From 66f8f587ead1fa8be9894c861395932e3d7b98b7 Mon Sep 17 00:00:00 2001 From: John Kyle Cronan Date: Wed, 27 Apr 2022 19:14:25 -0500 Subject: [PATCH] admin to customize the form status message --- formative/forms/admin.py | 15 ++++++++++++++- formative/models/formative.py | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/formative/forms/admin.py b/formative/forms/admin.py index ca5d9cd..147b127 100644 --- a/formative/forms/admin.py +++ b/formative/forms/admin.py @@ -357,6 +357,18 @@ class FormAdminForm(AdminJSONForm): widget=widgets.AdminRadioSelect(attrs={'class': 'radiolist'}) ) hidden = forms.BooleanField(required=False) + enabled_message = forms.CharField(required=False, + widget=widgets.AdminTextInputWidget, + help_text='If not specified, default is "Open for submissions."' + ) + disabled_message = forms.CharField(required=False, + widget=widgets.AdminTextInputWidget, + help_text='If not specified, default is "Not yet open for submissions."' + ) + completed_message = forms.CharField(required=False, + widget=widgets.AdminTextInputWidget, + help_text='If not specified, default is "Closed."' + ) access_enable = forms.CharField(required=False, label='?access= password') review_pre = forms.CharField( required=False, widget=widgets.AdminTextareaWidget(attrs={'rows': 5}), @@ -390,7 +402,8 @@ class FormAdminForm(AdminJSONForm): class Meta: static_fields = ('program', 'name', 'slug', 'status', 'hidden') json_fields = {'options': [ - 'hidden', 'access_enable', 'review_pre', 'review_post', + 'hidden', 'enabled_message', 'disabled_message', + 'completed_message', 'access_enable', 'review_pre', 'review_post', 'submitted_review_pre', 'timed_completion', 'complete_submit_time', 'no_review_after_submit', 'thanks', 'emails' ]} diff --git a/formative/models/formative.py b/formative/models/formative.py index a70eefd..5e55e0b 100644 --- a/formative/models/formative.py +++ b/formative/models/formative.py @@ -329,9 +329,15 @@ def status_message(self): if self.status == self.Status.DRAFT: return 'NA' elif self.status == self.Status.DISABLED: + if 'disabled_message' in self.options: + return self.options['disabled_message'] return _('Not yet open for submissions') elif self.status == self.Status.COMPLETED: + if 'completed_message' in self.options: + return self.options['completed_message'] return _('Closed') + if 'enabled_message' in self.options: + return self.options['enabled_message'] return _('Open for submissions') def hidden(self):