Stephen Turnbull has proposed merging 
lp:~stephen-xemacs/postorius/REAL-domain-not-list into lp:postorius.

Requested reviews:
  Mailman Coders (mailman-coders)

For more details, see:
https://code.launchpad.net/~stephen-xemacs/postorius/REAL-domain-not-list/+merge/154564

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.

-- 
https://code.launchpad.net/~stephen-xemacs/postorius/REAL-domain-not-list/+merge/154564
Your team Mailman Coders is requested to review the proposed merge of 
lp:~stephen-xemacs/postorius/REAL-domain-not-list into lp:postorius.
=== modified file 'src/postorius/templates/postorius/lists/index.html'
--- src/postorius/templates/postorius/lists/index.html	2013-03-19 23:58:42 +0000
+++ src/postorius/templates/postorius/lists/index.html	2013-03-21 00:49:27 +0000
@@ -8,7 +8,11 @@
     </div>
     {% if user.is_superuser %}
         <p>
+        {% if domain_count < 2 %}
+            <a class="btn btn-success" href="{% url 'domain_new' %}">{% trans "Create New Domain" %}</a>
+        {% else %}
             <a class="btn btn-success" href="{% url 'list_new' %}">{% trans "Create New List" %}</a>
+        {% endif %}
         </p>
     {% endif %}
 

=== modified file 'src/postorius/views/list.py'
--- src/postorius/views/list.py	2013-03-19 18:20:22 +0000
+++ src/postorius/views/list.py	2013-03-21 00:49:27 +0000
@@ -184,6 +184,16 @@
                         messages.error(request, e)
         return redirect('mass_subscribe', self.mailing_list.fqdn_listname)
 
+def _get_choosable_domains():
+    try:
+        domains = Domain.objects.all()
+    except MailmanApiError:
+        return utils.render_api_error(request)
+    choosable_domains = [("", _("Choose a Domain"))]
+    for domain in domains:
+        choosable_domains.append((domain.mail_host,
+                                  domain.mail_host))
+    return choosable_domains
 
 @login_required
 @user_passes_test(lambda u: u.is_superuser)
@@ -199,14 +209,7 @@
     """
     mailing_list = None
     if request.method == 'POST':
-        try:
-            domains = Domain.objects.all()
-        except MailmanApiError:
-            return utils.render_api_error(request)
-        choosable_domains = [("", _("Choose a Domain"))]
-        for domain in domains:
-            choosable_domains.append((domain.mail_host,
-                                      domain.mail_host))
+        choosable_domains = _get_choosable_domains()
         form = ListNew(choosable_domains, request.POST)
         if form.is_valid():
             #grab domain
@@ -234,13 +237,7 @@
             else:
                 messages.success(_("New List created"))
     else:
-        try:
-            domains = Domain.objects.all()
-        except MailmanApiError:
-            return utils.render_api_error(request)
-        choosable_domains = [("", _("Choose a Domain"))]
-        for domain in domains:
-            choosable_domains.append((domain.mail_host, domain.mail_host))
+        choosable_domains = _get_choosable_domains()
         form = ListNew(choosable_domains,
                        initial={'list_owner': request.user.email})
     return render_to_response(template, {'form': form},
@@ -259,12 +256,14 @@
         lists = List.objects.all(only_public=only_public)
     except MailmanApiError:
         return utils.render_api_error(request)
+    choosable_domains = _get_choosable_domains()
     if request.method == 'POST':
         return redirect("list_summary", fqdn_listname=request.POST["list"])
     else:
         return render_to_response(template,
                                   {'error': error,
-                                   'lists': lists},
+                                   'lists': lists,
+                                   'domain_count': len(choosable_domains)},
                                   context_instance=RequestContext(request))
 
 

_______________________________________________
Mailman-coders mailing list
[email protected]
http://mail.python.org/mailman/listinfo/mailman-coders

Reply via email to