Commit 294839ea by benjaoming

use gettext_lazy where appropriate, thanks @jluttine for starting work on this

parent fa01cfb2
......@@ -8,7 +8,8 @@ from datetime import timedelta
from django.utils import timezone
from django import forms
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe
from django.forms.util import flatatt
from six.moves import range
......@@ -54,7 +55,7 @@ class SpamProtectionMixin():
ip_address = request.META.get('REMOTE_ADDR', None)
if not (user or ip_address):
raise forms.ValidationError(_('Spam protection failed to find both a logged in user and an IP address.'))
raise forms.ValidationError(ugettext('Spam protection failed to find both a logged in user and an IP address.'))
def check_interval(from_time, max_count, interval_name):
from_time = timezone.now() - timedelta(minutes=settings.REVISIONS_MINUTES_LOOKBACK)
......@@ -67,7 +68,7 @@ class SpamProtectionMixin():
revisions = revisions.filter(ip_address=ip_address)
revisions = revisions.count()
if revisions >= max_count:
raise forms.ValidationError(_('Spam protection: You are only allowed to create or edit %(revisions)d article(s) per %(interval_name)s.') %
raise forms.ValidationError(ugettext('Spam protection: You are only allowed to create or edit %(revisions)d article(s) per %(interval_name)s.') %
{'revisions': max_count,
'interval_name': interval_name,})
......@@ -157,9 +158,9 @@ class EditForm(forms.Form, SpamProtectionMixin):
if self.no_clean or self.preview:
return cd
if not str(self.initial_revision.id) == str(self.presumed_revision):
raise forms.ValidationError(_('While you were editing, someone else changed the revision. Your contents have been automatically merged with the new contents. Please review the text below.'))
raise forms.ValidationError(ugettext('While you were editing, someone else changed the revision. Your contents have been automatically merged with the new contents. Please review the text below.'))
if cd['title'] == self.initial_revision.title and cd['content'] == self.initial_revision.content:
raise forms.ValidationError(_('No changes made. Nothing to save.'))
raise forms.ValidationError(ugettext('No changes made. Nothing to save.'))
self.check_spam()
return cd
......@@ -257,9 +258,9 @@ class CreateForm(forms.Form, SpamProtectionMixin):
def clean_slug(self):
slug = self.cleaned_data['slug']
if slug.startswith("_"):
raise forms.ValidationError(_('A slug may not begin with an underscore.'))
raise forms.ValidationError(ugettext('A slug may not begin with an underscore.'))
if slug == 'admin':
raise forms.ValidationError(_("'admin' is not a permitted slug name."))
raise forms.ValidationError(ugettext("'admin' is not a permitted slug name."))
if settings.URL_CASE_SENSITIVE:
already_existing_slug = models.URLPath.objects.filter(slug=slug, parent=self.urlpath_parent)
......@@ -270,16 +271,16 @@ class CreateForm(forms.Form, SpamProtectionMixin):
if already_existing_slug:
already_urlpath = already_existing_slug[0]
if already_urlpath.article and already_urlpath.article.current_revision.deleted:
raise forms.ValidationError(_('A deleted article with slug "%s" already exists.') % already_urlpath.slug)
raise forms.ValidationError(ugettext('A deleted article with slug "%s" already exists.') % already_urlpath.slug)
else:
raise forms.ValidationError(_('A slug named "%s" already exists.') % already_urlpath.slug)
raise forms.ValidationError(ugettext('A slug named "%s" already exists.') % already_urlpath.slug)
if settings.CHECK_SLUG_URL_AVAILABLE:
try:
# Fail validation if URL resolves to non-wiki app
match = resolve(self.urlpath_parent.path + '/' + slug + '/')
if match.app_name != 'wiki':
raise forms.ValidationError(_('This slug conflicts with an existing URL.'))
raise forms.ValidationError(ugettext('This slug conflicts with an existing URL.'))
except Resolver404:
pass
......@@ -308,9 +309,9 @@ class DeleteForm(forms.Form):
def clean(self):
cd = self.cleaned_data
if not cd['confirm']:
raise forms.ValidationError(_('You are not sure enough!'))
raise forms.ValidationError(ugettext('You are not sure enough!'))
if cd['revision'] != self.article.current_revision:
raise forms.ValidationError(_('While you tried to delete this article, it was modified. TAKE CARE!'))
raise forms.ValidationError(ugettext('While you tried to delete this article, it was modified. TAKE CARE!'))
return cd
......@@ -393,7 +394,7 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm):
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise forms.ValidationError(_('No user with that username'))
raise forms.ValidationError(ugettext('No user with that username'))
else:
user = None
else:
......
......@@ -2,7 +2,8 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from django import forms
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from wiki.plugins.attachments import models
from wiki.core.permissions import can_moderate
......@@ -101,14 +102,14 @@ class AttachmentArchiveForm(AttachmentForm):
except IllegalFileExtension as e:
raise forms.ValidationError(e)
except zipfile.BadZipfile:
raise forms.ValidationError(_("Not a zip file"))
raise forms.ValidationError(ugettext("Not a zip file"))
else:
return super(AttachmentArchiveForm, self).clean_file()
return uploaded_file
def clean(self):
if not can_moderate(self.article, self.request.user):
raise forms.ValidationError("User not allowed to moderate this article")
raise forms.ValidationError(ugettext("User not allowed to moderate this article"))
return self.cleaned_data
def save(self, *args, **kwargs):
......@@ -156,7 +157,7 @@ class DeleteForm(forms.Form):
def clean_confirm(self):
if not self.cleaned_data['confirm']:
raise forms.ValidationError(_('You are not sure enough!'))
raise forms.ValidationError(ugettext('You are not sure enough!'))
return True
class SearchForm(forms.Form):
......
......@@ -4,6 +4,7 @@ from __future__ import absolute_import
import os.path
from django.db import models
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from django.conf import settings as django_settings
......@@ -56,9 +57,9 @@ def extension_allowed(filename):
extension = filename.split(".")[-1]
except IndexError:
# No extension
raise IllegalFileExtension("No file extension found in filename. That's not okay!")
raise IllegalFileExtension(ugettext("No file extension found in filename. That's not okay!"))
if not extension.lower() in map(lambda x: x.lower(), settings.FILE_EXTENSIONS):
raise IllegalFileExtension("The following filename is illegal: %s. Extension has to be one of %s" %
raise IllegalFileExtension(ugettext("The following filename is illegal: %s. Extension has to be one of %s") %
(filename, ", ".join(settings.FILE_EXTENSIONS)))
return extension
......
from __future__ import unicode_literals
from __future__ import absolute_import
from django import forms
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from wiki.core.plugins.base import PluginSidebarFormMixin
from wiki.plugins.images import models
......@@ -16,7 +17,7 @@ class SidebarForm(PluginSidebarFormMixin):
self.fields['image'].required = True
def get_usermessage(self):
return _("New image %s was successfully uploaded. You can use it by selecting it from the list of available images.") % self.instance.get_filename()
return ugettext("New image %s was successfully uploaded. You can use it by selecting it from the list of available images.") % self.instance.get_filename()
def save(self, *args, **kwargs):
if not self.instance.id:
......@@ -65,5 +66,5 @@ class PurgeForm(forms.Form):
def clean_confirm(self):
confirm = self.cleaned_data['confirm']
if not confirm:
raise forms.ValidationError(_('You are not sure enough!'))
raise forms.ValidationError(ugettext('You are not sure enough!'))
return confirm
......@@ -2,7 +2,8 @@ from __future__ import unicode_literals
from __future__ import absolute_import
from django import forms
from django.forms.models import modelformset_factory, BaseModelFormSet
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from django_nyt.models import Settings, NotificationType, Subscription
from django_nyt import settings as notify_settings
......@@ -16,19 +17,20 @@ from wiki.plugins.notifications import models
class SettingsModelChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
return _("Receive notifications %(interval)s") % {
'interval': obj.get_interval_display()
}
return ugettext(
"Receive notifications %(interval)s"
) % {
'interval': obj.get_interval_display()
}
class ArticleSubscriptionModelMultipleChoiceField(forms.ModelMultipleChoiceField):
def label_from_instance(self, obj):
return _("%(title)s - %(url)s" % {
'title': obj.article.current_revision.title,
'url': obj.article.get_absolute_url()
}
)
return ugettext("%(title)s - %(url)s") % {
'title': obj.article.current_revision.title,
'url': obj.article.get_absolute_url()
}
class SettingsModelForm(forms.ModelForm):
......@@ -40,17 +42,17 @@ class SettingsModelForm(forms.ModelForm):
self.__editing_instance = True
self.fields['delete_subscriptions'] = ArticleSubscriptionModelMultipleChoiceField(
models.ArticleSubscription.objects.filter(subscription__settings=instance),
label=_("Remove subscriptions"),
label=ugettext("Remove subscriptions"),
required=False,
help_text=_("Select article subscriptions to remove from notifications"),
help_text=ugettext("Select article subscriptions to remove from notifications"),
initial = models.ArticleSubscription.objects.none(),
)
self.fields['email'] = forms.TypedChoiceField(
label=_("Email digests"),
choices = (
(0, _('Unchanged (selected on each article)')),
(1, _('No emails')),
(2, _('Email on any change')),
(0, ugettext('Unchanged (selected on each article)')),
(1, ugettext('No emails')),
(2, ugettext('Email on any change')),
),
coerce=lambda x: int(x) if not x is None else None,
widget=forms.RadioSelect(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment