diff --git a/src/postorius/forms.py b/src/postorius/forms.py index 536194a..d9eb612 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -597,16 +597,10 @@ data = self.cleaned_data['acceptable_aliases'] return data.splitlines() - def __init__(self, visible_section, visible_option, *args, **kwargs): + def __init__(self, visible_section, *args, **kwargs): super(ListSettings, self).__init__(*args, **kwargs) # if settings: # raise Exception(settings) # debug - if visible_option: - options = [] - for option in self.layout: - options += option[1:] - if visible_option in options: - self.layout = [["", visible_option]] if visible_section: sections = [] for section in self.layout: @@ -646,9 +640,9 @@ """ # just a really temporary layout to see that it works. -- Anna layout = [ - ["List Identity", "display_name", "mail_host", "description", + ["list_identity", "display_name", "mail_host", "description", "advertised", "subject_prefix"], - ["Automatic Responses", "autorespond_owner", + ["automatic_responses", "autorespond_owner", "autoresponse_owner_text", "autorespond_postings", "autoresponse_postings_text", "autorespond_requests", "autoresponse_request_text", "autoresponse_grace_period", @@ -656,7 +650,7 @@ "welcome_message_uri", "admin_immed_notify", "admin_notify_mchanges"], - ["Alter Messages", "filter_content", "collapse_alternatives", + ["alter_messages", "filter_content", "collapse_alternatives", "convert_html_to_plaintext", "anonymous_list", "include_rfc2369_headers", "allow_list_posts", @@ -664,13 +658,32 @@ "reply_to_address", "first_strip_reply_to", "posting_pipeline"], - ["Digest", "digest_size_threshold"], - ["Message Acceptance", "acceptable_aliases", "administrivia", + ["digest", "digest_size_threshold"], + ["message_acceptance", "acceptable_aliases", "administrivia", "default_nonmember_action", "default_member_action"], - ["Archives", "archive_policy"], + ["archiving", "archive_policy"], ] +SUBSCRIPTION_POLICY_CHOICES = ( + ('', _('Please Choose')), + ('open', _('Open')), + ('confirm', _('Confirm')), + ('moderate', _('Moderate')), + ('confirm_then_moderate', _('Confirm, then moderate')), +) + + +class ListSubscriptionPolicyForm(forms.Form): + """ + List Settings for subscription policy. + """ + subscription_policy = forms.ChoiceField( + label=_('Subscription Policy'), + choices=SUBSCRIPTION_POLICY_CHOICES, + help_text=_('Set the subscription policy.')) + + class ListArchiverForm(forms.Form): """ Select archivers for a list. diff --git a/src/postorius/templates/postorius/lists/settings.html b/src/postorius/templates/postorius/lists/settings.html index a410776..11bd328 100644 --- a/src/postorius/templates/postorius/lists/settings.html +++ b/src/postorius/templates/postorius/lists/settings.html @@ -7,28 +7,39 @@ {% if message %}

{{ message }}

{% endif %} {% list_nav 'list_settings' 'Settings' %} - {% if visible_section %} +
{% csrf_token %} + + {% for field in form %} - - {% csrf_token %} - {% for field in form %} - + {% if field.errors %} +
{{ field.errors }}
+ {% endif %} + +
+ +
+ {{ field.label_tag }} +
+ +
+ {{ field }} +

{{ field.help_text }}

+
+
+ {% endfor %} - - -
- {{ field.errors }} - {{ field.label_tag }}
- [{% trans "More info" %}{{ field.help_text }} - ] -
{{ field }}
- -
- {% endif %} + +
+ + + +
+ + {% endblock %} diff --git a/src/postorius/templates/postorius/lists/settings_legacy.html b/src/postorius/templates/postorius/lists/settings_legacy.html new file mode 100644 index 0000000..8836554 --- /dev/null +++ b/src/postorius/templates/postorius/lists/settings_legacy.html @@ -0,0 +1,34 @@ +{% extends postorius_base_template %} +{% load url from future %} +{% load i18n %} +{% load nav_helpers %} + +{% block main %} + {% if message %}

{{ message }}

