Commit cc1bf8f7 authored by Aurélien Bompard's avatar Aurélien Bompard

Merge branch 'fix-list-forms' into 'master'

Fix list forms

Set some better defaults in the List settings and creation forms. Allow the subject and the description to be empty.

See merge request !193
parents b2480c3d b7d7673d
Pipeline #5297489 failed with stage
in 2 minutes and 43 seconds
......@@ -155,7 +155,7 @@ class ListNew(forms.Form):
(False, _("Hide this list in list index"))))
description = forms.CharField(
label=_('Description'),
required=True)
required=False)
def __init__(self, domain_choices, *args, **kwargs):
super(ListNew, self).__init__(*args, **kwargs)
......@@ -604,6 +604,7 @@ class ListIdentityForm(ListSettingsForm):
'on the list of all lists'))
description = forms.CharField(
label=_('Description'),
required=False,
help_text=_(
'This description is used when the mailing list is listed with '
'other mailing lists, or in headers, and so forth. It should be '
......@@ -617,16 +618,19 @@ class ListIdentityForm(ListSettingsForm):
widget=forms.Textarea())
display_name = forms.CharField(
label=_('Display name'),
required=False,
help_text=_('Display name is the name shown in the web interface.')
)
if get_complete_version() < (1, 9):
subject_prefix = forms.CharField(
label=_('Subject prefix'),
required=False,
)
else:
subject_prefix = forms.CharField(
label=_('Subject prefix'),
strip=False,
required=False,
)
......
......@@ -133,7 +133,7 @@ class ListSettingsTest(ViewTestCase):
self.assertEqual(response.status_code, 200)
form = response.context["form"]
self.assertEqual(
form.initial['first_strip_reply_to'], False)
form.initial['first_strip_reply_to'], 'False')
post_data = dict(
(key, unicode(self.foo_list.settings[key]))
for key in form.fields)
......@@ -144,3 +144,21 @@ class ListSettingsTest(ViewTestCase):
# Get a new list object to avoid caching
m_list = List.objects.get(fqdn_listname='foo.example.com')
self.assertEqual(m_list.settings['first_strip_reply_to'], True)
def test_list_identity_allow_empty_prefix_and_desc(self):
self.assertEqual(self.foo_list.settings['subject_prefix'], '[Foo] ')
self.assertEqual(self.foo_list.settings['description'], '')
self.client.login(username='testsu', password='testpass')
url = reverse('list_settings',
args=('foo.example.com', 'list_identity'))
response = self.client.post(url, {
'subject_prefix': '',
'description': '',
'advertised': 'True',
})
self.assertRedirects(response, url)
self.assertHasSuccessMessage(response)
# Get a new list object to avoid caching
m_list = List.objects.get(fqdn_listname='foo.example.com')
self.assertEqual(m_list.settings['subject_prefix'], '')
self.assertEqual(m_list.settings['description'], '')
......@@ -527,7 +527,9 @@ def list_new(request, template='postorius/lists/new.html'):
form.cleaned_data['listname'])
mailing_list.add_owner(form.cleaned_data['list_owner'])
list_settings = mailing_list.settings
list_settings["description"] = form.cleaned_data['description']
if form.cleaned_data['description']:
list_settings["description"] = \
form.cleaned_data['description']
list_settings["advertised"] = form.cleaned_data['advertised']
list_settings.save()
messages.success(request, _("List created"))
......@@ -540,8 +542,10 @@ def list_new(request, template='postorius/lists/new.html'):
else:
messages.error(request, _('Please check the errors below'))
else:
form = ListNew(choosable_domains,
initial={'list_owner': request.user.email})
form = ListNew(choosable_domains, initial={
'list_owner': request.user.email,
'advertised': True,
})
return render(request, template, {'form': form})
......@@ -682,10 +686,10 @@ def list_settings(request, list_id=None, visible_section=None,
list_settings = m_list.settings
except (MailmanApiError, HTTPError):
return utils.render_api_error(request)
initial_data = dict(
(key, unicode(value)) for key, value in list_settings.items())
# List settings are grouped an processed in different forms.
if request.method == 'POST':
initial_data = dict(
(key, unicode(value)) for key, value in list_settings.items())
form = form_class(request.POST, mlist=m_list, initial=initial_data)
if form.is_valid():
try:
......@@ -700,7 +704,7 @@ def list_settings(request, list_id=None, visible_section=None,
messages.error(request, _('An error occured: %s') % e.reason)
return redirect('list_settings', m_list.list_id, visible_section)
else:
form = form_class(initial=dict(list_settings), mlist=m_list)
form = form_class(initial=initial_data, mlist=m_list)
return render(request, template, {
'form': form,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment