diff --git a/django_messages/apps.py b/django_messages/apps.py index c7a4f26..c15eb8b 100644 --- a/django_messages/apps.py +++ b/django_messages/apps.py @@ -1,6 +1,5 @@ from django.apps import AppConfig -from django.utils.translation import ugettext_lazy as _ class DjangoMessagesConfig(AppConfig): name = 'django_messages' - verbose_name = _('Messages') + verbose_name = 'Messages' diff --git a/django_messages/fields.py b/django_messages/fields.py index d1ac75c..f31a54a 100644 --- a/django_messages/fields.py +++ b/django_messages/fields.py @@ -5,7 +5,6 @@ from django import forms from django.forms import widgets -from django.utils.translation import ugettext_lazy as _ from django_messages.utils import get_user_model, get_username_field @@ -53,7 +52,7 @@ def clean(self, value): invalid_users.append(getattr(r, get_username_field())) if unknown_names or invalid_users: - raise forms.ValidationError(_(u"The following usernames are incorrect: %(users)s") % {'users': ', '.join(list(unknown_names)+invalid_users)}) + raise forms.ValidationError("The following usernames are incorrect: %(users)s" % {'users': ', '.join(list(unknown_names)+invalid_users)}) return users diff --git a/django_messages/forms.py b/django_messages/forms.py index 79a0238..5c67356 100644 --- a/django_messages/forms.py +++ b/django_messages/forms.py @@ -1,6 +1,5 @@ from django import forms from django.conf import settings -from django.utils.translation import ugettext_lazy as _ from django.utils import timezone if "pinax.notifications" in settings.INSTALLED_APPS and getattr(settings, 'DJANGO_MESSAGES_NOTIFY', True): @@ -15,9 +14,9 @@ class ComposeForm(forms.Form): """ A simple default form for private messages. """ - recipient = CommaSeparatedUserField(label=_(u"Recipient")) - subject = forms.CharField(label=_(u"Subject"), max_length=140) - body = forms.CharField(label=_(u"Body"), + recipient = CommaSeparatedUserField(label="Recipient") + subject = forms.CharField(label="Subject", max_length=140) + body = forms.CharField(label="Body", widget=forms.Textarea(attrs={'rows': '12', 'cols':'55'})) diff --git a/django_messages/management.py b/django_messages/management.py index cac6178..5689e0b 100644 --- a/django_messages/management.py +++ b/django_messages/management.py @@ -1,17 +1,16 @@ from django.db.models import signals from django.conf import settings -from django.utils.translation import ugettext_noop as _ if "pinax.notifications" in settings.INSTALLED_APPS and getattr(settings, 'DJANGO_MESSAGES_NOTIFY', True): from pinax.notifications import models as notification def create_notice_types(app, created_models, verbosity, **kwargs): - notification.create_notice_type("messages_received", _("Message Received"), _("you have received a message"), default=2) - notification.create_notice_type("messages_sent", _("Message Sent"), _("you have sent a message"), default=1) - notification.create_notice_type("messages_replied", _("Message Replied"), _("you have replied to a message"), default=1) - notification.create_notice_type("messages_reply_received", _("Reply Received"), _("you have received a reply to a message"), default=2) - notification.create_notice_type("messages_deleted", _("Message Deleted"), _("you have deleted a message"), default=1) - notification.create_notice_type("messages_recovered", _("Message Recovered"), _("you have undeleted a message"), default=1) + notification.create_notice_type("messages_received", "Message Received", "you have received a message", default=2) + notification.create_notice_type("messages_sent", "Message Sent", "you have sent a message", default=1) + notification.create_notice_type("messages_replied", "Message Replied", "you have replied to a message", default=1) + notification.create_notice_type("messages_reply_received", "Reply Received", "you have received a reply to a message", default=2) + notification.create_notice_type("messages_deleted", "Message Deleted", "you have deleted a message", default=1) + notification.create_notice_type("messages_recovered", "Message Recovered", "you have undeleted a message", default=1) signals.post_syncdb.connect(create_notice_types, sender=notification) else: diff --git a/django_messages/models.py b/django_messages/models.py index eee3096..6d65bc5 100644 --- a/django_messages/models.py +++ b/django_messages/models.py @@ -6,8 +6,6 @@ from django.db import models from django.db.models import signals from django.utils import timezone -from django.utils.encoding import python_2_unicode_compatible -from django.utils.translation import ugettext_lazy as _ AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User') @@ -48,21 +46,20 @@ def trash_for(self, user): ) -@python_2_unicode_compatible class Message(models.Model): """ A private message from user to user """ - subject = models.CharField(_("Subject"), max_length=140) - body = models.TextField(_("Body")) - sender = models.ForeignKey(AUTH_USER_MODEL, related_name='sent_messages', verbose_name=_("Sender"), on_delete=models.PROTECT) - recipient = models.ForeignKey(AUTH_USER_MODEL, related_name='received_messages', null=True, blank=True, verbose_name=_("Recipient"), on_delete=models.SET_NULL) - parent_msg = models.ForeignKey('self', related_name='next_messages', null=True, blank=True, verbose_name=_("Parent message"), on_delete=models.SET_NULL) - sent_at = models.DateTimeField(_("sent at"), null=True, blank=True) - read_at = models.DateTimeField(_("read at"), null=True, blank=True) - replied_at = models.DateTimeField(_("replied at"), null=True, blank=True) - sender_deleted_at = models.DateTimeField(_("Sender deleted at"), null=True, blank=True) - recipient_deleted_at = models.DateTimeField(_("Recipient deleted at"), null=True, blank=True) + subject = models.CharField("Subject", max_length=140) + body = models.TextField("Body") + sender = models.ForeignKey(AUTH_USER_MODEL, related_name='sent_messages', verbose_name="Sender", on_delete=models.PROTECT) + recipient = models.ForeignKey(AUTH_USER_MODEL, related_name='received_messages', null=True, blank=True, verbose_name="Recipient", on_delete=models.SET_NULL) + parent_msg = models.ForeignKey('self', related_name='next_messages', null=True, blank=True, verbose_name="Parent message", on_delete=models.SET_NULL) + sent_at = models.DateTimeField("sent at", null=True, blank=True) + read_at = models.DateTimeField("read at", null=True, blank=True) + replied_at = models.DateTimeField("replied at", null=True, blank=True) + sender_deleted_at = models.DateTimeField("Sender deleted at", null=True, blank=True) + recipient_deleted_at = models.DateTimeField("Recipient deleted at", null=True, blank=True) objects = MessageManager() @@ -91,8 +88,8 @@ def save(self, **kwargs): class Meta: ordering = ['-sent_at'] - verbose_name = _("Message") - verbose_name_plural = _("Messages") + verbose_name = "Message" + verbose_name_plural = "Messages" def inbox_count_for(user): diff --git a/django_messages/urls.py b/django_messages/urls.py index 87346d7..82bc200 100644 --- a/django_messages/urls.py +++ b/django_messages/urls.py @@ -1,17 +1,16 @@ -from django.conf.urls import url from django.views.generic import RedirectView - +from django.urls import include, path from django_messages.views import * urlpatterns = [ - url(r'^$', RedirectView.as_view(permanent=True, url='inbox/'), name='messages_redirect'), - url(r'^inbox/$', inbox, name='messages_inbox'), - url(r'^outbox/$', outbox, name='messages_outbox'), - url(r'^compose/$', compose, name='messages_compose'), - url(r'^compose/(?P[\w.@+-]+)/$', compose, name='messages_compose_to'), - url(r'^reply/(?P[\d]+)/$', reply, name='messages_reply'), - url(r'^view/(?P[\d]+)/$', view, name='messages_detail'), - url(r'^delete/(?P[\d]+)/$', delete, name='messages_delete'), - url(r'^undelete/(?P[\d]+)/$', undelete, name='messages_undelete'), - url(r'^trash/$', trash, name='messages_trash'), + path('', RedirectView.as_view(permanent=True, url='inbox/'), name='messages_redirect'), + path('inbox/', inbox, name='messages_inbox'), + path('outbox/', outbox, name='messages_outbox'), + path('compose/', compose, name='messages_compose'), + path('compose/(?P[\w.@+-]+)/', compose, name='messages_compose_to'), + path('reply/(?P[\d]+)/', reply, name='messages_reply'), + path('view/(?P[\d]+)/', view, name='messages_detail'), + path('delete/(?P[\d]+)/', delete, name='messages_delete'), + path('undelete/(?P[\d]+)/', undelete, name='messages_undelete'), + path('trash/$', trash, name='messages_trash'), ] diff --git a/django_messages/utils.py b/django_messages/utils.py index c277424..a36daa5 100644 --- a/django_messages/utils.py +++ b/django_messages/utils.py @@ -1,7 +1,6 @@ import re import django from django.utils.text import wrap -from django.utils.translation import ugettext, ugettext_lazy as _ from django.template.loader import render_to_string from django.conf import settings @@ -56,7 +55,7 @@ def format_subject(subject): } def new_message_email(sender, instance, signal, - subject_prefix=_(u'New Message: %(subject)s'), + subject_prefix=u'New Message: %(subject)s', template_name="django_messages/new_message.html", default_protocol=None, *args, **kwargs): diff --git a/django_messages/views.py b/django_messages/views.py index 4f1d4ff..9e611e7 100644 --- a/django_messages/views.py +++ b/django_messages/views.py @@ -3,7 +3,6 @@ from django.template import RequestContext from django.contrib import messages from django.contrib.auth.decorators import login_required -from django.utils.translation import ugettext as _ from django.utils import timezone try: from django.core.urlresolvers import reverse @@ -86,7 +85,7 @@ def compose(request, recipient=None, form_class=ComposeForm, form = form_class(request.POST, recipient_filter=recipient_filter) if form.is_valid(): form.save(sender=request.user) - messages.info(request, _(u"Message successfully sent.")) + messages.info(request, "Message successfully sent.") if success_url is None: success_url = reverse('messages_inbox') if 'next' in request.GET: @@ -105,7 +104,7 @@ def compose(request, recipient=None, form_class=ComposeForm, def reply(request, message_id, form_class=ComposeForm, template_name='django_messages/compose.html', success_url=None, recipient_filter=None, quote_helper=format_quote, - subject_template=_(u"Re: %(subject)s"),): + subject_template="Re: %(subject)s",): """ Prepares the ``form_class`` form for writing a reply to a given message (specified via ``message_id``). Uses the ``format_quote`` helper from @@ -123,7 +122,7 @@ def reply(request, message_id, form_class=ComposeForm, form = form_class(request.POST, recipient_filter=recipient_filter) if form.is_valid(): form.save(sender=request.user, parent_msg=parent) - messages.info(request, _(u"Message successfully sent.")) + messages.info(request, "Message successfully sent.") if success_url is None: success_url = reverse('messages_inbox') return HttpResponseRedirect(success_url) @@ -166,7 +165,7 @@ def delete(request, message_id, success_url=None): deleted = True if deleted: message.save() - messages.info(request, _(u"Message successfully deleted.")) + messages.info(request, "Message successfully deleted.") if notification: notification.send([user], "messages_deleted", {'message': message,}) return HttpResponseRedirect(success_url) @@ -193,7 +192,7 @@ def undelete(request, message_id, success_url=None): undeleted = True if undeleted: message.save() - messages.info(request, _(u"Message successfully recovered.")) + messages.info(request, "Message successfully recovered.") if notification: notification.send([user], "messages_recovered", {'message': message,}) return HttpResponseRedirect(success_url) @@ -201,7 +200,7 @@ def undelete(request, message_id, success_url=None): @login_required def view(request, message_id, form_class=ComposeForm, quote_helper=format_quote, - subject_template=_(u"Re: %(subject)s"), + subject_template="Re: %(subject)s", template_name='django_messages/view.html'): """ Shows a single message.``message_id`` argument is required.