diff --git a/fieldset_forms.py b/fieldset_forms.py index 8c05810..200fb28 100644 --- a/fieldset_forms.py +++ b/fieldset_forms.py @@ -14,7 +14,8 @@ """Initialize a FormsetField.""" super(FieldsetForm, self).__init__(*args) if hasattr(self, 'Meta') and hasattr(self.Meta, 'layout'): - assert hasattr(self.Meta.layout, '__getitem__'), "Meta.layout must be iterable" + msg = "Meta.layout must be iterable" + assert hasattr(self.Meta.layout, '__getitem__'), msg self.layout = self.Meta.layout else: self.layout = self.fields.keys() @@ -29,6 +30,8 @@ def create_fieldset(self, field): """Create a
around a number of field instances.""" + # field[0] is the name of the fieldset and + # field[1:] the fields it should include # create the divs in each fieldset by calling create_divs return u'
%s%s
' % (field[0], self.create_divs(field[1:])) @@ -41,9 +44,11 @@ # create a field instance for the bound field field_instance = self.base_fields[field] except KeyError: - raise FieldsetError("Could not resolve form field '%s'." % field) + # msg on a separate line since the line got too long otherwise + msg = "Could not resolve form field '%s'." % field + raise FieldsetError(msg) # create a bound field containing all the necessary fields - # from the model + # from the form bound_field = BoundField(self, field_instance, field) output += '
%(label)s%(help_text)s%(errors)s%(field)s
\n' % \ {'class': bound_field.name, diff --git a/templates/mailman-django/lists/index.html b/templates/mailman-django/lists/index.html index 531c56b..5b84e22 100644 --- a/templates/mailman-django/lists/index.html +++ b/templates/mailman-django/lists/index.html @@ -10,6 +10,7 @@ {% trans "Real Name" %} {% trans "List Name" %}   +   {% for list in lists %} @@ -18,6 +19,9 @@ Info / Subscribe + + Delete list + {% endfor %} diff --git a/urls.py b/urls.py index a67a9f8..3a1fd53 100644 --- a/urls.py +++ b/urls.py @@ -7,6 +7,7 @@ url(r'lists/$', 'list_index', name = 'list_index'), url(r'lists/new/$', 'list_new', name = 'list_new'), url(r'lists/(?P.+)/$', 'list_info', name = 'list_info'), + url(r'delete_list/(?P.+)/$', 'list_delete', name = 'list_delete'), # to override the default templates specifiy your own: # url(r'lists/(?P.+)/$', 'list_info', dict(template = 'path/to/template.html'), name = 'list_info'), ) diff --git a/views.py b/views.py index a1ee10d..387ae08 100644 --- a/views.py +++ b/views.py @@ -115,3 +115,25 @@ 'unsubscribe': unsubscribe, 'fqdn_listname': fqdn_listname, 'listinfo': listinfo}) + +def list_delete(request, fqdn_listname = None, + template = 'mailman-django/lists/index.html'): + """Delete a list. + """ + # create a connection to Mailman and get the list + try: + c = MailmanRESTClient('localhost:8001') + the_list = c.get_list(fqdn_listname) + except Exception, e: + return HttpResponse(e) + # get the parts for the list necessary to delete it + parts = fqdn_listname.split('@') + domain = the_list.get_domain(parts[1]) + domain.delete_list(parts[0]) + # let the user return to the list index page + try: + lists = c.get_lists() + return render_to_response(template, {'lists': lists}) + except MailmanRESTClientError, e: + return render_to_response('mailman-django/errors/generic.html', + {'message': e})