Commit 5e8303f61e535d52bb2112afbfda0db0fd803d17

Authored by Mariusz Felisiak
Committed by Claude Paroz
1 parent 46563224

Prevented django.utils.translation/encoding.* deprecation warnings.

@@ -7,7 +7,7 @@ from django.contrib.sites.models import Site @@ -7,7 +7,7 @@ from django.contrib.sites.models import Site
7 from django.db import models 7 from django.db import models
8 from django.urls import reverse 8 from django.urls import reverse
9 from django.utils import timezone 9 from django.utils import timezone
10 -from django.utils.translation import ugettext_lazy as _ 10 +from django.utils.translation import gettext_lazy as _
11 from six import python_2_unicode_compatible 11 from six import python_2_unicode_compatible
12 12
13 from .managers import CommentManager 13 from .managers import CommentManager
@@ -2,7 +2,7 @@ from __future__ import unicode_literals @@ -2,7 +2,7 @@ from __future__ import unicode_literals
2 2
3 from django.contrib import admin 3 from django.contrib import admin
4 from django.contrib.auth import get_user_model 4 from django.contrib.auth import get_user_model
5 -from django.utils.translation import ugettext_lazy as _, ungettext 5 +from django.utils.translation import gettext_lazy as _, ngettext
6 6
7 from django_comments import get_model 7 from django_comments import get_model
8 from django_comments.views.moderation import perform_flag, perform_approve, perform_delete 8 from django_comments.views.moderation import perform_flag, perform_approve, perform_delete
@@ -56,19 +56,19 @@ class CommentsAdmin(admin.ModelAdmin): @@ -56,19 +56,19 @@ class CommentsAdmin(admin.ModelAdmin):
56 56
57 def flag_comments(self, request, queryset): 57 def flag_comments(self, request, queryset):
58 self._bulk_flag(request, queryset, perform_flag, 58 self._bulk_flag(request, queryset, perform_flag,
59 - lambda n: ungettext('flagged', 'flagged', n)) 59 + lambda n: ngettext('flagged', 'flagged', n))
60 60
61 flag_comments.short_description = _("Flag selected comments") 61 flag_comments.short_description = _("Flag selected comments")
62 62
63 def approve_comments(self, request, queryset): 63 def approve_comments(self, request, queryset):
64 self._bulk_flag(request, queryset, perform_approve, 64 self._bulk_flag(request, queryset, perform_approve,
65 - lambda n: ungettext('approved', 'approved', n)) 65 + lambda n: ngettext('approved', 'approved', n))
66 66
67 approve_comments.short_description = _("Approve selected comments") 67 approve_comments.short_description = _("Approve selected comments")
68 68
69 def remove_comments(self, request, queryset): 69 def remove_comments(self, request, queryset):
70 self._bulk_flag(request, queryset, perform_delete, 70 self._bulk_flag(request, queryset, perform_delete,
71 - lambda n: ungettext('removed', 'removed', n)) 71 + lambda n: ngettext('removed', 'removed', n))
72 72
73 remove_comments.short_description = _("Remove selected comments") 73 remove_comments.short_description = _("Remove selected comments")
74 74
@@ -82,7 +82,7 @@ class CommentsAdmin(admin.ModelAdmin): @@ -82,7 +82,7 @@ class CommentsAdmin(admin.ModelAdmin):
82 action(request, comment) 82 action(request, comment)
83 n_comments += 1 83 n_comments += 1
84 84
85 - msg = ungettext('%(count)s comment was successfully %(action)s.', 85 + msg = ngettext('%(count)s comment was successfully %(action)s.',
86 '%(count)s comments were successfully %(action)s.', 86 '%(count)s comments were successfully %(action)s.',
87 n_comments) 87 n_comments)
88 self.message_user(request, msg % {'count': n_comments, 'action': done_message(n_comments)}) 88 self.message_user(request, msg % {'count': n_comments, 'action': done_message(n_comments)})
1 from django.contrib.sites.shortcuts import get_current_site 1 from django.contrib.sites.shortcuts import get_current_site
2 from django.contrib.syndication.views import Feed 2 from django.contrib.syndication.views import Feed
3 -from django.utils.translation import ugettext as _ 3 +from django.utils.translation import gettext as _
4 4
5 import django_comments 5 import django_comments
6 6
@@ -5,10 +5,10 @@ from django.conf import settings @@ -5,10 +5,10 @@ from django.conf import settings
5 from django.contrib.contenttypes.models import ContentType 5 from django.contrib.contenttypes.models import ContentType
6 from django.forms.utils import ErrorDict 6 from django.forms.utils import ErrorDict
7 from django.utils.crypto import salted_hmac, constant_time_compare 7 from django.utils.crypto import salted_hmac, constant_time_compare
8 -from django.utils.encoding import force_text 8 +from django.utils.encoding import force_str
9 from django.utils.text import get_text_list 9 from django.utils.text import get_text_list
10 from django.utils import timezone 10 from django.utils import timezone
11 -from django.utils.translation import pgettext_lazy, ungettext, ugettext, ugettext_lazy as _ 11 +from django.utils.translation import pgettext_lazy, ngettext, gettext, gettext_lazy as _
12 12
13 from . import get_model 13 from . import get_model
14 14
@@ -139,7 +139,7 @@ class CommentDetailsForm(CommentSecurityForm): @@ -139,7 +139,7 @@ class CommentDetailsForm(CommentSecurityForm):
139 """ 139 """
140 return dict( 140 return dict(
141 content_type=ContentType.objects.get_for_model(self.target_object), 141 content_type=ContentType.objects.get_for_model(self.target_object),
142 - object_pk=force_text(self.target_object._get_pk_val()), 142 + object_pk=force_str(self.target_object._get_pk_val()),
143 user_name=self.cleaned_data["name"], 143 user_name=self.cleaned_data["name"],
144 user_email=self.cleaned_data["email"], 144 user_email=self.cleaned_data["email"],
145 user_url=self.cleaned_data["url"], 145 user_url=self.cleaned_data["url"],
@@ -180,12 +180,12 @@ class CommentDetailsForm(CommentSecurityForm): @@ -180,12 +180,12 @@ class CommentDetailsForm(CommentSecurityForm):
180 getattr(settings, 'PROFANITIES_LIST', False)): 180 getattr(settings, 'PROFANITIES_LIST', False)):
181 bad_words = [w for w in settings.PROFANITIES_LIST if w in comment.lower()] 181 bad_words = [w for w in settings.PROFANITIES_LIST if w in comment.lower()]
182 if bad_words: 182 if bad_words:
183 - raise forms.ValidationError(ungettext( 183 + raise forms.ValidationError(ngettext(
184 "Watch your mouth! The word %s is not allowed here.", 184 "Watch your mouth! The word %s is not allowed here.",
185 "Watch your mouth! The words %s are not allowed here.", 185 "Watch your mouth! The words %s are not allowed here.",
186 len(bad_words)) % get_text_list( 186 len(bad_words)) % get_text_list(
187 ['"%s%s%s"' % (i[0], '-' * (len(i) - 2), i[-1]) 187 ['"%s%s%s"' % (i[0], '-' * (len(i) - 2), i[-1])
188 - for i in bad_words], ugettext('and'))) 188 + for i in bad_words], gettext('and')))
189 return comment 189 return comment
190 190
191 191
1 from django.db import models 1 from django.db import models
2 from django.contrib.contenttypes.models import ContentType 2 from django.contrib.contenttypes.models import ContentType
3 -from django.utils.encoding import force_text 3 +from django.utils.encoding import force_str
4 4
5 5
6 class CommentManager(models.Manager): 6 class CommentManager(models.Manager):
@@ -18,5 +18,5 @@ class CommentManager(models.Manager): @@ -18,5 +18,5 @@ class CommentManager(models.Manager):
18 ct = ContentType.objects.get_for_model(model) 18 ct = ContentType.objects.get_for_model(model)
19 qs = self.get_queryset().filter(content_type=ct) 19 qs = self.get_queryset().filter(content_type=ct)
20 if isinstance(model, models.Model): 20 if isinstance(model, models.Model):
21 - qs = qs.filter(object_pk=force_text(model._get_pk_val())) 21 + qs = qs.filter(object_pk=force_str(model._get_pk_val()))
22 return qs 22 return qs
1 from django.conf import settings 1 from django.conf import settings
2 from django.db import models 2 from django.db import models
3 from django.utils import timezone 3 from django.utils import timezone
4 -from django.utils.translation import ugettext_lazy as _ 4 +from django.utils.translation import gettext_lazy as _
5 from six import python_2_unicode_compatible 5 from six import python_2_unicode_compatible
6 6
7 from .abstracts import ( 7 from .abstracts import (
@@ -62,7 +62,7 @@ from django.core.mail import send_mail @@ -62,7 +62,7 @@ from django.core.mail import send_mail
62 from django.db.models.base import ModelBase 62 from django.db.models.base import ModelBase
63 from django.template import loader 63 from django.template import loader
64 from django.utils import timezone 64 from django.utils import timezone
65 -from django.utils.translation import ugettext as _ 65 +from django.utils.translation import gettext as _
66 66
67 import django_comments 67 import django_comments
68 from django_comments import signals 68 from django_comments import signals
@@ -3,7 +3,7 @@ from django.template.loader import render_to_string @@ -3,7 +3,7 @@ from django.template.loader import render_to_string
3 from django.conf import settings 3 from django.conf import settings
4 from django.contrib.contenttypes.models import ContentType 4 from django.contrib.contenttypes.models import ContentType
5 from django.contrib.sites.shortcuts import get_current_site 5 from django.contrib.sites.shortcuts import get_current_site
6 -from django.utils.encoding import smart_text 6 +from django.utils.encoding import smart_str
7 7
8 import django_comments 8 import django_comments
9 9
@@ -85,7 +85,7 @@ class BaseCommentNode(template.Node): @@ -85,7 +85,7 @@ class BaseCommentNode(template.Node):
85 85
86 qs = self.comment_model.objects.filter( 86 qs = self.comment_model.objects.filter(
87 content_type=ctype, 87 content_type=ctype,
88 - object_pk=smart_text(object_pk), 88 + object_pk=smart_str(object_pk),
89 site__pk=site_id, 89 site__pk=site_id,
90 ) 90 )
91 91
Please register or login to post a comment