diff --git a/src/postorius/forms.py b/src/postorius/forms.py
index 13bad30..9579c91 100644
--- a/src/postorius/forms.py
+++ b/src/postorius/forms.py
@@ -168,17 +168,23 @@
class ListSubscribe(FieldsetForm):
-
"""Form fields to join an existing list.
"""
- email = forms.EmailField(
+
+ email = forms.ChoiceField(
label=_('Your email address'),
- widget=forms.HiddenInput(),
+ validators=[validate_email],
+ widget=forms.Select(),
error_messages={'required': _('Please enter an email address.'),
'invalid': _('Please enter a valid email address.')})
display_name = forms.CharField(label=_('Your name (optional)'),
required=False)
+ def __init__(self, user_emails, *args, **kwargs):
+ super(ListSubscribe, self).__init__(*args, **kwargs)
+ self.fields['email'].choices = ((address, address)
+ for address in user_emails)
+
class ListUnsubscribe(FieldsetForm):
diff --git a/src/postorius/templates/postorius/lists/summary.html b/src/postorius/templates/postorius/lists/summary.html
index 99fc33a..ca0bb37 100644
--- a/src/postorius/templates/postorius/lists/summary.html
+++ b/src/postorius/templates/postorius/lists/summary.html
@@ -14,7 +14,7 @@
{% trans 'Description' %}
{{list.settings.description }}
-
+
{% if user.is_authenticated %}
{% if userSubscribed %}
{% trans "Unsubscribe" %}
diff --git a/src/postorius/templates/postorius/user_mailmansettings.html b/src/postorius/templates/postorius/user_mailmansettings.html
index 12a709d..0688f4c 100644
--- a/src/postorius/templates/postorius/user_mailmansettings.html
+++ b/src/postorius/templates/postorius/user_mailmansettings.html
@@ -28,7 +28,7 @@
{% trans "Mail Delivery" %}:
[{% trans 'More info' %}{{ settingsform.delivery_status.help_text }}
- ]
+ ]
{{settingsform.delivery_status }} |
diff --git a/src/postorius/tests/test_forms.py b/src/postorius/tests/test_forms.py
index a48c8f5..091c92f 100644
--- a/src/postorius/tests/test_forms.py
+++ b/src/postorius/tests/test_forms.py
@@ -16,7 +16,8 @@
# Postorius. If not, see .
from django.utils import unittest
-from postorius.forms import UserPreferences, DomainNew
+from postorius.forms import (
+ UserPreferences, DomainNew, ListSubscribe)
class UserPreferencesTest(unittest.TestCase):
@@ -49,3 +50,29 @@
'contact_address': 'contact@mailman.most-desirable.org',
})
self.assertFalse(form.is_valid())
+
+class ListSubscribeTest(unittest.TestCase):
+ def test_subscribe_works(self):
+ user_emails = ['someone@example.com']
+ form = ListSubscribe(user_emails, {
+ 'email' : 'someone@example.com',
+ 'display_name' : 'Someone',
+ })
+ self.assertTrue(form.is_valid())
+
+
+ def test_subscribe_fails(self):
+ user_emails = ['someone@example.com']
+ form = ListSubscribe(user_emails, {
+ 'email' : 'notaemail',
+ 'display_name' : 'Someone',
+ })
+ self.assertFalse(form.is_valid())
+
+ def test_subscribe_validates_email(self):
+ user_emails = ['something']
+ form = ListSubscribe(user_emails, {
+ 'email' : 'something',
+ 'display_name' : 'Someone',
+ })
+ self.assertFalse(form.is_valid())
diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py
index f78de08..a24b7af 100644
--- a/src/postorius/views/list.py
+++ b/src/postorius/views/list.py
@@ -172,10 +172,19 @@
"""
def get(self, request, list_id):
- user_email = getattr(request.user, 'email', None)
+ try:
+ mm_user = MailmanUser.objects.get(address=request.user.email)
+ user_emails = [str(address) for address in getattr(mm_user, 'addresses')]
+ # TODO:maxking - add the clause below in above
+ # statement after the subscription policy is sorted
+ # out
+ # if address.verified_on is not None]
+ except Mailman404Error:
+ # The user does not have a mailman user associated with it.
+ user_emails = [request.user.email]
userSubscribed = False
try:
- userMember = self.mailing_list.get_member(user_email)
+ userMember = self.mailing_list.get_member(user_emails[0])
except ValueError:
pass
else:
@@ -183,7 +192,7 @@
return render_to_response(
'postorius/lists/summary.html',
{'list': self.mailing_list,
- 'subscribe_form': ListSubscribe(initial={'email': user_email}),
+ 'subscribe_form': ListSubscribe(user_emails),
'userSubscribed': userSubscribed},
context_instance=RequestContext(request))
@@ -195,7 +204,9 @@
@method_decorator(login_required)
def post(self, request, list_id):
try:
- form = ListSubscribe(request.POST)
+ mm_user = MailmanUser.objects.get(address=request.user.email)
+ user_addresses = [str(address) for address in mm_user.addresses]
+ form = ListSubscribe(user_addresses, request.POST)
if form.is_valid():
email = request.POST.get('email')
self.mailing_list.subscribe(email)
@@ -474,7 +485,7 @@
context_instance=RequestContext(request))
-
+
@list_moderator_required
def list_held_messages(request, list_id):
"""Shows a list of held messages.