Commit fd2475db by Russell Jones Committed by benjaoming

Start using from __future__ import unicode_literals everywhere

Remove u from  u"" and u''
Start to remove calls to unicode()
parent b74539f7
......@@ -29,6 +29,7 @@ Options:
"""
from __future__ import print_function
from __future__ import unicode_literals
from docopt import docopt
import os
import re
......
......@@ -18,6 +18,7 @@
# Unused feature, atm. everything is bundled with django-wiki
VERSION = "0.0.4"
from __future__ import unicode_literals
from django.contrib.contenttypes.models import ContentType
from django.db.models import Model
from django.utils.translation import ugettext as _
......@@ -52,7 +53,7 @@ def notify(message, key, target_object=None, url=None, filter_exclude={}):
if target_object:
if not isinstance(target_object, Model):
raise TypeError(_(u"You supplied a target_object that's not an instance of a django Model."))
raise TypeError(_("You supplied a target_object that's not an instance of a django Model."))
object_id = target_object.id
else:
object_id = None
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
......@@ -15,12 +16,12 @@ class NotificationType(models.Model):
key = models.CharField(
max_length=128,
primary_key=True,
verbose_name=_(u'unique key'),
verbose_name=_('unique key'),
unique=True
)
label = models.CharField(
max_length=128,
verbose_name=_(u'verbose name'),
verbose_name=_('verbose name'),
blank=True,
null=True
)
......@@ -31,8 +32,8 @@ class NotificationType(models.Model):
class Meta:
db_table = settings.DB_TABLE_PREFIX + '_notificationtype'
verbose_name = _(u'type')
verbose_name_plural = _(u'types')
verbose_name = _('type')
verbose_name_plural = _('types')
class Settings(models.Model):
"""
......@@ -44,18 +45,18 @@ class Settings(models.Model):
)
interval = models.SmallIntegerField(
choices=settings.INTERVALS,
verbose_name=_(u'interval'),
verbose_name=_('interval'),
default=settings.INTERVALS_DEFAULT
)
def __unicode__(self):
obj_name = _(u"Settings for %s") % self.user.username
obj_name = _("Settings for %s") % self.user.username
return unicode(obj_name)
class Meta:
db_table = settings.DB_TABLE_PREFIX + '_settings'
verbose_name = _(u'settings')
verbose_name_plural = _(u'settings')
verbose_name = _('settings')
verbose_name_plural = _('settings')
class Subscription(models.Model):
......@@ -65,7 +66,7 @@ class Subscription(models.Model):
max_length=64,
null=True,
blank=True,
help_text=_(u'Leave this blank to subscribe to any kind of object')
help_text=_('Leave this blank to subscribe to any kind of object')
)
send_emails = models.BooleanField(default=True)
latest = models.ForeignKey('Notification',
......@@ -80,8 +81,8 @@ class Subscription(models.Model):
class Meta:
db_table = settings.DB_TABLE_PREFIX + '_subscription'
verbose_name = _(u'subscription')
verbose_name_plural = _(u'subscriptions')
verbose_name = _('subscription')
verbose_name_plural = _('subscriptions')
class Notification(models.Model):
......@@ -93,7 +94,7 @@ class Notification(models.Model):
)
message = models.TextField()
url = models.CharField(
verbose_name=_(u'link for notification'),
verbose_name=_('link for notification'),
blank=True,
null=True,
max_length=200
......@@ -103,9 +104,9 @@ class Notification(models.Model):
created = models.DateTimeField(auto_now_add=True)
occurrences = models.PositiveIntegerField(
default=1,
verbose_name=_(u'occurrences'),
verbose_name=_('occurrences'),
help_text=_(
u'If the same notification was fired multiple '
'If the same notification was fired multiple '
'times with no intermediate notifications'
)
)
......@@ -167,6 +168,6 @@ class Notification(models.Model):
class Meta:
db_table = settings.DB_TABLE_PREFIX + '_notification'
verbose_name = _(u'notification')
verbose_name_plural = _(u'notifications')
verbose_name = _('notification')
verbose_name_plural = _('notifications')
ordering = ('-id',)
from __future__ import unicode_literals
import markdown
from wiki.core.plugins import registry as plugin_registry
......@@ -15,4 +17,4 @@ class ArticleMarkdown(markdown.Markdown):
def article_markdown(text, article, *args, **kwargs):
md = ArticleMarkdown(article, *args, **kwargs)
return md.convert(unicode(text))
return md.convert(text)
from __future__ import unicode_literals
from django.utils.translation import ugettext as _
"""Base classes for different plugin objects.
......@@ -22,12 +23,12 @@ class BasePlugin(object):
'root': [], # General urlpatterns that will reside in /wiki/plugins/plugin-slug/...
'article': [], # urlpatterns that receive article_id or urlpath, i.e. /wiki/ArticleName/plugin/plugin-slug/...
}
article_tab = None #(_(u'Attachments'), "icon-file")
article_tab = None #(_('Attachments'), "icon-file")
article_view = None # A view for article_id/plugin/slug/
notifications = [] # A list of notification handlers to be subscribed if the notification system is active
# Example
# [{'model': models.AttachmentRevision,
# 'message': lambda obj: _(u"A file was changed: %s") % obj.get_filename(),
# 'message': lambda obj: _("A file was changed: %s") % obj.get_filename(),
# 'key': ARTICLE_EDIT,
# 'created': True,
# 'get_article': lambda obj: obj.attachment.article}
......@@ -50,7 +51,7 @@ class PluginSidebarFormMixin(forms.ModelForm):
pass
class PluginSettingsFormMixin(object):
settings_form_headline = _(u'Settings for plugin')
settings_form_headline = _('Settings for plugin')
settings_order = 1
settings_write_access = False
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.contrib.auth.models import Group
......@@ -20,29 +21,29 @@ class Article(models.Model):
objects = managers.ArticleManager()
current_revision = models.OneToOneField('ArticleRevision',
verbose_name=_(u'current revision'),
verbose_name=_('current revision'),
blank=True, null=True, related_name='current_set',
help_text=_(u'The revision being displayed for this article. If you need to do a roll-back, simply change the value of this field.'),
help_text=_('The revision being displayed for this article. If you need to do a roll-back, simply change the value of this field.'),
)
created = models.DateTimeField(auto_now_add=True, verbose_name=_(u'created'),)
modified = models.DateTimeField(auto_now=True, verbose_name=_(u'modified'),
help_text=_(u'Article properties last modified'))
created = models.DateTimeField(auto_now_add=True, verbose_name=_('created'),)
modified = models.DateTimeField(auto_now=True, verbose_name=_('modified'),
help_text=_('Article properties last modified'))
owner = models.ForeignKey(compat.USER_MODEL, verbose_name=_('owner'),
blank=True, null=True, related_name='owned_articles',
help_text=_(u'The owner of the article, usually the creator. The owner always has both read and write access.'),
help_text=_('The owner of the article, usually the creator. The owner always has both read and write access.'),
on_delete=models.SET_NULL)
group = models.ForeignKey(Group, verbose_name=_('group'),
blank=True, null=True,
help_text=_(u'Like in a UNIX file system, permissions can be given to a user according to group membership. Groups are handled through the Django auth system.'),
help_text=_('Like in a UNIX file system, permissions can be given to a user according to group membership. Groups are handled through the Django auth system.'),
on_delete=models.SET_NULL)
group_read = models.BooleanField(default=True, verbose_name=_(u'group read access'))
group_write = models.BooleanField(default=True, verbose_name=_(u'group write access'))
other_read = models.BooleanField(default=True, verbose_name=_(u'others read access'))
other_write = models.BooleanField(default=True, verbose_name=_(u'others write access'))
group_read = models.BooleanField(default=True, verbose_name=_('group read access'))
group_write = models.BooleanField(default=True, verbose_name=_('group write access'))
other_read = models.BooleanField(default=True, verbose_name=_('others read access'))
other_write = models.BooleanField(default=True, verbose_name=_('others write access'))
# PERMISSIONS
def can_read(self, user):
......@@ -140,15 +141,15 @@ class Article(models.Model):
def __unicode__(self):
if self.current_revision:
return self.current_revision.title
obj_name = _(u'Article without content (%(id)d)') % {'id': self.id}
obj_name = _('Article without content (%(id)d)') % {'id': self.id}
return unicode(obj_name)
class Meta:
app_label = settings.APP_LABEL
permissions = (
("moderate", _(u"Can edit all articles and lock/unlock/restore")),
("assign", _(u"Can change ownership of any article")),
("grant", _(u"Can assign permissions to other users")),
("moderate", _("Can edit all articles and lock/unlock/restore")),
("assign", _("Can change ownership of any article")),
("grant", _("Can assign permissions to other users")),
)
def render(self, preview_content=None):
......@@ -199,8 +200,8 @@ class ArticleForObject(models.Model):
class Meta:
app_label = settings.APP_LABEL
verbose_name = _(u'Article for object')
verbose_name_plural = _(u'Articles for object')
verbose_name = _('Article for object')
verbose_name_plural = _('Articles for object')
# Do not allow several objects
unique_together = ('content_type', 'object_id')
......@@ -208,7 +209,7 @@ class BaseRevisionMixin(models.Model):
"""This is an abstract model used as a mixin: Do not override any of the
core model methods but respect the inheritor's freedom to do so itself."""
revision_number = models.IntegerField(editable=False, verbose_name=_(u'revision number'))
revision_number = models.IntegerField(editable=False, verbose_name=_('revision number'))
user_message = models.TextField(blank=True,)
automatic_log = models.TextField(blank=True, editable=False,)
......@@ -229,11 +230,11 @@ class BaseRevisionMixin(models.Model):
# but the actual related object. If the latest revision says "deleted=True" then
# the related object should be regarded as deleted.
deleted = models.BooleanField(
verbose_name=_(u'deleted'),
verbose_name=_('deleted'),
default=False,
)
locked = models.BooleanField(
verbose_name=_(u'locked'),
verbose_name=_('locked'),
default=False,
)
......@@ -253,22 +254,22 @@ class ArticleRevision(BaseRevisionMixin, models.Model):
copy, do NEVER create m2m relationships."""
article = models.ForeignKey('Article', on_delete=models.CASCADE,
verbose_name=_(u'article'))
verbose_name=_('article'))
# This is where the content goes, with whatever markup language is used
content = models.TextField(blank=True, verbose_name=_(u'article contents'))
content = models.TextField(blank=True, verbose_name=_('article contents'))
# This title is automatically set from either the article's title or
# the last used revision...
title = models.CharField(max_length=512, verbose_name=_(u'article title'),
null=False, blank=False, help_text=_(u'Each revision contains a title field that must be filled out, even if the title has not changed'))
title = models.CharField(max_length=512, verbose_name=_('article title'),
null=False, blank=False, help_text=_('Each revision contains a title field that must be filled out, even if the title has not changed'))
# TODO:
# Allow a revision to redirect to another *article*. This
# way, we can redirects and still maintain old content.
#redirect = models.ForeignKey('Article', null=True, blank=True,
# verbose_name=_(u'redirect'),
# help_text=_(u'If set, the article will redirect to the contents of another article.'),
# verbose_name=_('redirect'),
# help_text=_('If set, the article will redirect to the contents of another article.'),
# related_name='redirect_set')
def __unicode__(self):
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.db.models import signals
......@@ -34,7 +35,7 @@ class ArticlePlugin(models.Model):
properties in the future..."""
article = models.ForeignKey('wiki.Article', on_delete=models.CASCADE,
verbose_name=_(u"article"))
verbose_name=_("article"))
deleted = models.BooleanField(default=False)
......@@ -74,8 +75,8 @@ class ReusablePlugin(ArticlePlugin):
# The article on which the plugin was originally created.
# Used to apply permissions.
ArticlePlugin.article.on_delete=models.SET_NULL
ArticlePlugin.article.verbose_name=_(u'original article')
ArticlePlugin.article.help_text=_(u'Permissions are inherited from this article')
ArticlePlugin.article.verbose_name=_('original article')
ArticlePlugin.article.help_text=_('Permissions are inherited from this article')
ArticlePlugin.article.null = True
ArticlePlugin.article.blank = True
......@@ -141,7 +142,7 @@ class SimplePlugin(ArticlePlugin):
self.article = article
def get_logmessage(self):
return _(u"A plugin was changed")
return _("A plugin was changed")
def save(self, *args, **kwargs):
if not self.pk:
......@@ -170,9 +171,9 @@ class RevisionPlugin(ArticlePlugin):
"""
# The current revision of this plugin, if any!
current_revision = models.OneToOneField('RevisionPluginRevision',
verbose_name=_(u'current revision'),
verbose_name=_('current revision'),
blank=True, null=True, related_name='plugin_set',
help_text=_(u'The revision being displayed for this plugin. '
help_text=_('The revision being displayed for this plugin. '
'If you need to do a roll-back, simply change the value of this field.'),
)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
#^was before coding line, is this required?
import logging
from django.contrib.contenttypes import generic
......@@ -55,12 +56,12 @@ class URLPath(MPTTModel):
Article,
on_delete=models.CASCADE,
editable=False,
verbose_name=_(u'Cache lookup value for articles'),
verbose_name=_('Cache lookup value for articles'),
)
SLUG_MAX_LENGTH = 50
slug = models.SlugField(verbose_name=_(u'slug'), null=True, blank=True,
slug = models.SlugField(verbose_name=_('slug'), null=True, blank=True,
max_length=SLUG_MAX_LENGTH)
site = models.ForeignKey(Site)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
......@@ -156,7 +157,7 @@ class URLPath(MPTTModel):
def __unicode__(self):
path = self.path
return path if path else ugettext(u"(root)")
return path if path else ugettext("(root)")
def save(self, *args, **kwargs):
super(URLPath, self).save(*args, **kwargs)
......@@ -166,19 +167,19 @@ class URLPath(MPTTModel):
super(URLPath, self).delete(*args, **kwargs)
class Meta:
verbose_name = _(u'URL path')
verbose_name_plural = _(u'URL paths')
verbose_name = _('URL path')
verbose_name_plural = _('URL paths')
unique_together = ('site', 'parent', 'slug')
app_label = settings.APP_LABEL
def clean(self, *args, **kwargs):
if self.slug and not self.parent:
raise ValidationError(_(u'Sorry but you cannot have a root article with a slug.'))
raise ValidationError(_('Sorry but you cannot have a root article with a slug.'))
if not self.slug and self.parent:
raise ValidationError(_(u'A non-root note must always have a slug.'))
raise ValidationError(_('A non-root note must always have a slug.'))
if not self.parent:
if URLPath.objects.root_nodes().filter(site=self.site).exclude(id=self.id):
raise ValidationError(_(u'There is already a root node on %s') % self.site)
raise ValidationError(_('There is already a root node on %s') % self.site)
super(URLPath, self).clean(*args, **kwargs)
@classmethod
......@@ -298,10 +299,10 @@ def on_article_delete(instance, *args, **kwargs):
other_read = False,
other_write = False)
article.add_revision(ArticleRevision(
content=_(u'Articles who lost their parents\n'
content=_('Articles who lost their parents\n'
'===============================\n\n'
'The children of this article have had their parents deleted. You should probably find a new home for them.'),
title=_(u"Lost and found")))
title=_("Lost and found")))
ns.lost_and_found = URLPath.objects.create(slug=settings.LOST_AND_FOUND_SLUG,
parent=URLPath.root(),
site=site,
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
from django.utils.translation import ugettext as _
......@@ -13,8 +14,8 @@ from wiki.plugins.attachments.models import IllegalFileExtension
class AttachmentForm(forms.ModelForm):
description = forms.CharField(
label=_(u'Description'),
help_text=_(u'A short summary of what the file contains'),
label=_('Description'),
help_text=_('A short summary of what the file contains'),
required=False
)
......@@ -63,8 +64,8 @@ class AttachmentForm(forms.ModelForm):
class AttachmentReplaceForm(AttachmentForm):
replace = forms.BooleanField(
label=_(u'Remove previous'),
help_text=_(u'Remove previous attachment revisions and their files (to '
label=_('Remove previous'),
help_text=_('Remove previous attachment revisions and their files (to '
'save space)?'),
required=False,
)
......@@ -73,13 +74,13 @@ class AttachmentReplaceForm(AttachmentForm):
class AttachmentArchiveForm(AttachmentForm):
file = forms.FileField( #@ReservedAssignment
label=_(u'File or zip archive'),
label=_('File or zip archive'),
required=True
)
unzip_archive = forms.BooleanField(
label=_(u'Unzip file'),
help_text=_(u'Create individual attachments for files in a .zip file - directories do not work.'),
label=_('Unzip file'),
help_text=_('Create individual attachments for files in a .zip file - directories do not work.'),
required=False
)
......@@ -99,7 +100,7 @@ class AttachmentArchiveForm(AttachmentForm):
except IllegalFileExtension as e:
raise forms.ValidationError(e)
except zipfile.BadZipfile:
raise forms.ValidationError(_(u"Not a zip file"))
raise forms.ValidationError(_("Not a zip file"))
else:
return super(AttachmentArchiveForm, self).clean_file()
return uploaded_file
......@@ -149,12 +150,12 @@ class AttachmentArchiveForm(AttachmentForm):
class DeleteForm(forms.Form):
"""This form is both used for dereferencing and deleting attachments"""
confirm = forms.BooleanField(label=_(u'Yes I am sure...'),
confirm = forms.BooleanField(label=_('Yes I am sure...'),
required=False)
def clean_confirm(self):
if not self.cleaned_data['confirm']:
raise forms.ValidationError(_(u'You are not sure enough!'))
raise forms.ValidationError(_('You are not sure enough!'))
return True
class SearchForm(forms.Form):
......
from __future__ import unicode_literals
import markdown
import re
......@@ -52,7 +53,7 @@ class AttachmentPreprocessor(markdown.preprocessors.Preprocessor):
}))
line = self.markdown.htmlStash.store(html, safe=True)
except models.Attachment.DoesNotExist:
line = line.replace(m.group(1), u"""<span class="attachment attachment-deleted">Attachment with ID #%s is deleted.</span>""" % attachment_id)
line = line.replace(m.group(1), """<span class="attachment attachment-deleted">Attachment with ID #%s is deleted.</span>""" % attachment_id)
line = before + line + after
new_text.append(line)
return new_text
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf.urls import patterns, url, include
from django.utils.translation import ugettext as _
......@@ -21,7 +22,7 @@ class AttachmentPlugin(BasePlugin):
)
}
article_tab = (_(u'Attachments'), "icon-file")
article_tab = (_('Attachments'), "icon-file")
article_view = views.AttachmentView().dispatch
# List of notifications to construct signal handlers for. This
......@@ -29,10 +30,10 @@ class AttachmentPlugin(BasePlugin):
notifications = [{
'model': models.AttachmentRevision,
'message': lambda obj: (
_(u"A file was changed: %s")
_("A file was changed: %s")
if not obj.deleted
else
_(u"A file was deleted: %s")
_("A file was deleted: %s")
) % truncate_title(obj.get_filename()),
'key': ARTICLE_EDIT,
'created': True,
......
from __future__ import unicode_literals
from django import forms
from django.utils.translation import ugettext as _
......@@ -14,7 +15,7 @@ class SidebarForm(PluginSidebarFormMixin):
self.fields['image'].required = True
def get_usermessage(self):
return _(u"New image %s was successfully uploaded. You can use it by selecting it from the list of available images.") % self.instance.get_filename()
return _("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:
......@@ -58,10 +59,10 @@ class RevisionForm(forms.ModelForm):
class PurgeForm(forms.Form):
confirm = forms.BooleanField(label=_(u'Are you sure?'), required=False)
confirm = forms.BooleanField(label=_('Are you sure?'), required=False)
def clean_confirm(self):
confirm = self.cleaned_data['confirm']
if not confirm:
raise forms.ValidationError(_(u'You are not sure enough!'))
return confirm
\ No newline at end of file
raise forms.ValidationError(_('You are not sure enough!'))
return confirm
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf.urls import patterns, url
from django.utils.translation import ugettext as _
......@@ -24,7 +25,7 @@ class ImagePlugin(BasePlugin):
# is handled inside the notifications plugin.
notifications = [
{'model': models.ImageRevision,
'message': lambda obj: _(u"An image was added: %s") % truncate_title(obj.get_filename()),
'message': lambda obj: _("An image was added: %s") % truncate_title(obj.get_filename()),
'key': ARTICLE_EDIT,
'created': False,
'ignore': lambda revision: bool(revision.previous_revision), # Ignore if there is a previous revision... the image isn't new
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import markdown
import re
from six import string_types
......@@ -47,11 +48,11 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
value = True
if isinstance(value, string_types):
# If value is enclosed with ': Remove and remove escape sequences
if value.startswith(u"'") and len(value) > 2:
if value.startswith("'") and len(value) > 2:
value = value[1:-1]
value = value.replace(u"\\\\", u"¤KEEPME¤")
value = value.replace(u"\\", u"")
value = value.replace(u"¤KEEPME¤", u"\\")
value = value.replace("\\\\", "¤KEEPME¤")
value = value.replace("\\", "")
value = value.replace("¤KEEPME¤", "\\")
kwargs_dict[str(arg)] = value
line = getattr(self, macro)(**kwargs_dict)
else:
......@@ -70,26 +71,26 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
)
return self.markdown.htmlStash.store(html, safe=True)
article_list.meta = dict(
short_description = _(u'Article list'),
help_text = _(u'Insert a list of articles in this level.'),
example_code = _(u'[article_list depth:2]'),
short_description = _('Article list'),
help_text = _('Insert a list of articles in this level.'),
example_code = _('[article_list depth:2]'),
args = {'depth': _('Maximum depth to show levels for.')}
)
def toc(self):
return "[TOC]"
toc.meta = dict(
short_description = _(u'Table of contents'),
help_text = _(u'Insert a table of contents matching the headings.'),
example_code = _(u'[TOC]'),
short_description = _('Table of contents'),
help_text = _('Insert a table of contents matching the headings.'),
example_code = _('[TOC]'),
args = {}
)
def wikilink(self):
return ""
wikilink.meta = dict(
short_description = _(u'WikiLinks'),
help_text = _(u'Insert a link to another wiki page with a short notation.'),
example_code = _(u'[[WikiLink]]'),
short_description = _('WikiLinks'),
help_text = _('Insert a link to another wiki page with a short notation.'),
example_code = _('[[WikiLink]]'),
args = {}
)
from __future__ import unicode_literals
from django import forms
from django.forms.models import modelformset_factory, BaseModelFormSet
from django.utils.translation import ugettext as _
......@@ -14,7 +15,7 @@ from wiki.plugins.notifications import models
class SettingsModelChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
return _(u"Receive notifications %(interval)s") % {
return _("Receive notifications %(interval)s") % {
'interval': obj.get_interval_display()
}
......@@ -22,7 +23,7 @@ class SettingsModelChoiceField(forms.ModelChoiceField):
class ArticleSubscriptionModelMultipleChoiceField(forms.ModelMultipleChoiceField):
def label_from_instance(self, obj):
return _(u"%(title)s - %(url)s" % {
return _("%(title)s - %(url)s" % {
'title': obj.article.current_revision.title,
'url': obj.article.get_absolute_url()
}
......@@ -38,17 +39,17 @@ class SettingsModelForm(forms.ModelForm):
self.__editing_instance = True
self.fields['delete_subscriptions'] = ArticleSubscriptionModelMultipleChoiceField(
models.ArticleSubscription.objects.filter(settings=instance),
label=_(u"Remove subscriptions"),
label=_("Remove subscriptions"),
required=False,
help_text=_(u"Select article subscriptions to remove from notifications"),
help_text=_("Select article subscriptions to remove from notifications"),
initial = models.ArticleSubscription.objects.none(),
)
self.fields['email'] = forms.TypedChoiceField(
label=_(u"Email digests"),
label=_("Email digests"),
choices = (
(0, _(u'Unchanged (selected on each article)')),
(1, _(u'No emails')),
(2, _(u'Email on any change')),
(0, _('Unchanged (selected on each article)')),
(1, _('No emails')),
(2, _('Email on any change')),
),
coerce=lambda x: int(x) if not x is None else None,
widget=forms.RadioSelect(),
......@@ -98,22 +99,22 @@ SettingsFormSet = modelformset_factory(
class SubscriptionForm(PluginSettingsFormMixin, forms.Form):
settings_form_headline = _(u'Notifications')
settings_form_headline = _('Notifications')
settings_order = 1
settings_write_access = False
settings = SettingsModelChoiceField(
Settings,
empty_label=None,
label=_(u'Settings')
label=_('Settings')
)
edit = forms.BooleanField(
required=False,
label=_(u'When this article is edited')
label=_('When this article is edited')
)
edit_email = forms.BooleanField(
required=False,
label=_(u'Also receive emails about article edits'),
label=_('Also receive emails about article edits'),
widget=forms.CheckboxInput(
attrs={'onclick': mark_safe("$('#id_edit').attr('checked', $(this).is(':checked'));")}
)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.db.models import signals
......@@ -15,7 +16,7 @@ from wiki.plugins.notifications.util import get_title
class ArticleSubscription(ArticlePlugin, Subscription):
def __unicode__(self):
title = (_(u"%(user)s subscribing to %(article)s (%(type)s)") %
title = (_("%(user)s subscribing to %(article)s (%(type)s)") %
{'user': self.settings.user.username,
'article': self.article.current_revision.title,
'type': self.notification_type.label})
......@@ -37,13 +38,13 @@ def post_article_revision_save(**kwargs):
url = default_url(instance.article)
filter_exclude = {'settings__user': instance.user}
if instance.deleted:
notify(_(u'Article deleted: %s') % get_title(instance), settings.ARTICLE_EDIT,
notify(_('Article deleted: %s') % get_title(instance), settings.ARTICLE_EDIT,
target_object=instance.article, url=url, filter_exclude=filter_exclude)
elif instance.previous_revision:
notify(_(u'Article modified: %s') % get_title(instance), settings.ARTICLE_EDIT,
notify(_('Article modified: %s') % get_title(instance), settings.ARTICLE_EDIT,
target_object=instance.article, url=url, filter_exclude=filter_exclude)
else:
notify(_(u'New article created: %s') % get_title(instance), settings.ARTICLE_EDIT,
notify(_('New article created: %s') % get_title(instance), settings.ARTICLE_EDIT,
target_object=instance, url=url, filter_exclude=filter_exclude)
# Whenever a new revision is created, we notifý users that an article
......
from __future__ import unicode_literals
from django.utils.translation import ugettext as _
def get_title(article):
......@@ -7,7 +8,7 @@ def get_title(article):
def truncate_title(title):
"""Truncate a title (of an article, file, image etc) to be displayed in notifications messages."""
if not title:
return _(u"(none)")
return _("(none)")
if len(title) > 25:
return "%s..." % title[:22]
return title
# Create your views here.
from __future__ import unicode_literals
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect
......@@ -27,7 +28,7 @@ class NotificationSettings(FormView):
).select_related('article', 'article__current_revision')
messages.info(
self.request,
_(u"You will receive notifications %(interval)s for "
_("You will receive notifications %(interval)s for "
"%(articles)d articles") %
{
'interval': settings.get_interval_display(),
......@@ -54,4 +55,4 @@ class NotificationSettings(FormView):
).select_related('article', 'article__current_revision')
)
return context
\ No newline at end of file
......@@ -10,6 +10,7 @@ SETTINGS.LOGIN_URL
SETTINGS.LOGOUT_URL
"""
from __future__ import unicode_literals
from django.conf import settings as django_settings
from django.contrib import messages
from django.contrib.auth import logout as auth_logout, login as auth_login
......@@ -42,7 +43,7 @@ class Signup(CreateView):
return redirect(settings.SIGNUP_URL)
# Allow superusers to use signup page...
if not request.user.is_superuser and not settings.ACCOUNT_SIGNUP_ALLOWED:
c = RequestContext(request, {'error_msg': _(u'Account signup is only allowed for administrators.'),
c = RequestContext(request, {'error_msg': _('Account signup is only allowed for administrators.'),
})
return render_to_response("wiki/error.html", context_instance=c)
......@@ -55,7 +56,7 @@ class Signup(CreateView):
return context
def get_success_url(self, *args):
messages.success(self.request, _(u'You are now signed up... and now you can sign in!'))
messages.success(self.request, _('You are now signed up... and now you can sign in!'))
return reverse("wiki:login")
......@@ -68,7 +69,7 @@ class Logout(View):
def get(self, request, *args, **kwargs):
auth_logout(request)
messages.info(request, _(u"You are no longer logged in. Bye bye!"))
messages.info(request, _("You are no longer logged in. Bye bye!"))
return redirect("wiki:root")
......@@ -101,7 +102,7 @@ class Login(FormView):
def form_valid(self, form, *args, **kwargs):
auth_login(self.request, form.get_user())
messages.info(self.request, _(u"You are now logged in! Have fun!"))
messages.info(self.request, _("You are now logged in! Have fun!"))
if self.request.GET.get("next", None):
return redirect(self.request.GET['next'])
if django_settings.LOGIN_REDIRECT_URL:
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import difflib
import logging
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from django.db import transaction
from django.shortcuts import render_to_response, redirect, get_object_or_404
from django.template.context import RequestContext
from django.utils.decorators import method_decorator
......@@ -89,16 +91,17 @@ class Create(FormView, ArticleMixin):
'other_read': self.article.other_read,
'other_write': self.article.other_write,
})
messages.success(self.request, _(u"New article '%s' created.") % self.newpath.article.current_revision.title)
messages.success(self.request, _("New article '%s' created.") % self.newpath.article.current_revision.title)
transaction.commit()
# TODO: Handle individual exceptions better and give good feedback.
except Exception, e:
log.exception("Exception creating article.")
transaction.rollback()
if self.request.user.is_superuser:
messages.error(self.request, _(u"There was an error creating this article: %s") % str(e))
messages.error(self.request, _("There was an error creating this article: %s") % str(e))
else:
messages.error(self.request, _(u"There was an error creating this article."))
messages.error(self.request, _("There was an error creating this article."))
transaction.commit()
return redirect('wiki:get', '')
url = self.get_success_url()
......@@ -174,7 +177,7 @@ class Delete(FormView, ArticleMixin):
cannot_delete_children = True
if self.cannot_delete_root or cannot_delete_children:
messages.error(self.request, _(u'This article cannot be deleted because it has children or is a root article.'))
messages.error(self.request, _('This article cannot be deleted because it has children or is a root article.'))
return redirect('wiki:get', article_id=self.article.id)
......@@ -183,14 +186,14 @@ class Delete(FormView, ArticleMixin):
if self.urlpath:
self.urlpath.delete_subtree()
self.article.delete()
messages.success(self.request, _(u'This article together with all its contents are now completely gone! Thanks!'))
messages.success(self.request, _('This article together with all its contents are now completely gone! Thanks!'))
else:
revision = models.ArticleRevision()
revision.inherit_predecessor(self.article)
revision.set_from_request(self.request)
revision.deleted = True
self.article.add_revision(revision)
messages.success(self.request, _(u'The article "%s" is now marked as deleted! Thanks for keeping the site free from unwanted material!') % revision.title)
messages.success(self.request, _('The article "%s" is now marked as deleted! Thanks for keeping the site free from unwanted material!') % revision.title)
return self.get_success_url()
def get_success_url(self):
......@@ -278,7 +281,7 @@ class Edit(FormView, ArticleMixin):
if usermessage:
messages.success(self.request, usermessage)
else:
messages.success(self.request, _(u'Your changes were saved.'))
messages.success(self.request, _('Your changes were saved.'))
title = form.cleaned_data['unsaved_article_title']
content = form.cleaned_data['unsaved_article_content']
......@@ -311,7 +314,7 @@ class Edit(FormView, ArticleMixin):
revision.deleted = False
revision.set_from_request(self.request)
self.article.add_revision(revision)
messages.success(self.request, _(u'A new revision of the article was succesfully added.'))
messages.success(self.request, _('A new revision of the article was succesfully added.'))
return self.get_success_url()
def get_success_url(self):
......@@ -366,7 +369,7 @@ class Deleted(Delete):
revision.deleted = False
revision.automatic_log = _('Restoring article')
self.article.add_revision(revision)
messages.success(request, _(u'The article "%s" and its children are now restored.') % revision.title)
messages.success(request, _('The article "%s" and its children are now restored.') % revision.title)
if self.urlpath:
return redirect('wiki:get', path=self.urlpath.path)
else:
......@@ -598,7 +601,7 @@ class ChangeRevisionView(RedirectView):
revision = get_object_or_404(models.ArticleRevision, article=self.article, id=self.kwargs['revision_id'])
self.article.current_revision = revision
self.article.save()
messages.success(self.request, _(u"The article %(title)s is now set to display revision #%(revision_number)d") % {
messages.success(self.request, _("The article %(title)s is now set to display revision #%(revision_number)d") % {
'title': revision.title,
'revision_number': revision.revision_number,
})
......@@ -659,7 +662,7 @@ def diff(request, revision_id, other_revision_id=None):
other_changes = []
if not other_revision or other_revision.title != revision.title:
other_changes.append((_(u'New title'), revision.title))
other_changes.append((_('New title'), revision.title))
return dict(diff=list(diff), other_changes=other_changes)
......@@ -679,7 +682,7 @@ def merge(request, article, revision_id, urlpath=None, template_file="wiki/previ
old_revision = article.current_revision
if revision.deleted:
c = RequestContext(request, {'error_msg': _(u'You cannot merge with a deleted revision'),
c = RequestContext(request, {'error_msg': _('You cannot merge with a deleted revision'),
'article': article,
'urlpath': urlpath})
return render_to_response("wiki/error.html", context_instance=c)
......@@ -690,7 +693,7 @@ def merge(request, article, revision_id, urlpath=None, template_file="wiki/previ
new_revision.locked = False
new_revision.title=article.current_revision.title
new_revision.content=content
new_revision.automatic_log = (_(u'Merge between revision #%(r1)d and revision #%(r2)d') %
new_revision.automatic_log = (_('Merge between revision #%(r1)d and revision #%(r2)d') %
{'r1': revision.revision_number,
'r2': old_revision.revision_number})
article.add_revision(new_revision, save=True)
......@@ -698,7 +701,7 @@ def merge(request, article, revision_id, urlpath=None, template_file="wiki/previ
old_revision.simpleplugin_set.all().update(article_revision=new_revision)
revision.simpleplugin_set.all().update(article_revision=new_revision)
messages.success(request, _(u'A new revision was created: Merge between revision #%(r1)d and revision #%(r2)d') %
messages.success(request, _('A new revision was created: Merge between revision #%(r1)d and revision #%(r2)d') %
{'r1': revision.revision_number,
'r2': old_revision.revision_number})
if urlpath:
......
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