Rajeev S has proposed merging lp:~rajeevs1992/postorius/postorius into
lp:postorius.
Requested reviews:
Mailman Coders (mailman-coders)
For more details, see:
https://code.launchpad.net/~rajeevs1992/postorius/postorius/+merge/207826
Added a file upload feature to add Mass subscriptions.Also changed email
validator to django builtin validator.(DRY)
--
https://code.launchpad.net/~rajeevs1992/postorius/postorius/+merge/207826
Your team Mailman Coders is requested to review the proposed merge of
lp:~rajeevs1992/postorius/postorius into lp:postorius.
=== modified file 'src/postorius/forms.py'
--- src/postorius/forms.py 2013-10-22 18:52:15 +0000
+++ src/postorius/forms.py 2014-02-23 14:49:03 +0000
@@ -706,6 +706,11 @@
widget=forms.Textarea,
)
+ upload = forms.FileField(
+ label = ('Or Upload a file,with one email per line'),
+ required = False,
+ )
+
verify_with_email = forms.BooleanField(required=False)
class Meta:
=== modified file 'src/postorius/templates/postorius/lists/mass_subscribe.html'
--- src/postorius/templates/postorius/lists/mass_subscribe.html 2013-05-31 02:21:03 +0000
+++ src/postorius/templates/postorius/lists/mass_subscribe.html 2014-02-23 14:49:03 +0000
@@ -6,7 +6,7 @@
{% block main %}
{% list_nav 'mass_subscribe' 'Mass Subscription' %}
- <form action="{% url 'mass_subscribe' list.fqdn_listname %}" method="post" class="well"> {% csrf_token %}
+ <form action="{% url 'mass_subscribe' list.fqdn_listname %}" method="post" class="well" enctype="multipart/form-data"> {% csrf_token %}
{{ form.as_p }}
<button class="btn btn-primary" type="submit">{% trans "Subscribe users" %}</button>
</form>
=== modified file 'src/postorius/views/list.py'
--- src/postorius/views/list.py 2013-10-22 20:01:21 +0000
+++ src/postorius/views/list.py 2014-02-23 14:49:03 +0000
@@ -21,13 +21,15 @@
from django.contrib import messages
from django.contrib.auth.decorators import (login_required,
user_passes_test)
+from django.core.validators import validate_email
+from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
from django.utils.decorators import method_decorator
from django.utils.translation import gettext as _
from urllib2 import HTTPError
-
+import csv
from postorius import utils
from postorius.models import (Domain, List, MailmanUser,
MailmanApiError)
@@ -170,6 +172,12 @@
class ListMassSubsribeView(MailingListView):
"""Mass subscription."""
+ def verify_email(self,email):
+ try:
+ validate_email( email )
+ return True
+ except ValidationError:
+ return False
@method_decorator(list_owner_required)
def get(self, request, *args, **kwargs):
@@ -180,27 +188,28 @@
def post(self, request, *args, **kwargs):
form = ListMassSubscription(request.POST)
- if not form.is_valid():
+ emails = request.POST["emails"].splitlines()
+ if 'upload' in request.FILES:
+ for i in request.FILES["upload"].readlines():
+ emails.append(i.strip())
+ if emails == []:
messages.error(request, 'Please fill out the form correctly.')
- else:
- emails = request.POST["emails"].splitlines()
- for email in emails:
- parts = email.split('@')
- if len(parts) != 2 or '.' not in parts[1]:
- messages.error(request,
- 'The email address %s is not valid.' %
- email)
- else:
- try:
- self.mailing_list.subscribe(address=email)
- messages.success(
- request,
- 'The address %s has been subscribed to %s.' %
- (email, self.mailing_list.fqdn_listname))
- except MailmanApiError:
- return utils.render_api_error(request)
- except HTTPError, e:
- messages.error(request, e)
+ for email in emails:
+ if not self.verify_email(email):
+ messages.error(request,
+ 'The email address %s is not valid.' %
+ email)
+ else:
+ try:
+ self.mailing_list.subscribe(address=email)
+ messages.success(
+ request,
+ 'The address %s has been subscribed to %s.' %
+ (email, self.mailing_list.fqdn_listname))
+ except MailmanApiError:
+ return utils.render_api_error(request)
+ except HTTPError, e:
+ messages.error(request, e)
return redirect('mass_subscribe', self.mailing_list.fqdn_listname)
_______________________________________________
Mailman-coders mailing list
[email protected]
https://mail.python.org/mailman/listinfo/mailman-coders