diff --git a/src/postorius/forms.py b/src/postorius/forms.py index bc90f0b..6936ace 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -225,7 +225,7 @@ widget=forms.Textarea(), label=_("Acceptable aliases"), required=False, - help_text=( + help_text=_( 'Alias names which qualify as explicit to or cc destination names ' 'for this list. Alternate addresses that are acceptable when ' '`require_explicit_destination\' is enabled. This option takes a ' @@ -237,7 +237,7 @@ widget=forms.RadioSelect(choices=((True, _('Yes')), (False, _('No')))), required=False, label=_('Administrivia'), - help_text=( + help_text=_( 'Administrivia tests will check postings to see whether it\'s ' 'really meant as an administrative request (like subscribe, ' 'unsubscribe, etc), and will add it to the the administrative ' @@ -250,7 +250,7 @@ 'required': _("Please choose a default member action.")}, required=True, choices=action_choices, - help_text=( + help_text=_( 'Default action to take when a member posts to the list. ' 'Hold -- This holds the message for approval by the list ' 'moderators.' @@ -269,7 +269,7 @@ 'required': _("Please choose a default non-member action.")}, required=True, choices=action_choices, - help_text=( + help_text=_( 'When a post from a non-member is received, the message\'s sender ' 'is matched against the list of explicitly accepted, held, ' 'rejected (bounced), and discarded addresses. ' @@ -282,8 +282,7 @@ """ 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(forms.Form): @@ -296,36 +295,32 @@ 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'))), widget=forms.RadioSelect, 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.')) + help_text=_('Should Mailman convert text/html parts to plain text? ' + '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'))), @@ -376,10 +371,10 @@ error_messages={ 'required': _("Please choose a reply-to action.")}, choices=( - ("no_munging", _("No Munging")), - ("point_to_list", _("Reply goes to list")), - ("explicit_header", _("Explicit Reply-to header set"))), - help_text=( + ('no_munging', _('No Munging')), + ('point_to_list', _('Reply goes to list')), + ('explicit_header', _('Explicit Reply-to header set'))), + help_text=_( 'Where are replies to list messages directed? No Munging is ' 'strongly recommended for most mailing lists. \nThis option ' 'controls what Mailman does to the Reply-To: header in messages ' @@ -411,11 +406,10 @@ error_messages={ 'required': _("Please choose a reply-to action.")}, choices=( - ("default-owner-pipeline", _("default-owner-pipeline")), - ("default-posting-pipeline", _("default-posting-pipeline")), - ("virgin", _("virgin"))), - help_text=( - 'Type of pipeline you want to use for this mailing list')) + ('default-owner-pipeline', _('default-owner-pipeline')), + ('default-posting-pipeline', _('default-posting-pipeline')), + ('virgin', _('virgin'))), + help_text=_('Type of pipeline you want to use for this mailing list')) class ListAutomaticResponsesForm(forms.Form): @@ -430,30 +424,27 @@ 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(), required=False, - help_text=('Auto-response text to send to -owner emails.')) + help_text=_('Auto-response text to send to -owner emails.')) autorespond_postings = forms.ChoiceField( 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(), required=False, - help_text=('Auto-response text to send to mailing list posters.')) + help_text=_('Auto-response text to send to mailing list posters.')) autorespond_requests = forms.ChoiceField( choices=autorespond_choices, widget=forms.RadioSelect, label=_('Autorespond requests'), - help_text=( + help_text=_( 'Should Mailman send an auto-response to emails sent to the ' '-request address? If you choose yes, decide whether you want ' 'Mailman to discard the original email, or forward it on to the ' @@ -462,10 +453,10 @@ label=_('Autoresponse request text'), widget=forms.Textarea(), required=False, - help_text=('Auto-response text to send to -request emails.')) + help_text=_('Auto-response text to send to -request emails.')) autoresponse_grace_period = forms.CharField( label=_('Autoresponse grace period'), - help_text=( + help_text=_( 'Number of days between auto-responses to either the mailing list ' 'or -request/-owner address from the same poster. Set to zero ' '(or negative) for no grace period (i.e. auto-respond to every ' @@ -476,7 +467,7 @@ widget=forms.RadioSelect, required=False, label=_('Send welcome message'), - help_text=( + help_text=_( 'Send welcome message to newly subscribed members? ' 'Turn this off only if you plan on subscribing people manually ' 'and don\'t want them to know that you did so. This option is ' @@ -492,7 +483,7 @@ widget=forms.RadioSelect(choices=((True, _('Yes')), (False, _('No')))), required=False, label=_('Admin immed notify'), - help_text=( + help_text=_( 'Should the list moderators get immediate notice of new requests, ' 'as well as daily notices about collected ones? List moderators ' '(and list administrators) are sent daily reminders of requests ' @@ -504,9 +495,7 @@ 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(forms.Form): @@ -518,11 +507,10 @@ 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=( + help_text=_( 'This description is used when the mailing list is listed with ' 'other mailing lists, or in headers, and so forth. It should be ' 'as succinct as you can get it, while still identifying what the ' @@ -533,15 +521,15 @@ error_messages={'required': _('Please a domain name'), 'invalid': _('Please enter a valid domain name.')}, required=True, - help_text=( - "The \"host_name\" is the preferred name for email to " - "'mailman-related addresses on this host, and generally should be " + help_text=_( + 'The "host_name" is the preferred name for email to ' + 'mailman-related addresses on this host, and generally should be ' "the mail host's exchanger address, if any. This setting can be " - "useful for selecting among alternative names of a host that " - "has multiple addresses.")) + 'useful for selecting among alternative names of a host that ' + 'has multiple addresses.')) display_name = forms.CharField( label=_('Display name'), - help_text=('Display name is the name shown in the web interface.') + help_text=_('Display name is the name shown in the web interface.') ) subject_prefix = forms.CharField( label=_('Subject prefix'), @@ -747,7 +735,7 @@ password = cleaned_data.get("password") password_repeat = cleaned_data.get("password_repeat") if password != password_repeat: - raise forms.ValidationError("Passwords must be identical.") + raise forms.ValidationError(_('Passwords must be identical.')) return cleaned_data diff --git a/src/postorius/utils.py b/src/postorius/utils.py index ee1ea6c..e07d9f0 100644 --- a/src/postorius/utils.py +++ b/src/postorius/utils.py @@ -22,6 +22,7 @@ from django.shortcuts import render_to_response, redirect from django.template import RequestContext from mailmanclient import Client +from django.utils.translation import gettext as _ logger = logging.getLogger(__name__) @@ -39,8 +40,7 @@ """ return render_to_response( 'postorius/errors/generic.html', - {'error': "Mailman REST API not available. " - "Please start Mailman core."}, + {'error': _('Mailman REST API not available. Please start Mailman core.')}, context_instance=RequestContext(request)) diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index 7be8d0f..b2eb075 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -120,10 +120,9 @@ for key in preferences_form.fields.keys(): preferences[key] = preferences_form.cleaned_data[key] preferences.save() - messages.success( - request, 'The member\'s preferences have been updated.') + messages.success(request, _("The member's preferences have been updated.")) else: - messages.error(request, 'Something went wrong.') + messages.error(request, _('Something went wrong.')) # this is a bit silly, since we already have the preferences, # but I want to be sure we don't show stale data. @@ -232,15 +231,13 @@ if form.is_valid(): email = form.cleaned_data['email'] if old_email == email: - messages.error(request, 'You are already subscribed') + messages.error(request, _('You are already subscribed')) else: self.mailing_list.unsubscribe(old_email) self.mailing_list.subscribe(email) - messages.success(request, - 'Subscription changed to {} address'.format(email)) + messages.success(request, _('Subscription changed to %s') % email) else: - messages.error(request, 'Something went wrong. ' - 'Please try again.') + messages.error(request, _('Something went wrong. Please try again.')) except MailmanApiError: return utils.render_api_error(request) except HTTPError as e: @@ -268,16 +265,13 @@ if type(response) == dict and response.get('token_owner') == \ 'moderator': messages.success( - request, - 'Your subscription request has been submitted and is ' - 'waiting for moderator approval.') + request, _('Your subscription request has been submitted and is ' + 'waiting for moderator approval.')) else: - messages.success( - request, 'You are subscribed to %s.' % - self.mailing_list.fqdn_listname) + messages.success(request, _('You are subscribed to %s.') % + self.mailing_list.fqdn_listname) else: - messages.error(request, 'Something went wrong. ' - 'Please try again.') + messages.error(request, _('Something went wrong. Please try again.')) except MailmanApiError: return utils.render_api_error(request) except HTTPError as e: @@ -294,9 +288,7 @@ email = kwargs['email'] try: self.mailing_list.unsubscribe(email) - messages.success(request, - '%s has been unsubscribed from this list.' % - email) + messages.success(request, _('%s has been unsubscribed from this list.') % email) except MailmanApiError: return utils.render_api_error(request) except ValueError as e: @@ -318,26 +310,23 @@ def post(self, request, *args, **kwargs): form = ListMassSubscription(request.POST) if not form.is_valid(): - messages.error(request, 'Please fill out the form correctly.') + messages.error(request, _('Please fill out the form correctly.')) else: - emails = request.POST["emails"].splitlines() + emails = request.POST['emails'].splitlines() for email in emails: try: validate_email(email) self.mailing_list.subscribe(address=email, pre_verified=True, pre_confirmed=True) - messages.success( - request, - 'The address %s has been subscribed to %s.' % - (email, self.mailing_list.fqdn_listname)) + messages.success(request, + _('The address %(address)s has been subscribed to %(list)s.') % + {'address':email, 'list': self.mailing_list.fqdn_listname}) except MailmanApiError: return utils.render_api_error(request) except HTTPError as e: messages.error(request, e) except ValidationError: - messages.error(request, - 'The email address %s is not valid.' % - email) + messages.error(request, _('The email address %s is not valid.') % email) return redirect('mass_subscribe', self.mailing_list.list_id) @@ -357,24 +346,22 @@ def post(self, request, *args, **kwargs): form = ListMassRemoval(request.POST) if not form.is_valid(): - messages.error(request, 'Please fill out the form correctly.') + messages.error(request, _('Please fill out the form correctly.')) else: - emails = request.POST["emails"].splitlines() + emails = request.POST['emails'].splitlines() for email in emails: try: validate_email(email) self.mailing_list.unsubscribe(email.lower()) messages.success(request, - 'The address %s has been unsubscribed from %s.' % - (email, self.mailing_list.fqdn_listname)) + _('The address %(address)s has been unsubscribed from %(list)s.') % + {'email': email, 'list': self.mailing_list.fqdn_listname}) except MailmanApiError: return utils.render_api_error(request) except (HTTPError, ValueError) as e: messages.error(request, e) except ValidationError: - messages.error(request, - 'The email address %s is not valid.' % - email) + messages.error(request, _('The email address %s is not valid.') % email) return redirect('mass_removal', self.mailing_list.list_id) @@ -567,7 +554,7 @@ except HTTPError as e: messages.error(request, e.msg) return redirect('list_held_messages', the_list.list_id) - messages.success(request, 'The message has been accepted.') + messages.success(request, _('The message has been accepted.')) return redirect('list_held_messages', the_list.list_id) @@ -584,7 +571,7 @@ except HTTPError as e: messages.error(request, e.msg) return redirect('list_held_messages', the_list.list_id) - messages.success(request, 'The message has been discarded.') + messages.success(request, _('The message has been discarded.')) return redirect('list_held_messages', the_list.list_id) @@ -601,7 +588,7 @@ except HTTPError as e: messages.error(request, e.msg) return redirect('list_held_messages', the_list.list_id) - messages.success(request, 'The message has been deferred.') + messages.success(request, _('The message has been deferred.')) return redirect('list_held_messages', the_list.list_id) @@ -618,7 +605,7 @@ except HTTPError as e: messages.error(request, e.msg) return redirect('list_held_messages', the_list.list_id) - messages.success(request, 'The message has been rejected.') + messages.success(request, _('The message has been rejected.')) return redirect('list_held_messages', the_list.list_id) @@ -660,8 +647,7 @@ except MailmanApiError: return utils.render_api_error(request) except HTTPError as e: - messages.error(request, '{0}: {1}'.format( - _('The request could not be moderated'), e.reason)) + messages.error(request, _('The request could not be moderated: %s') % e.reason) return redirect('list_subscription_requests', m_list.list_id) @@ -718,12 +704,9 @@ for key in form.fields.keys(): list_settings[key] = form.cleaned_data[key] list_settings.save() - messages.success(request, - _('The settings have been updated.')) + messages.success(request, _('The settings have been updated.')) except HTTPError as e: - messages.error( - request, - '{0}: {1}'.format(_('An error occured'), e.reason)) + messages.error(request, _('An error occured: %s') % e.reason) else: form = form_class(initial=list_settings) @@ -752,8 +735,7 @@ if role == 'owner': owners = the_list.owners if address not in owners: - messages.error(request, - _('The user {} is not an owner'.format(address))) + messages.error(request, _('The user %s is not an owner') % address) return redirect('list_members', the_list.list_id) if len(owners) == 1: messages.error(request, _('Removing the last owner is impossible')) @@ -767,24 +749,20 @@ redirect_on_success = redirect('list_summary', the_list.list_id) elif role == 'moderator': if address not in the_list.moderators: - messages.error(request, - _('The user {} is not a moderator'.format(address))) + messages.error(request, _('The user %s is not a moderator') % address) return redirect('list_members', the_list.list_id) - if request.method == 'POST': try: the_list.remove_role(role, address) except MailmanApiError: return utils.render_api_error(request) except HTTPError as e: - messages.error(request, _('The {0} could not be removed:' - ' {1}'.format(role, e.msg))) + messages.error(request, _('The %(role)s could not be removed: %(msg)s') % + {'role':role, 'msg': e.msg}) return redirect('list_members', the_list.list_id) - messages.success(request, - _('The user {0} has been removed as {1}.' - .format(address, role))) + messages.success(request, _('The user %(address)s has been removed as %(role)s.') % + {'address': address, 'role': role}) return redirect_on_success - return render_to_response(template, {'role': role, 'address': address, 'list_id': the_list.list_id}, @@ -814,17 +792,15 @@ 'because they are not enabled in the Mailman ' 'configuration. They will be enabled for ' 'this list, if the archiver is enabled in the ' - 'Mailman configuration. {0}.' - ''.format(', '.join(activation_postponed)))) + 'Mailman configuration. %s.') % + ', '.join(activation_postponed)) if len(activation_success) > 0: - messages.success(request, - _('You activated new archivers for this list: ' - '{0}'.format(', '.join(activation_success)))) + messages.success(request, _('You activated new archivers for this list: %s') % + ', '.join(activation_success)) # There are archivers to disable. if len(to_disable) > 0: - messages.success(request, - _('You disabled the following archivers: ' - '{0}'.format(', '.join(to_disable)))) + messages.success(request, _('You disabled the following archivers: %s') % + ', '.join(to_disable)) @login_required @@ -836,14 +812,13 @@ try: mlist = List.objects.get_or_404(fqdn_listname=list_id) if len(mlist.members) == 0: - messages.error(request, 'No member is subscribed to the list currently.') + messages.error(request, _('No member is subscribed to the list currently.')) return redirect('mass_removal', mlist.list_id) if request.method == 'POST': try: for names in mlist.members: mlist.unsubscribe(names.email) - messages.success(request, - 'All members have been unsubscribed from the list.') + messages.success(request, _('All members have been unsubscribed from the list.')) return redirect('list_members', mlist.list_id) except Exception as e: messages.error(request, e) diff --git a/src/postorius/views/user.py b/src/postorius/views/user.py index 0376189..e316d98 100644 --- a/src/postorius/views/user.py +++ b/src/postorius/views/user.py @@ -60,10 +60,9 @@ preferences[ key] = global_preferences_form.cleaned_data[key] preferences.save() - messages.success( - request, 'Your preferences have been updated.') + messages.success(request, _('Your preferences have been updated.')) else: - messages.error(request, 'Something went wrong.') + messages.error(request, _('Something went wrong.')) except MailmanApiError: return utils.render_api_error(request) except Mailman404Error as e: @@ -95,18 +94,15 @@ mm_user = MailmanUser.objects.get(address=request.user.email) formset_class = formset_factory(UserPreferences) formset = formset_class(request.POST) - zipped_data = zip(formset.forms, mm_user.addresses) if formset.is_valid(): - for form, address in zipped_data: + for form, address in zip(formset.forms, mm_user.addresses): preferences = address.preferences for key in form.fields.keys(): - preferences[ - key] = form.cleaned_data[key] + preferences[key] = form.cleaned_data[key] preferences.save() - messages.success( - request, 'Your preferences have been updated.') + messages.success(request, _('Your preferences have been updated.')) else: - messages.error(request, 'Something went wrong.') + messages.error(request, _('Something went wrong.')) except MailmanApiError: return utils.render_api_error(request) except HTTPError as e: @@ -149,17 +145,15 @@ mm_user = MailmanUser.objects.get(address=request.user.email) formset_class = formset_factory(UserPreferences) formset = formset_class(request.POST) - zipped_data = zip(formset.forms, mm_user.subscriptions) if formset.is_valid(): - for form, subscription in zipped_data: + for form, subscription in zip(formset.forms, mm_user.subscriptions): preferences = subscription.preferences for key in form.cleaned_data.keys(): preferences[key] = form.cleaned_data[key] preferences.save() - messages.success( - request, 'Your preferences have been updated.') + messages.success(request, _('Your preferences have been updated.')) else: - messages.error(request, 'Something went wrong.') + messages.error(request, _('Something went wrong.')) except MailmanApiError: return utils.render_api_error(request) except HTTPError as e: @@ -231,8 +225,8 @@ try: profile.send_confirmation_link(request) except SMTPException: - messages.error(request, 'The email confirmation message could ' - 'not be sent. %s' % profile.activation_key) + messages.error(request, _('The email confirmation message could not be sent. %s') + % profile.activation_key) return render_to_response('postorius/user_address_activation_sent.html', context_instance=RequestContext(request)) return render_to_response('postorius/user_address_activation.html', @@ -322,14 +316,11 @@ except MailmanApiError: return utils.render_api_error(request) except HTTPError as e: - messages.error(request, _('The user could not be deleted:' - ' %s' % e.msg)) - return redirect("user_index") - messages.success(request, - _('The user %s has been deleted.' % email_id)) - return redirect("user_index") - return render_to_response(template, - {'user_id': user_id, 'email_id': email_id}, + messages.error(request, _('The user could not be deleted: %s') % e.msg) + return redirect('user_index') + messages.success(request, _('The user %s has been deleted.') % email_id) + return redirect('user_index') + return render_to_response(template, {'user_id': user_id, 'email_id': email_id}, context_instance=RequestContext(request)) @@ -341,8 +332,8 @@ except Mailman404Error: mailman_user = utils.get_client().create_user(user_email, '') mailman_user.add_address(address) - except (MailmanApiError, MailmanConnectionError) as e: - messages.error(request, 'The address could not be added.') + except (MailmanApiError, MailmanConnectionError): + messages.error(request, _('The address could not be added.')) def address_activation_link(request, activation_key):