diff --git a/src/postorius/forms.py b/src/postorius/forms.py index 4eaf396..ffdc878 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -199,11 +199,13 @@ """Form fields to join an existing list. """ - email = forms.ChoiceField(label=_('Your email address'), + email = forms.ChoiceField( + label=_('Your email address'), validators=[validate_email], widget=forms.Select(), - error_messages={'required': _('Please enter an email address.'), - 'invalid': _('Please enter a valid email address.')}) + 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) @@ -244,8 +246,10 @@ help_text=_('Open: Subscriptions are added automatically\n' 'Confirm: Subscribers need to confirm the subscription ' 'using an email sent to them\n' - 'Moderate: Moderators will have to authorize each subscription manually.\n' - 'Confirm then Moderate: First subscribers have to confirm, then a moderator ' + 'Moderate: Moderators will have to authorize ' + 'each subscription manually.\n' + 'Confirm then Moderate: First subscribers have to confirm,' + ' then a moderator ' 'needs to authorize.')) @@ -355,7 +359,8 @@ """ digest_size_threshold = forms.DecimalField( label=_('Digest size threshold'), - help_text=_('How big in Kb should a digest be before it gets sent out?')) + help_text=_('How big in Kb should a digest be before ' + 'it gets sent out?')) class AlterMessagesForm(ListSettingsForm): @@ -368,16 +373,16 @@ widget=forms.RadioSelect, required=False, label=_('Filter content'), - help_text=_('Should Mailman filter the content of list traffic according ' - 'to the settings below?')) + help_text=_('Should Mailman filter the content of list traffic ' + 'according to the settings below?')) collapse_alternatives = forms.TypedChoiceField( coerce=lambda x: x == 'True', choices=((True, _('Yes')), (False, _('No'))), widget=forms.RadioSelect, required=False, label=_('Collapse alternatives'), - help_text=_('Should Mailman collapse multipart/alternative to its first ' - 'part content?')) + help_text=_('Should Mailman collapse multipart/alternative to ' + 'its first part content?')) convert_html_to_plaintext = forms.TypedChoiceField( coerce=lambda x: x == 'True', choices=((True, _('Yes')), (False, _('No'))), @@ -385,15 +390,17 @@ required=False, label=_('Convert html to plaintext'), help_text=_('Should Mailman convert text/html parts to plain text? ' - 'This conversion happens after MIME attachments have been stripped.')) + 'This conversion happens after MIME attachments ' + 'have been stripped.')) anonymous_list = forms.TypedChoiceField( coerce=lambda x: x == 'True', choices=((True, _('Yes')), (False, _('No'))), widget=forms.RadioSelect, required=False, label=_('Anonymous list'), - help_text=_('Hide the sender of a message, replacing it with the list address ' - '(Removes From, Sender and Reply-To fields)')) + help_text=_('Hide the sender of a message, ' + 'replacing it with the list address ' + '(Removes From, Sender and Reply-To fields)')) include_rfc2369_headers = forms.TypedChoiceField( coerce=lambda x: x == 'True', choices=((True, _('Yes')), (False, _('No'))), @@ -497,7 +504,8 @@ choices=autorespond_choices, widget=forms.RadioSelect, label=_('Autorespond to list owner'), - help_text=_('Should Mailman send an auto-response to emails sent to the -owner address?')) + help_text=_('Should Mailman send an auto-response to ' + 'emails sent to the -owner address?')) autoresponse_owner_text = forms.CharField( label=_('Autoresponse owner text'), widget=forms.Textarea(), @@ -507,7 +515,8 @@ choices=autorespond_choices, widget=forms.RadioSelect, label=_('Autorespond postings'), - help_text=_('Should Mailman send an auto-response to mailing list posters?')) + help_text=_('Should Mailman send an auto-response to ' + 'mailing list posters?')) autoresponse_postings_text = forms.CharField( label=_('Autoresponse postings text'), widget=forms.Textarea(), @@ -568,7 +577,8 @@ widget=forms.RadioSelect(choices=((True, _('Yes')), (False, _('No')))), required=False, label=_('Notify admin of membership changes'), - help_text=_('Should administrator get notices of subscribes and unsubscribes?')) + help_text=_('Should administrator get notices of ' + 'subscribes and unsubscribes?')) class ListIdentityForm(ListSettingsForm): @@ -580,7 +590,8 @@ choices=((True, _('Yes')), (False, _('No'))), widget=forms.RadioSelect, label=_('Show list on index page'), - help_text=_('Choose whether to include this list on the list of all lists')) + help_text=_('Choose whether to include this list ' + 'on the list of all lists')) description = forms.CharField( label=_('Description'), help_text=_( @@ -663,10 +674,8 @@ class ListHeaderMatchForm(forms.Form): """Edit a list's header match.""" - HM_ACTION_CHOICES = [ - (None, _("Default antispam action")) ] + [ - a for a in ACTION_CHOICES if a[0] != 'defer' - ] + HM_ACTION_CHOICES = [(None, _("Default antispam action"))] + \ + [a for a in ACTION_CHOICES if a[0] != 'defer'] header = forms.CharField( label=_('Header'), @@ -683,17 +692,18 @@ action = forms.ChoiceField( label=_('Action'), error_messages={'invalid': _('Please enter a valid action.')}, - #widget=forms.RadioSelect(), required=False, choices=HM_ACTION_CHOICES, help_text=_('Action to take when a header matches') ) + class ListHeaderMatchFormset(forms.BaseFormSet): def clean(self): """Checks that no two header matches have the same order.""" if any(self.errors): - # Don't bother validating the formset unless each form is valid on its own + # Don't bother validating the formset unless + # each form is valid on its own return orders = [] for form in self.forms: @@ -702,7 +712,8 @@ except KeyError: continue if order in orders: - raise forms.ValidationError("Header matches must have distinct orders.") + raise forms.ValidationError('Header matches must have' + ' distinct orders.') orders.append(order) @@ -823,14 +834,15 @@ # Check if the address belongs to someone else if User.objects.filter(email=email).exists(): - raise forms.ValidationError(_('This email is in use.' - 'Please choose another or contact the administrator'), - 'error') + raise forms.ValidationError( + _('This email is in use. Please choose another or contact' + ' the administrator'), 'error') # Check if the email is attached to a user in Mailman try: utils.get_client().get_user(email) - raise forms.ValidationError(_('This email already belongs to a user'), 'error') + raise forms.ValidationError( + _('This email already belongs to a user'), 'error') except HTTPError: pass return email diff --git a/src/postorius/migrations/0001_initial.py b/src/postorius/migrations/0001_initial.py index 9cca4b1..fdffe48 100644 --- a/src/postorius/migrations/0001_initial.py +++ b/src/postorius/migrations/0001_initial.py @@ -15,7 +15,8 @@ migrations.CreateModel( name='AddressConfirmationProfile', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), ('email', models.EmailField(max_length=254)), ('activation_key', models.CharField(max_length=40)), ('created', models.DateTimeField()), diff --git a/src/postorius/models.py b/src/postorius/models.py index 1c6d6d0..702a498 100644 --- a/src/postorius/models.py +++ b/src/postorius/models.py @@ -259,7 +259,8 @@ The following settings are recognized: - >>> EMAIL_CONFIRMATION_TEMPLATE = 'postorius/user/address_confirmation_message.txt' + >>> EMAIL_CONFIRMATION_TEMPLATE = \ + 'postorius/user/address_confirmation_message.txt' >>> EMAIL_CONFIRMATION_FROM = 'postmaster@list.org' >>> EMAIL_CONFIRMATION_SUBJECT = 'Confirmation needed' @@ -276,14 +277,14 @@ # Detect the right template path, either from the param, # the setting or the default if not template_path: - template_path = getattr(settings, - 'EMAIL_CONFIRMATION_TEMPLATE', - 'postorius/user/address_confirmation_message.txt') + template_path = getattr( + settings, 'EMAIL_CONFIRMATION_TEMPLATE', + 'postorius/user/address_confirmation_message.txt') # Create a template context (if there is none) containing # the activation_link and the host_url. if not template_context: template_context = {'activation_link': activation_link, - 'host_url': request.build_absolute_uri("/")} + 'host_url': request.build_absolute_uri("/")} email_subject = getattr( settings, 'EMAIL_CONFIRMATION_SUBJECT', u'Confirmation needed') try: @@ -297,6 +298,7 @@ except AttributeError: raise ImproperlyConfigured - send_mail(email_subject, render_to_string(template_path, template_context), + send_mail(email_subject, + render_to_string(template_path, template_context), sender_address, [self.email]) diff --git a/src/postorius/templatetags/bootstrap_tags.py b/src/postorius/templatetags/bootstrap_tags.py index 827fb16..f1680ad 100644 --- a/src/postorius/templatetags/bootstrap_tags.py +++ b/src/postorius/templatetags/bootstrap_tags.py @@ -31,8 +31,10 @@ return field.field.widget.__class__.__name__ -@register.inclusion_tag('postorius/lib/form-horizontal.html', takes_context=True) -def render_form_horizontal(context, form, size_left=2, size_right=8, button=None): +@register.inclusion_tag('postorius/lib/form-horizontal.html', + takes_context=True) +def render_form_horizontal(context, form, size_left=2, size_right=8, + button=None): return dict( form=form, size_left=size_left, diff --git a/src/postorius/tests/mailman_api_tests/test_address_activation.py b/src/postorius/tests/mailman_api_tests/test_address_activation.py index f4341bb..c1e4a96 100644 --- a/src/postorius/tests/mailman_api_tests/test_address_activation.py +++ b/src/postorius/tests/mailman_api_tests/test_address_activation.py @@ -38,14 +38,16 @@ def setUp(self): super(TestAddressActivationForm, self).setUp() # Create a user and profile. - self.user = User.objects.create_user('testuser', 'les@example.org', 'testpass') - self.profile = AddressConfirmationProfile.objects.create(email='les2@example.org', - user=self.user) - self.expired = AddressConfirmationProfile.objects.create(email='expired@example.org', - user=self.user) + self.user = User.objects.create_user( + 'testuser', 'les@example.org', 'testpass') + self.profile = AddressConfirmationProfile.objects.create( + email='les2@example.org', user=self.user) + self.expired = AddressConfirmationProfile.objects.create( + email='expired@example.org', user=self.user) self.expired.created -= timedelta(weeks=100) self.expired.save() - self.mm_user = self.mm_client.create_user('subscribed@example.org', 'password') + self.mm_user = self.mm_client.create_user( + 'subscribed@example.org', 'password') def tearDown(self): self.profile.delete() @@ -88,8 +90,8 @@ self.user = User.objects.create_user( username=u'ler_mm', email=u'ler@mailman.mostdesirable.org', password=u'pwd') - self.profile = AddressConfirmationProfile.objects.create(email=u'les@example.org', - user=self.user) + self.profile = AddressConfirmationProfile.objects.create( + email=u'les@example.org', user=self.user) # Create a test request object self.request = RequestFactory().get('/') @@ -167,7 +169,8 @@ username='ler', email=u'ler@example.org', password='pwd') self.mm_user = self.mm_client.create_user('ler@example.org', None) - self.profile = AddressConfirmationProfile.objects.create(email=u'les@example.org', user=self.user) + self.profile = AddressConfirmationProfile.objects.create( + email=u'les@example.org', user=self.user) self.profile.save() def tearDown(self): diff --git a/src/postorius/tests/mailman_api_tests/test_domain_new.py b/src/postorius/tests/mailman_api_tests/test_domain_new.py index c4925bc..6ba6a3e 100644 --- a/src/postorius/tests/mailman_api_tests/test_domain_new.py +++ b/src/postorius/tests/mailman_api_tests/test_domain_new.py @@ -57,14 +57,15 @@ post_data = {'mail_host': 'example.com', 'web_host': 'http://example.com', 'description': 'A new Domain.'} - response = self.client.post(reverse('domain_new'), post_data, follow=True) + response = self.client.post(reverse('domain_new'), post_data, + follow=True) self.assertContains(response, 'New Domain registered') self.assertRedirects(response, reverse('domain_index')) - a_new_domain = self.mm_client.get_domain('example.com') + a_new_domain = self.mm_client.get_domain('example.com') self.assertEqual(a_new_domain.mail_host, u'example.com') self.assertEqual(a_new_domain.base_url, u'http://example.com') self.assertEqual(a_new_domain.owners[0]['user_id'], - self.mm_client.get_user('su@example.com').user_id) + self.mm_client.get_user('su@example.com').user_id) a_new_domain.delete() diff --git a/src/postorius/tests/mailman_api_tests/test_list_bans.py b/src/postorius/tests/mailman_api_tests/test_list_bans.py index 2ae37ea..d9b80c8 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_bans.py +++ b/src/postorius/tests/mailman_api_tests/test_list_bans.py @@ -70,12 +70,12 @@ response = self.client.get(self.url) self.assertEqual(response.status_code, 200) self.assertTrue('addban_form' in response.context) - self.assertContains(response, - '') - self.assertContains(response, - '') + self.assertContains( + response, '') + self.assertContains( + response, '') def test_context_contains_delete_forms(self): banned = ["banned{}@example.com".format(i) for i in range(1,10)] @@ -84,11 +84,12 @@ response = self.client.get(self.url) self.assertEqual(response.status_code, 200) for ban in banned: - self.assertContains(response, - '' % ban) - self.assertContains(response, - '