Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a possibility to send msgs to users who's nicks have spaces. Also fixed .mo file for RU locale #139

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion django_messages/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class DjangoMessagesConfig(AppConfig):
name = 'django_messages'
default_auto_field = 'django.db.models.AutoField'
verbose_name = _('Messages')
2 changes: 1 addition & 1 deletion django_messages/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django import forms
from django.forms import widgets
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from django_messages.utils import get_user_model, get_username_field

Expand Down
2 changes: 1 addition & 1 deletion django_messages/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.utils import timezone

if "pinax.notifications" in settings.INSTALLED_APPS and getattr(settings, 'DJANGO_MESSAGES_NOTIFY', True):
Expand Down
Binary file modified django_messages/locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion django_messages/management.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db.models import signals
from django.conf import settings
from django.utils.translation import ugettext_noop as _
from django.utils.translation import gettext_noop as _

if "pinax.notifications" in settings.INSTALLED_APPS and getattr(settings, 'DJANGO_MESSAGES_NOTIFY', True):
from pinax.notifications import models as notification
Expand Down
4 changes: 1 addition & 3 deletions django_messages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
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 _
from django.utils.translation import gettext_lazy as _

AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')

Expand Down Expand Up @@ -48,7 +47,6 @@ def trash_for(self, user):
)


@python_2_unicode_compatible
class Message(models.Model):
"""
A private message from user to user
Expand Down
22 changes: 11 additions & 11 deletions django_messages/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from django.conf.urls import url
from django.urls import path, re_path
from django.views.generic import RedirectView

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<recipient>[\w.@+-]+)/$', compose, name='messages_compose_to'),
url(r'^reply/(?P<message_id>[\d]+)/$', reply, name='messages_reply'),
url(r'^view/(?P<message_id>[\d]+)/$', view, name='messages_detail'),
url(r'^delete/(?P<message_id>[\d]+)/$', delete, name='messages_delete'),
url(r'^undelete/(?P<message_id>[\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'),
re_path(r'^compose/(?P<recipient>[\w\s.@+-]+)/$', compose, name='messages_compose_to'),
path('reply/<int:message_id>/', reply, name='messages_reply'),
path('view/<int:message_id>/', view, name='messages_detail'),
path('delete/<int:message_id>/', delete, name='messages_delete'),
path('undelete/<int:message_id>/', undelete, name='messages_undelete'),
path('trash/', trash, name='messages_trash'),
]
6 changes: 3 additions & 3 deletions django_messages/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import django
from django.utils.text import wrap
from django.utils.translation import ugettext, ugettext_lazy as _
from django.utils.translation import gettext, gettext_lazy as _
from django.template.loader import render_to_string
from django.conf import settings

Expand All @@ -22,7 +22,7 @@ def format_quote(sender, body):
for i, line in enumerate(lines):
lines[i] = "> %s" % line
quote = '\n'.join(lines)
return ugettext(u"%(sender)s wrote:\n%(body)s") % {
return gettext(u"%(sender)s wrote:\n%(body)s") % {
'sender': sender,
'body': quote
}
Expand Down Expand Up @@ -50,7 +50,7 @@ def format_subject(subject):
# if anything fails here, fall back to the old mechanism
pass

return ugettext(u"Re%(prefix)s: %(subject)s") % {
return gettext(u"Re%(prefix)s: %(subject)s") % {
'subject': subject,
'prefix': prefix
}
Expand Down
7 changes: 6 additions & 1 deletion django_messages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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.translation import gettext as _
from django.utils import timezone
try:
from django.core.urlresolvers import reverse
Expand All @@ -14,6 +14,10 @@
from django_messages.models import Message
from django_messages.forms import ComposeForm
from django_messages.utils import format_quote, get_user_model, get_username_field
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote

User = get_user_model()

Expand Down Expand Up @@ -95,6 +99,7 @@ def compose(request, recipient=None, form_class=ComposeForm,
else:
form = form_class(initial={"subject": request.GET.get("subject", "")})
if recipient is not None:
recipient = unquote(recipient)
recipients = [u for u in User.objects.filter(**{'%s__in' % get_username_field(): [r.strip() for r in recipient.split('+')]})]
form.fields['recipient'].initial = recipients
return render(request, template_name, {
Expand Down