{% endif %} + {% list_nav 'list_settings' 'Settings' %} + + + {% if visible_section %} + + + {% csrf_token %} + {% for field in form %} + + {% endfor %} + + +
+ {{ field.errors }} + {{ field.label_tag }}
+ [{% trans "More info" %}{{ field.help_text }} + ] +
{{ field }}
+ +
+ {% endif %} + +{% endblock %} diff --git a/src/postorius/urls.py b/src/postorius/urls.py index fb15ef3..7caba84 100644 --- a/src/postorius/urls.py +++ b/src/postorius/urls.py @@ -76,8 +76,7 @@ url(r'^remove/(?P[^/]+)/' '(?P
[^/]+)', 'remove_role', name='remove_role'), - url(r'^settings/(?P[^/]+)?' - '(?:/(?P.*))?$', + url(r'^settings/(?P[^/]+)?$', 'list_settings', name='list_settings'), url(r'^archival_options$', diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index 739592c..28b4a4e 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -561,9 +561,29 @@ context_instance=RequestContext(request)) +SETTINGS_SECTION_NAMES = ( + ('list_identity', _('List Identity')), + ('automatic_responses', _('Automatic Responses')), + ('alter_messages', _('Alter Messages')), + ('digest', _('Digest')), + ('message_acceptance', _('Message Acceptance')), + ('archiving', _('Archiving')), + ('subscription_policy', _('Subscription Policy')), +) + +SETTINGS_FORMS = { + 'list_identity': None, + 'automatic_responses': None, + 'alter_messages': None, + 'digest': None, + 'message_acceptance': None, + 'archiving': None, + 'subscription_policy': ListSubscriptionPolicyForm, +} + + @list_owner_required def list_settings(request, list_id=None, visible_section=None, - visible_option=None, template='postorius/lists/settings.html'): """ View and edit the settings of a list. @@ -576,56 +596,74 @@ result in using //option """ message = "" - if visible_section is None: - visible_section = 'List Identity' - form_sections = [] + # List object. try: - the_list = List.objects.get_or_404(fqdn_listname=list_id) + m_list = List.objects.get_or_404(fqdn_listname=list_id) except MailmanApiError: return utils.render_api_error(request) - # collect all Form sections for the links: - temp = ListSettings('', '') - for section in temp.layout: - try: - form_sections.append((section[0], - temp.section_descriptions[section[0]])) - except KeyError: - pass - del temp - # Save a Form Processed by POST - if request.method == 'POST': - form = ListSettings(visible_section, visible_option, data=request.POST) - form.truncate() - if form.is_valid(): - list_settings = the_list.settings - for key in form.fields.keys(): - list_settings[key] = form.cleaned_data[key] + list_settings = m_list.settings + # List settings are grouped an processed in different forms. + form_class = SETTINGS_FORMS.get(visible_section) + if form_class: + if request.method == 'POST': + form = form_class(request.POST) + if form.is_valid(): + for key in form.fields.keys(): + list_settings[key] = form.cleaned_data[key] list_settings.save() - message = _("The list settings have been updated.") else: - message = _( - "Validation Error - The list settings have not been updated.") + form = form_class(initial=list_settings) + + + # START Legacy section + # This really needs to be cleaned up. else: - # Provide a form with existing values - # create form and process layout into form.layout - form = ListSettings(visible_section, visible_option, data=None) - # create a Dict of all settings which are used in the form - used_settings = {} - for section in form.layout: - for option in section[1:]: - used_settings[option] = the_list.settings[option] - if option == u'acceptable_aliases': - used_settings[option] = '\n'.join(used_settings[option]) - # recreate the form using the settings - form = ListSettings(visible_section, visible_option, - data=used_settings) - form.truncate() + template='postorius/lists/settings_legacy.html' + if visible_section is None: + visible_section = 'List Identity' + form_sections = [] + # collect all Form sections for the links: + temp = ListSettings('', '') + for section in temp.layout: + try: + form_sections.append((section[0], + temp.section_descriptions[section[0]])) + except KeyError: + pass + del temp + # Save a Form Processed by POST + if request.method == 'POST': + form = ListSettings(visible_section, data=request.POST) + form.truncate() + if form.is_valid(): + for key in form.fields.keys(): + list_settings[key] = form.cleaned_data[key] + list_settings.save() + message = _("The list settings have been updated.") + else: + message = _( + "Validation Error - The list settings have not been updated.") + else: + # Provide a form with existing values + # create form and process layout into form.layout + form = ListSettings(visible_section, data=None) + # create a Dict of all settings which are used in the form + used_settings = {} + for section in form.layout: + for option in section[1:]: + used_settings[option] = m_list.settings[option] + if option == u'acceptable_aliases': + used_settings[option] = '\n'.join(used_settings[option]) + # recreate the form using the settings + form = ListSettings(visible_section, data=used_settings) + form.truncate() + # END Legacy section + return render_to_response(template, {'form': form, - 'form_sections': form_sections, + 'section_names': SETTINGS_SECTION_NAMES, 'message': message, - 'list': the_list, - 'visible_option': visible_option, + 'list': m_list, 'visible_section': visible_section}, context_instance=RequestContext(request))