[damned-lies] Prevented deprecation warnings with 'u' gettext prefix



commit d7fa94923387a7bc96bb35d5b958ae5e1d7c5fca
Author: Claude Paroz <claude 2xlibre net>
Date:   Wed Dec 4 14:13:06 2019 +0100

    Prevented deprecation warnings with 'u' gettext prefix

 common/utils.py               |  2 +-
 common/views.py               |  2 +-
 languages/models.py           |  2 +-
 languages/views.py            |  2 +-
 people/forms.py               | 14 +++++++-------
 people/models.py              |  2 +-
 people/templatetags/people.py |  2 +-
 people/tests.py               |  2 +-
 people/views.py               |  6 +++---
 requirements.txt              |  2 +-
 stats/forms.py                |  2 +-
 stats/models.py               | 26 +++++++++++++-------------
 stats/views.py                |  2 +-
 teams/forms.py                |  2 +-
 teams/models.py               | 10 +++++-----
 teams/tests.py                |  4 ++--
 teams/views.py                |  2 +-
 vertimus/feeds.py             |  2 +-
 vertimus/forms.py             |  6 +++---
 vertimus/models.py            | 28 +++++++++++++++-------------
 20 files changed, 61 insertions(+), 59 deletions(-)
---
diff --git a/common/utils.py b/common/utils.py
index 638fb6dd..14612b0f 100644
--- a/common/utils.py
+++ b/common/utils.py
@@ -6,7 +6,7 @@ from subprocess import Popen, PIPE
 
 from django.conf import settings
 from django.core.mail import EmailMessage
-from django.utils.translation import ugettext as _, get_language
+from django.utils.translation import gettext as _, get_language
 
 try:
     import icu
diff --git a/common/views.py b/common/views.py
index 3bda4e1b..48ced4d9 100644
--- a/common/views.py
+++ b/common/views.py
@@ -9,7 +9,7 @@ from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirec
 from django.shortcuts import render
 from django.template.loader import get_template, TemplateDoesNotExist
 from django.urls import reverse
-from django.utils.translation import ugettext as _
+from django.utils.translation import gettext as _
 from django.views.decorators.csrf import csrf_exempt
 
 from people.models import Person, obfuscate_email
diff --git a/languages/models.py b/languages/models.py
index 1cb1ca02..69bd6a2f 100644
--- a/languages/models.py
+++ b/languages/models.py
@@ -1,7 +1,7 @@
 from django.conf import settings
 from django.db import models
 from django.db.models import Q
-from django.utils.translation import ugettext as _
+from django.utils.translation import gettext as _
 from django.urls import NoReverseMatch
 from teams.models import Team, FakeTeam
 
diff --git a/languages/views.py b/languages/views.py
index 5295950f..fbeae48f 100644
--- a/languages/views.py
+++ b/languages/views.py
@@ -5,7 +5,7 @@ import tarfile
 from django.conf import settings
 from django.http import HttpResponse, HttpResponseRedirect
 from django.shortcuts import render, get_object_or_404
-from django.utils.translation import ugettext as _
+from django.utils.translation import gettext as _
 
 from common import utils
 from languages.models import Language
diff --git a/people/forms.py b/people/forms.py
index f0bf2de1..0a8436a5 100644
--- a/people/forms.py
+++ b/people/forms.py
@@ -8,7 +8,7 @@ from django.contrib.auth.forms import AuthenticationForm
 from django.core.exceptions import ValidationError
 from django.urls import reverse
 from django.utils.encoding import force_bytes
-from django.utils.translation import ugettext_lazy, ugettext as _
+from django.utils.translation import gettext_lazy, gettext as _
 
 from common.utils import send_mail
 from teams.models import Team
@@ -19,15 +19,15 @@ class RegistrationForm(forms.Form):
     """ Form for user registration """
     username = forms.RegexField(widget=forms.TextInput(attrs={'class': 'form-control'}),
                                max_length=30, regex=r'^\w+$',
-                               label=ugettext_lazy('Choose a username:'),
-                               help_text=ugettext_lazy('May contain only letters, numbers, underscores or 
hyphens'))
+                               label=gettext_lazy('Choose a username:'),
+                               help_text=gettext_lazy('May contain only letters, numbers, underscores or 
hyphens'))
     email = forms.EmailField(widget=forms.TextInput(attrs={'class': 'form-control'}),
-                               label=ugettext_lazy('Email:'))
+                               label=gettext_lazy('Email:'))
     password1 = forms.CharField(widget=forms.PasswordInput(attrs={'class': 
'form-control'},render_value=False),
-                                label=ugettext_lazy('Password:'), required=False, min_length=7,
-                                help_text=ugettext_lazy('At least 7 characters'))
+                                label=gettext_lazy('Password:'), required=False, min_length=7,
+                                help_text=gettext_lazy('At least 7 characters'))
     password2 = forms.CharField(widget=forms.PasswordInput(attrs={'class': 
'form-control'},render_value=False),
-                                label=ugettext_lazy('Confirm password:'), required=False)
+                                label=gettext_lazy('Confirm password:'), required=False)
 
     def clean_username(self):
         """  Validate the username (correctness and uniqueness)"""
