diff --git a/src/postorius/forms.py b/src/postorius/forms.py index 39ecfb7..889d2e1 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -57,15 +57,22 @@ return result -def _get_site_choices(): - for site in Site.objects.order_by("name"): - yield (site.pk, "{} ({})".format(site.name, site.domain)) +class SiteModelChoiceField(forms.ModelChoiceField): + + def label_from_instance(self, obj): + return "%s (%s)" % (obj.name, obj.domain) -class DomainNew(forms.Form): +def _get_web_host_help(): + # Using a function is necessary, otherwise reverse() will be called before + # URLConfs are loaded. + return (_('Edit the list of available web hosts.') + % reverse("admin:sites_site_changelist")) + +class DomainForm(forms.Form): """ - Form field to add a new domain + Add or edit a domain. """ mail_host = forms.CharField( label=_('Mail Host'), @@ -77,14 +84,14 @@ description = forms.CharField( label=_('Description'), required=False) - web_host = forms.ChoiceField( + site = SiteModelChoiceField( label=_('Web Host'), error_messages={'required': _('Please enter a domain name'), 'invalid': _('Please enter a valid domain name.')}, required=True, - choices=_get_site_choices, - help_text=lambda: _('Edit the list of available web hosts.') - % reverse("admin:sites_site_changelist"), + queryset=Site.objects.order_by("name").all(), + initial=Site.objects.get_current(), + help_text=_get_web_host_help, ) def clean_mail_host(self): @@ -95,19 +102,6 @@ raise forms.ValidationError(_("Please enter a valid domain name")) return mail_host - class Meta: - - """ - Class to handle the automatic insertion of fieldsets and divs. - - To use it: add a list for each wished fieldset. The first item in - the list should be the wished name of the fieldset, the following - the fields that should be included in the fieldset. - """ - layout = [["Please enter Details", - "mail_host", - "description"]] - class MemberForm(forms.Form): """Assing a role to the member""" diff --git a/src/postorius/templates/postorius/domain/edit.html b/src/postorius/templates/postorius/domain/edit.html new file mode 100644 index 0000000..ce1e69e --- /dev/null +++ b/src/postorius/templates/postorius/domain/edit.html @@ -0,0 +1,20 @@ +{% extends "postorius/base.html" %} +{% load i18n %} +{% load bootstrap_tags %} + +{% block head_title %} +{% trans 'Edit domain' %} {{ domain }} - {{ block.super }} +{% endblock %} + +{% block content %} + +
{{ domain.mail_host }} | {{ domain.description }} | {{ domain.site.name }} ({{ domain.site.domain }}) | -{% trans 'Delete' %} | ++ {% trans 'Edit' %} + {% trans 'Delete' %} + | {% endfor %}
No domains yet.
+ {% endif %} {% endblock content %} diff --git a/src/postorius/tests/mailman_api_tests/test_domain_new.py b/src/postorius/tests/mailman_api_tests/test_domain_new.py index ab13204..20a6f45 100644 --- a/src/postorius/tests/mailman_api_tests/test_domain_new.py +++ b/src/postorius/tests/mailman_api_tests/test_domain_new.py @@ -46,7 +46,7 @@ self.client.login(username='su', password='pwd') post_data = {'mail_host': 'example.com', 'description': 'A new Domain.', - 'web_host': '1', + 'site': '1', } response = self.client.post(reverse('domain_new'), post_data) @@ -65,7 +65,7 @@ self.client.login(username='su', password='pwd') post_data = {'mail_host': 'example com', 'description': 'A new Domain', - 'web_host': '1', + 'site': '1', } response = self.client.post(reverse('domain_new'), post_data) self.assertContains(response, 'Please check the errors below') diff --git a/src/postorius/urls.py b/src/postorius/urls.py index 06f4347..957428a 100644 --- a/src/postorius/urls.py +++ b/src/postorius/urls.py @@ -86,6 +86,8 @@ # /domains/ url(r'^domains/$', domain_views.domain_index, name='domain_index'), url(r'^domains/new/$', domain_views.domain_new, name='domain_new'), + url(r'^domains/(?P