diff --git a/forms.py b/forms.py index 4cb2a71..af84da8 100644 --- a/forms.py +++ b/forms.py @@ -40,7 +40,7 @@ ("Swedish", "Swedish"), ("Turkish", "Turkish"), ("Ukrainian", "Ukrainian"), - ("Vietnamese", "Vietnamese")), + ("Vietnamese", "Vietnamese")) listname = forms.EmailField( label = _('List Name'), initial = '@mailman.state-of-mind.de', @@ -596,4 +596,14 @@ "start_chain", "subject_prefix", "subscribe_auto_approval", "subscribe_policy", "topics", "topics_bodylines_limit", "topics_enabled", "unsubscribe_policy"]] - + +class ListMassSubscription(FieldsetForm): + """Form fields to masssubscribe users to a list. + """ + emails = forms.CharField( + label = _('Emails to mass subscribe'), + widget = forms.Textarea, + ) + + class Meta: + layout = [["Mass subscription", "emails"],] diff --git a/templates/mailman-django/lists/created.html b/templates/mailman-django/lists/created.html new file mode 100644 index 0000000..049e99b --- /dev/null +++ b/templates/mailman-django/lists/created.html @@ -0,0 +1,19 @@ +{% extends "mailman-django/base.html" %} +{% load i18n %} + +{% block content %} + +

{% trans "List Created" %}

+ +

The list {{ fqdn_listname }} has been created. What would you like to do next?

+ + + + + + +{% endblock %} diff --git a/templates/mailman-django/lists/index.html b/templates/mailman-django/lists/index.html index 5b84e22..6c8c089 100644 --- a/templates/mailman-django/lists/index.html +++ b/templates/mailman-django/lists/index.html @@ -11,6 +11,7 @@ {% trans "List Name" %}     + {% for list in lists %} @@ -22,6 +23,10 @@ Delete list + {% endfor %} diff --git a/templates/mailman-django/lists/mass_subscribe.html b/templates/mailman-django/lists/mass_subscribe.html new file mode 100644 index 0000000..a1bd8df --- /dev/null +++ b/templates/mailman-django/lists/mass_subscribe.html @@ -0,0 +1,24 @@ +{% extends "mailman-django/base.html" %} +{% load i18n %} + +{% block content %} + +

{% trans "Mass Subscribe Users" %}

+ +

Here you can mass subscribe users to the list {{ fqdn_listname }}. To do so, please enter one name on each row. To go back to the general settings page, please click here.

+ +{% if message %} +

{{ message }}

+{% endif %} + +
+ +{{ form.as_div }} + +
+ +
+ +
+ +{% endblock %} diff --git a/templates/mailman-django/lists/settings.html b/templates/mailman-django/lists/settings.html index eac75e0..8fa7d67 100644 --- a/templates/mailman-django/lists/settings.html +++ b/templates/mailman-django/lists/settings.html @@ -3,10 +3,12 @@ {% block content %} -

{% trans "List Settings" %}

+

{% trans "List Settings for " %}{{ fqdn_listname }}

This page visualizes all list settings. Currently the page is not connected to the rest server so the settings will not be saved when changing them. However, this gives an idea of what the settings page could look like.

+

If you wish to mass subscribe users to this list, please click here.

+ {% if message %}

{{ message }}

{% endif %} diff --git a/urls.py b/urls.py index e793160..9939e17 100644 --- a/urls.py +++ b/urls.py @@ -4,11 +4,12 @@ urlpatterns = patterns('mailman_django.views', (r'^$', 'list_index'), - 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'), - url(r'settings/(?P.+)/$', 'list_settings', name = 'list_settings'), + 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'), + url(r'^settings/(?P[^/]+)/$', 'list_settings', name = 'list_settings'), + url(r'^settings/(?P[^/]+)/mass_subscribe/$', 'mass_subscribe', name = 'mass_subscribe'), # 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 80abfcb..ec72b1d 100644 --- a/views.py +++ b/views.py @@ -6,7 +6,7 @@ from django.utils.translation import gettext as _ import re from mailman_rest_client import MailmanRESTClient, MailmanRESTClientError -from forms import ListNew, ListSubscribe, ListUnsubscribe, ListSettings +from forms import * def list_new(request, template = 'mailman-django/lists/new.html'): @@ -32,7 +32,8 @@ return HttpResponse(e) try: response = domain.create_list(parts[0]) - return HttpResponseRedirect(reverse('list_index')) + return render_to_response('mailman-django/lists/created.html', + {'fqdn_listname': response.info['fqdn_listname'] }) except MailmanRESTClientError, e: return HttpResponse(e) @@ -140,6 +141,7 @@ def list_settings(request, fqdn_listname = None, template = 'mailman-django/lists/settings.html'): """The settings of a list.""" + message = "" try: c = MailmanRESTClient('localhost:8001') the_list = c.get_list(fqdn_listname) @@ -152,7 +154,36 @@ message = "The list has been updated." else: form = ListSettings(the_list.info) - message = "" + return render_to_response(template, {'form': form, + 'message': message, + 'fqdn_listname': the_list.info['fqdn_listname']}) + +def mass_subscribe(request, fqdn_listname = None, + template = 'mailman-django/lists/mass_subscribe.html'): + """Mass subscribe users to a list.""" + message = "" + try: + c = MailmanRESTClient('localhost:8001') + the_list = c.get_list(fqdn_listname) + except Exception, e: + return HttpResponse(e) + if request.method == 'POST': + form = ListMassSubscription(request.POST) + if form.is_valid(): + try: + emails = request.POST["emails"].splitlines() + message = "The mass subscription was successful." + for email in emails: + # very simple test if email address is valid + parts = email.split('@') + if len(parts) == 2 and '.' in parts[1]: + the_list.subscribe(address=email, real_name="") + else: + message = "Please make sure the email addresses are valid." + except Exception, e: + return HttpResponse(e) + else: + form = ListMassSubscription() return render_to_response(template, {'form': form, 'message': message, 'fqdn_listname': the_list.info['fqdn_listname']})