diff --git a/people/models.py b/people/models.py
index 821e7966..73e5fa19 100644
--- a/people/models.py
+++ b/people/models.py
@@ -7,7 +7,7 @@ from django.db import models
 from django.urls import reverse
 from django.utils.html import escape
 from django.utils.safestring import mark_safe
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import gettext_lazy as _
 
 AVATAR_SERVICES = {
     'gravatar.com': 'https://secure.gravatar.com/avatar/{hash}.jpg?{qs}',
diff --git a/people/templatetags/people.py b/people/templatetags/people.py
index dff9365f..d355f150 100644
--- a/people/templatetags/people.py
+++ b/people/templatetags/people.py
@@ -4,7 +4,7 @@ from django import template
 from django.conf import settings
 from django.utils.html import format_html, format_html_join
 from django.utils.http import urlencode
-from django.utils.translation import ugettext as _
+from django.utils.translation import gettext as _
 
 from people.models import AVATAR_SERVICES
 
diff --git a/people/tests.py b/people/tests.py
index aec93787..7d81cd7c 100644
--- a/people/tests.py
+++ b/people/tests.py
@@ -7,7 +7,7 @@ from django.core.exceptions import ValidationError
 from django.test import TestCase
 from django.urls import reverse
 from django.utils.safestring import SafeData
-from django.utils.translation import ugettext as _
+from django.utils.translation import gettext as _
 
 from common.utils import pyicu_present
 from people.models import Person, obfuscate_email
diff --git a/people/views.py b/people/views.py
index 780919ab..92a2776e 100644
--- a/people/views.py
+++ b/people/views.py
@@ -9,7 +9,7 @@ from django.db import IntegrityError
 from django.http import HttpResponseRedirect
 from django.shortcuts import render, get_object_or_404
 from django.urls import reverse
-from django.utils.translation import ugettext_lazy, ugettext as _
+from django.utils.translation import gettext_lazy, gettext as _
 from django.views.decorators.http import require_POST
 from django.views.generic import ListView, DetailView, UpdateView
 
@@ -80,8 +80,8 @@ def person_team_join(request):
                 new_role.save()
                 messages.success(request, _("You have successfully joined the team “%s”.") % 
team.get_description())
                 team.send_mail_to_coordinator(
-                    subject=ugettext_lazy("A new person joined your team"),
-                    message=ugettext_lazy("%(name)s has just joined your translation team on %(site)s"),
+                    subject=gettext_lazy("A new person joined your team"),
+                    message=gettext_lazy("%(name)s has just joined your translation team on %(site)s"),
                     messagekw={'name': person.name, 'site': settings.SITE_DOMAIN}
                 )
             except IntegrityError:
diff --git a/requirements.txt b/requirements.txt
index a3a56711..78d13fbb 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-django>=2.0
+django>=2.2
 pillow
 mysqlclient
 social-auth-app-django==3.1.0
diff --git a/stats/forms.py b/stats/forms.py
index f2a4932f..23788e01 100644
--- a/stats/forms.py
+++ b/stats/forms.py
@@ -1,6 +1,6 @@
 from django import forms
 from django.core.exceptions import ValidationError
-from django.utils.translation import ugettext as _
+from django.utils.translation import gettext as _
 
 from stats.models import Branch, Category, CategoryName, Release
 
diff --git a/stats/models.py b/stats/models.py
index 9496dd5a..ffc81de8 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -18,7 +18,7 @@ from django.core.validators import RegexValidator
 from django.urls import reverse
 from django.utils.encoding import force_text
 from django.utils.functional import cached_property
-from django.utils.translation import ungettext, ugettext as _, ugettext_noop
+from django.utils.translation import ngettext, gettext as _, gettext_noop
 from django.utils import dateformat
 from django.db import models
 
@@ -463,9 +463,9 @@ class Branch(models.Model):
                     if previous_pot.exists():
                         # Use old POT file
                         potfile = previous_pot
-                        pot_stat.set_error('error', ugettext_noop("Can’t generate POT file, using old one."))
+                        pot_stat.set_error('error', gettext_noop("Can’t generate POT file, using old one."))
                     else:
-                        pot_stat.set_error('error', ugettext_noop("Can’t generate POT file, statistics 
aborted."))
+                        pot_stat.set_error('error', gettext_noop("Can’t generate POT file, statistics 
aborted."))
                         continue
 
                 # 5. Check if pot changed
@@ -486,7 +486,7 @@ class Branch(models.Model):
                     try:
                         shutil.copyfile(str(potfile), str(previous_pot))
                     except Exception:
-                        pot_stat.set_error('error', ugettext_noop("Can’t copy new POT file to public 
location."))
+                        pot_stat.set_error('error', gettext_noop("Can’t copy new POT file to public 
location."))
 
                 # Send pot_has_changed signal
                 if previous_pot.exists() and changed_status != utils.NOT_CHANGED:
@@ -740,7 +740,7 @@ class Domain(models.Model):
             try:
                 handle = request.urlopen(req)
             except URLError:
-                return "", (("error", ugettext_noop("Error retrieving pot file from URL.")),)
+                return "", (("error", gettext_noop("Error retrieving pot file from URL.")),)
             with potfile.open('wb') as f:
                 f.write(handle.read())
 
@@ -769,7 +769,7 @@ class Domain(models.Model):
                     p for p in vcs_path.parent.iterdir() if p.is_file() and p.name.endswith('.srt')
                 ]
                 if not srt_files:
-                    return "", (("error", ugettext_noop("No subtitle files found.")),)
+                    return "", (("error", gettext_noop("No subtitle files found.")),)
             with srt_files[0].open(mode='r') as po_fh, potfile.open(mode='wb') as pot_fh:
                 sub2po.convertsub(po_fh, pot_fh)
 
@@ -778,7 +778,7 @@ class Domain(models.Model):
             if status != utils.STATUS_OK:
                 return "", (
                     ("error",
-                     ugettext_noop("Error regenerating POT file for 
%(file)s:\n<pre>%(cmd)s\n%(output)s</pre>") % {
+                     gettext_noop("Error regenerating POT file for 
%(file)s:\n<pre>%(cmd)s\n%(output)s</pre>") % {
                         'file': self.potbase(),
                         'cmd': ' '.join(pot_command) if isinstance(pot_command, list) else pot_command,
                         'output': force_text(errs)
@@ -802,7 +802,7 @@ class Domain(models.Model):
         if errors:
             return "", errors
         elif not potfile.exists():
-            return "", (("error", ugettext_noop("Unable to generate POT file")),)
+            return "", (("error", gettext_noop("Unable to generate POT file")),)
         else:
             return potfile, ()
 
@@ -889,7 +889,7 @@ class Domain(models.Model):
                 linguas_file = utils.MakefileWrapper(branch, base_path / file_path)
                 langs = linguas_file.read_variable(variable)
                 return {'langs': langs.split() if langs is not None else None,
-                        'error': ugettext_noop("Entry for this language is not present in %(var)s variable 
in %(file)s file." % {
+                        'error': gettext_noop("Entry for this language is not present in %(var)s variable in 
%(file)s file." % {
                             'var': variable, 'file': file_path})}
         # Standard linguas location
         if self.dtype == 'ui':
@@ -1422,14 +1422,14 @@ class Statistics(models.Model):
         pot_words_size = self.full_po.pot_size(words=True)
         fig_count = self.full_po.fig_count()
         """ Return stat table header: 'POT file (n messages) - updated on ??-??-???? tz' """
-        msg_text = ungettext("%(count)s message", "%(count)s messages", pot_size) % {'count': pot_size}
+        msg_text = ngettext("%(count)s message", "%(count)s messages", pot_size) % {'count': pot_size}
         upd_text = _("updated on %(date)s") % {
                         # Date format syntax is similar to PHP http://www.php.net/date
                         'date': dateformat.format(self.full_po.updated, _("Y-m-d g:i a O"))
                         }
-        words_text = ungettext("%(count)s word", "%(count)s words", pot_words_size) % {'count': 
pot_words_size}
+        words_text = ngettext("%(count)s word", "%(count)s words", pot_words_size) % {'count': 
pot_words_size}
         if fig_count:
-            fig_text = ungettext("%(count)s figure", "%(count)s figures", fig_count) % {'count': fig_count}
+            fig_text = ngettext("%(count)s figure", "%(count)s figures", fig_count) % {'count': fig_count}
             text = _("POT file (%(messages)s — %(words)s, %(figures)s) — %(updated)s") % \
                               {'messages': msg_text, 'figures': fig_text, 'updated': upd_text, 'words': 
words_text }
         else:
@@ -1521,7 +1521,7 @@ class Statistics(models.Model):
             if abs_po_path.exists():
                 git_stats = utils.po_file_stats(abs_po_path)
                 if stats['translated'] > git_stats['translated']:
-                    self.set_error('warn', ugettext_noop(
+                    self.set_error('warn', gettext_noop(
                         "The currently committed file has less translated strings. "
                         "You should probably commit this file."
                     ))
diff --git a/stats/views.py b/stats/views.py
index 0084e512..67173f86 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -8,7 +8,7 @@ from django.core import serializers
 from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect, Http404
 from django.shortcuts import render, get_object_or_404
 from django.urls import reverse
-from django.utils.translation import ugettext as _
+from django.utils.translation import gettext as _
 
 from common.utils import MIME_TYPES, get_user_locale, run_shell_command
 from stats.models import Statistics, FakeLangStatistics, Module, ModuleLock, Branch, Category, Release
diff --git a/teams/forms.py b/teams/forms.py
index 01774c1d..9b7aaf02 100644
--- a/teams/forms.py
+++ b/teams/forms.py
@@ -1,6 +1,6 @@
 from django import forms
 from django.conf import settings
-from django.utils.translation import ugettext as _
+from django.utils.translation import gettext as _
 
 from common.utils import is_site_admin, send_mail
 from teams.models import Team, Role, ROLE_CHOICES
diff --git a/teams/models.py b/teams/models.py
index 40bf8860..b16e6e63 100644
--- a/teams/models.py
+++ b/teams/models.py
@@ -4,7 +4,7 @@ from django.conf import settings
 from django.db import models
 from django.urls import reverse
 from django.utils import translation
-from django.utils.translation import ugettext_lazy, ugettext as _
+from django.utils.translation import gettext_lazy, gettext as _
 
 from common.utils import send_mail
 from people.models import Person
@@ -214,10 +214,10 @@ class FakeTeam:
 
 
 ROLE_CHOICES = (
-    ('translator', ugettext_lazy('Translator')),
-    ('reviewer', ugettext_lazy('Reviewer')),
-    ('committer', ugettext_lazy('Committer')),
-    ('coordinator', ugettext_lazy('Coordinator')),
+    ('translator', gettext_lazy('Translator')),
+    ('reviewer', gettext_lazy('Reviewer')),
+    ('committer', gettext_lazy('Committer')),
+    ('coordinator', gettext_lazy('Coordinator')),
 )
 
 class Role(models.Model):
diff --git a/teams/tests.py b/teams/tests.py
index 470eedd4..2b7e80b3 100644
--- a/teams/tests.py
+++ b/teams/tests.py
@@ -4,7 +4,7 @@ from django.conf import settings
 from django.core import mail
 from django.test import TestCase
 from django.urls import reverse
-from django.utils.translation import ugettext_lazy
+from django.utils.translation import gettext_lazy
 
 from people.models import Person
 from teams.models import Team, Role
@@ -208,7 +208,7 @@ class TeamTests(TeamsAndRolesMixin, TestCase):
         self.assertEqual(mail.outbox[0].subject, "%sfoo" % settings.EMAIL_SUBJECT_PREFIX)
         self.assertEqual(mail.outbox[0].extra_headers, {settings.EMAIL_HEADER_NAME: 'coordinator-mail'})
         # the message is sent in the language of the team
-        self.t.send_mail_to_coordinator(subject=ugettext_lazy("About Damned Lies"), message="...")
+        self.t.send_mail_to_coordinator(subject=gettext_lazy("About Damned Lies"), message="...")
         self.assertEqual(len(mail.outbox), 2)
         self.assertEqual(
             mail.outbox[1].subject,
diff --git a/teams/views.py b/teams/views.py
index 19dc4d35..1859fef7 100644
--- a/teams/views.py
+++ b/teams/views.py
@@ -1,7 +1,7 @@
 from django.http import HttpResponseRedirect, HttpResponseForbidden
 from django.shortcuts import render, get_object_or_404
 from django.urls import reverse
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import gettext_lazy as _
 
 from common import utils
 from teams.models import Team, FakeTeam, Role
diff --git a/vertimus/feeds.py b/vertimus/feeds.py
index c91eac97..ba848fa2 100644
--- a/vertimus/feeds.py
+++ b/vertimus/feeds.py
@@ -1,7 +1,7 @@
 from django.conf import settings
 from django.contrib.syndication.views import Feed, FeedDoesNotExist
 from django.urls import reverse
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import gettext_lazy as _
 
 from languages.models import Language
 from teams.models import Team
diff --git a/vertimus/forms.py b/vertimus/forms.py
index f2f35be2..f989c052 100644
--- a/vertimus/forms.py
+++ b/vertimus/forms.py
@@ -3,7 +3,7 @@ import os
 from django import forms
 from django.core.exceptions import ValidationError
 from django.urls import reverse
-from django.utils.translation import ugettext, ugettext_lazy as _
+from django.utils.translation import gettext, gettext_lazy as _
 
 from vertimus.models import Action, ActionCI, ActionSeparator
 from stats.models import Person
@@ -31,9 +31,9 @@ class AuthorChoiceField(forms.ModelChoiceField):
 
     def label_from_instance(self, obj):
         if str(obj) == obj.username:
-            return DisabledLabel(ugettext("%(name)s (full name missing)") % {'name': obj.username})
+            return DisabledLabel(gettext("%(name)s (full name missing)") % {'name': obj.username})
         elif not obj.email:
-            return DisabledLabel(ugettext("%(name)s (email missing)") % {'name': str(obj)})
+            return DisabledLabel(gettext("%(name)s (email missing)") % {'name': str(obj)})
         return str(obj)
 
 
diff --git a/vertimus/models.py b/vertimus/models.py
index ff140a97..fb12143f 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -9,7 +9,7 @@ from django.db.models import Max, Q
 from django.db.models.signals import post_save, pre_delete
 from django.dispatch import receiver
 from django.urls import reverse
-from django.utils.translation import override, ugettext, ugettext_noop, ugettext_lazy as _
+from django.utils.translation import override, gettext, gettext_noop, gettext_lazy as _
 
 from common.utils import run_shell_command, send_mail
 from stats.models import Branch, Domain, Statistics, PoFile, UnableToCommit
@@ -418,7 +418,7 @@ class ActionAbstract(models.Model):
         """
         history = []
         if state or sequence:
-            file_history = [{'action_id': 0, 'title': ugettext("File in repository")}]
+            file_history = [{'action_id': 0, 'title': gettext("File in repository")}]
             if not sequence:
                 query = cls.objects.filter(state_db__id=state.id)
             else:
@@ -429,7 +429,7 @@ class ActionAbstract(models.Model):
                 if action.file and action.file.path.endswith('.po'):
                     file_history.insert(0, {
                         'action_id': action.id,
-                        'title': ugettext("Uploaded file by %(name)s on %(date)s") % {
+                        'title': gettext("Uploaded file by %(name)s on %(date)s") % {
                             'name': action.person.name,
                             'date': action.created},
                         })
@@ -437,8 +437,9 @@ class ActionAbstract(models.Model):
 
 
 class Action(ActionAbstract):
-    default_message = ugettext_noop(
-        "The new state of %(module)s — %(branch)s — %(domain)s (%(language)s) is now “%(new_state)s”.")
+    default_message = gettext_noop(
+        "The new state of %(module)s — %(branch)s — %(domain)s (%(language)s) is now “%(new_state)s”."
+    )
 
     class Meta:
         db_table = 'action'
@@ -553,7 +554,7 @@ class Action(ActionAbstract):
                 state.language.locale)))
         subject = state.branch.module.name + ' - ' + state.branch.name
         with override(state.language.locale):
-            message = ugettext("Hello,") + "\n\n" + ugettext(self.default_message) + "\n%(url)s\n\n"
+            message = gettext("Hello,") + "\n\n" + gettext(self.default_message) + "\n%(url)s\n\n"
             message = message % {
                 'module': state.branch.module.name,
                 'branch': state.branch.name,
@@ -562,9 +563,9 @@ class Action(ActionAbstract):
                 'new_state': state.description,
                 'url': url
             }
-            message += self.comment or ugettext("Without comment")
+            message += self.comment or gettext("Without comment")
             message += "\n\n" + self.person.name
-            message += "\n--\n" + ugettext("This is an automated message sent from %s.") % 
settings.SITE_DOMAIN
+            message += "\n--\n" + gettext("This is an automated message sent from %s.") % 
settings.SITE_DOMAIN
         try:
             send_mail(
                 subject, message, to=recipient_list,
@@ -600,8 +601,9 @@ class ActionArchived(ActionAbstract):
 class ActionWC(Action):
     name = 'WC'
     comment_is_required = True
-    default_message = ugettext_noop(
-        "A new comment has been posted on %(module)s — %(branch)s — %(domain)s (%(language)s).")
+    default_message = gettext_noop(
+        "A new comment has been posted on %(module)s — %(branch)s — %(domain)s (%(language)s)."
+    )
 
     class Meta:
         proxy = True
@@ -679,14 +681,14 @@ class ActionCI(Action):
             # Commit failed, state unchanged
             raise Exception(_("The commit failed. The error was: “%s”") % sys.exc_info()[1])
 
-        msg = ugettext("The file has been successfully committed to the repository.")
+        msg = gettext("The file has been successfully committed to the repository.")
         if form_data.get('sync_master', False) and not state.branch.is_head():
             # Cherry-pick the commit on the master branch
             success = state.branch.module.get_head_branch().cherrypick_commit(commit_hash, state.domain)
             if success:
-                msg += ugettext(" Additionally, the synchronization with the master branch succeeded.")
+                msg += uettext(" Additionally, the synchronization with the master branch succeeded.")
             else:
-                msg += ugettext(" However, the synchronization with the master branch failed.")
+                msg += gettext(" However, the synchronization with the master branch failed.")
 
         super().apply_on(state, form_data)  # Mail sent in super
         return msg


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]