Merge lp:~stephen-xemacs/postorius/REAL-domain-not-list into lp:postorius

Proposed by Stephen Turnbull
Status: Merged
Merged at revision: 129
Proposed branch: lp:~stephen-xemacs/postorius/REAL-domain-not-list
Merge into: lp:postorius
Diff against target: 81 lines (+19/-16)
2 files modified
src/postorius/templates/postorius/lists/index.html (+4/-0)
src/postorius/views/list.py (+15/-16)
To merge this branch: bzr merge lp:~stephen-xemacs/postorius/REAL-domain-not-list
Reviewer Review Type Date Requested Status
Mailman Coders Pending
Review via email: mp+154564@code.launchpad.net

Description of the change

When the superuser first visits the root of the postorius URL space, she is invited to create a list, but won't be able to if there are no domains.

This branch
1. Adds code to the lists/index.html template to check if any domains have been created yet, and offer to create a domain instead of a list.
2. Refactors the code to create the domain list used in the domain menu out to a new function _get_choosable_domains(), and uses it in views/list.py.
3. Adds the length of the domain list to the list_index view, so the index.html template can check it.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/postorius/templates/postorius/lists/index.html'
2--- src/postorius/templates/postorius/lists/index.html 2013-03-19 23:58:42 +0000
3+++ src/postorius/templates/postorius/lists/index.html 2013-03-21 00:49:27 +0000
4@@ -8,7 +8,11 @@
5 </div>
6 {% if user.is_superuser %}
7 <p>
8+ {% if domain_count < 2 %}
9+ <a class="btn btn-success" href="{% url 'domain_new' %}">{% trans "Create New Domain" %}</a>
10+ {% else %}
11 <a class="btn btn-success" href="{% url 'list_new' %}">{% trans "Create New List" %}</a>
12+ {% endif %}
13 </p>
14 {% endif %}
15
16
17=== modified file 'src/postorius/views/list.py'
18--- src/postorius/views/list.py 2013-03-19 18:20:22 +0000
19+++ src/postorius/views/list.py 2013-03-21 00:49:27 +0000
20@@ -184,6 +184,16 @@
21 messages.error(request, e)
22 return redirect('mass_subscribe', self.mailing_list.fqdn_listname)
23
24+def _get_choosable_domains():
25+ try:
26+ domains = Domain.objects.all()
27+ except MailmanApiError:
28+ return utils.render_api_error(request)
29+ choosable_domains = [("", _("Choose a Domain"))]
30+ for domain in domains:
31+ choosable_domains.append((domain.mail_host,
32+ domain.mail_host))
33+ return choosable_domains
34
35 @login_required
36 @user_passes_test(lambda u: u.is_superuser)
37@@ -199,14 +209,7 @@
38 """
39 mailing_list = None
40 if request.method == 'POST':
41- try:
42- domains = Domain.objects.all()
43- except MailmanApiError:
44- return utils.render_api_error(request)
45- choosable_domains = [("", _("Choose a Domain"))]
46- for domain in domains:
47- choosable_domains.append((domain.mail_host,
48- domain.mail_host))
49+ choosable_domains = _get_choosable_domains()
50 form = ListNew(choosable_domains, request.POST)
51 if form.is_valid():
52 #grab domain
53@@ -234,13 +237,7 @@
54 else:
55 messages.success(_("New List created"))
56 else:
57- try:
58- domains = Domain.objects.all()
59- except MailmanApiError:
60- return utils.render_api_error(request)
61- choosable_domains = [("", _("Choose a Domain"))]
62- for domain in domains:
63- choosable_domains.append((domain.mail_host, domain.mail_host))
64+ choosable_domains = _get_choosable_domains()
65 form = ListNew(choosable_domains,
66 initial={'list_owner': request.user.email})
67 return render_to_response(template, {'form': form},
68@@ -259,12 +256,14 @@
69 lists = List.objects.all(only_public=only_public)
70 except MailmanApiError:
71 return utils.render_api_error(request)
72+ choosable_domains = _get_choosable_domains()
73 if request.method == 'POST':
74 return redirect("list_summary", fqdn_listname=request.POST["list"])
75 else:
76 return render_to_response(template,
77 {'error': error,
78- 'lists': lists},
79+ 'lists': lists,
80+ 'domain_count': len(choosable_domains)},
81 context_instance=RequestContext(request))
82
83

Subscribers

People subscribed via source and target branches