From bbb5bd736196803ff53ae0d665e9372352754bb0 Mon Sep 17 00:00:00 2001
From: Paul Marillonnet <pmarillonnet@entrouvert.com>
Date: Thu, 15 Jul 2021 12:18:52 +0200
Subject: [PATCH 3/4] misc: apply pyupgrade (#54260)

---
 django_journal/actions.py                 |  2 +-
 django_journal/admin.py                   | 26 +++++++++++------------
 django_journal/decorator.py               |  2 +-
 django_journal/managers.py                |  2 +-
 django_journal/migrations/0001_initial.py |  7 ++----
 django_journal/models.py                  |  6 +++---
 setup.py                                  |  2 +-
 tests/test_main.py                        | 10 ++++-----
 8 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/django_journal/actions.py b/django_journal/actions.py
index 70002d6..35a88ed 100644
--- a/django_journal/actions.py
+++ b/django_journal/actions.py
@@ -49,4 +49,4 @@ def export_as_csv(modeladmin, request, queryset):
     return response
 
 
-export_as_csv.short_description = _(u"Export CSV file")
+export_as_csv.short_description = _("Export CSV file")
diff --git a/django_journal/admin.py b/django_journal/admin.py
index 1873d4a..2c83ed7 100644
--- a/django_journal/admin.py
+++ b/django_journal/admin.py
@@ -17,25 +17,25 @@ class ModelAdminFormatter(Formatter):
         self.filter_link = filter_link
         self.object_link = object_link
         self.model_admin = model_admin
-        super(ModelAdminFormatter, self).__init__()
+        super().__init__()
 
     def build_object_link(self, value):
         content_type = ContentType.objects.get_for_model(value.__class__)
-        url = u'{0}:{1}_{2}_change'.format(
+        url = '{}:{}_{}_change'.format(
             self.model_admin.admin_site.name, content_type.app_label, content_type.model
         )
         try:
             url = reverse(url, args=(value.pk,))
         except NoReverseMatch:
-            return u''
-        return u'<a href="{0}" class="external-link"></a>'.format(escape(url))
+            return ''
+        return f'<a href="{escape(url)}" class="external-link"></a>'
 
     def format_field(self, value, format_spec):
         if isinstance(value, models.Model):
             res = ''
             if self.filter_link:
                 content_type = ContentType.objects.get_for_model(value.__class__)
-                res = u'<a href="?objectdata__content_type={0}&objectdata__object_id={1}">{2}</a>'.format(
+                res = '<a href="?objectdata__content_type={}&objectdata__object_id={}">{}</a>'.format(
                     content_type.id, value.pk, escape(force_text(value))
                 )
             else:
@@ -43,7 +43,7 @@ class ModelAdminFormatter(Formatter):
             if self.object_link:
                 res += self.build_object_link(value)
             return res
-        return escape(super(ModelAdminFormatter, self).format_field(value, format_spec))
+        return escape(super().format_field(value, format_spec))
 
 
 class ObjectDataInlineAdmin(admin.TabularInline):
@@ -82,7 +82,7 @@ class JournalAdmin(admin.ModelAdmin):
 
     def queryset(self, request):
         '''Get as much data as possible using the fewest requests possible.'''
-        qs = super(JournalAdmin, self).queryset(request)
+        qs = super().queryset(request)
         qs = qs.select_related('tag', 'template').prefetch_related(
             'objectdata_set__content_type',
             'stringdata_set',
@@ -96,7 +96,7 @@ class JournalAdmin(admin.ModelAdmin):
         return True
 
     def _tag(self, entry):
-        name = entry.tag.name.replace(u'-', u'\u2011')
+        name = entry.tag.name.replace('-', '\u2011')
         res = format_html('<a href="?tag__id__exact={0}">{1}</a>', escape(entry.tag.id), escape(name))
         return res
 
@@ -128,24 +128,24 @@ class JournalAdmin(admin.ModelAdmin):
         if objectdata.content_object is not None:
             caption = force_text(objectdata.content_object)
         else:
-            caption = _(u'<deleted {content_type} {object_id}>').format(
+            caption = _('<deleted {content_type} {object_id}>').format(
                 content_type=objectdata.content_type, object_id=objectdata.object_id
             )
-        return u'<a href="?objectdata__content_type={0}&objectdata__object_id={1}">{2}</a>'.format(
+        return '<a href="?objectdata__content_type={}&objectdata__object_id={}">{}</a>'.format(
             objectdata.content_type_id, objectdata.object_id, escape(caption)
         )
 
     def object_link(self, obj_data):
         if obj_data.content_object is None:
-            return u''
-        url = u'{0}:{1}_{2}_change'.format(
+            return ''
+        url = '{}:{}_{}_change'.format(
             self.admin_site.name, obj_data.content_type.app_label, obj_data.content_type.model
         )
         try:
             url = reverse(url, args=(obj_data.object_id,))
         except NoReverseMatch:
             return ''
-        return u'<a href="{0}" class="external-link"></a>'.format(url)
+        return f'<a href="{url}" class="external-link"></a>'
 
     def message_for_change(self, entry):
         ctx = entry.message_context()
diff --git a/django_journal/decorator.py b/django_journal/decorator.py
index 6529cfe..cd9237a 100644
--- a/django_journal/decorator.py
+++ b/django_journal/decorator.py
@@ -6,7 +6,7 @@ if hasattr(transaction, 'atomic'):
     atomic = transaction.atomic
 else:
 
-    class Transaction(object):
+    class Transaction:
         sid = None
 
         def __init__(self, using=None):
diff --git a/django_journal/managers.py b/django_journal/managers.py
index 5b2497a..86f2052 100644
--- a/django_journal/managers.py
+++ b/django_journal/managers.py
@@ -65,7 +65,7 @@ class JournalQuerySet(QuerySet):
 class JournalManager(Manager.from_queryset(JournalQuerySet)):
     def get_query_set(self):
         return (
-            super(JournalManager, self)
+            super()
             .get_query_set()
             .prefetch_related(
                 'objectdata_set__content_type',
diff --git a/django_journal/migrations/0001_initial.py b/django_journal/migrations/0001_initial.py
index 3f45137..9a2f303 100644
--- a/django_journal/migrations/0001_initial.py
+++ b/django_journal/migrations/0001_initial.py
@@ -1,6 +1,3 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
 import django.db.models.deletion
 from django.db import migrations, models
 
@@ -127,10 +124,10 @@ class Migration(migrations.Migration):
         ),
         migrations.AlterUniqueTogether(
             name='stringdata',
-            unique_together=set([('journal', 'tag')]),
+            unique_together={('journal', 'tag')},
         ),
         migrations.AlterUniqueTogether(
             name='objectdata',
-            unique_together=set([('journal', 'tag')]),
+            unique_together={('journal', 'tag')},
         ),
     ]
diff --git a/django_journal/models.py b/django_journal/models.py
index 2cf1682..6bbe532 100644
--- a/django_journal/models.py
+++ b/django_journal/models.py
@@ -82,7 +82,7 @@ class Journal(models.Model):
             if data.content_object is not None:
                 ctx[data.tag.name] = data.content_object
             else:
-                ctx[data.tag.name] = u'<deleted {content_type} {object_id}>'.format(
+                ctx[data.tag.name] = '<deleted {content_type} {object_id}>'.format(
                     content_type=data.content_type, object_id=data.object_id
                 )
         for data in self.stringdata_set.all():
@@ -103,7 +103,7 @@ class Journal(models.Model):
         return self.template.content.format(**ctx)
 
     def __repr__(self):
-        return '<Journal pk:{0} tag:{1} message:{2}>'.format(
+        return '<Journal pk:{} tag:{} message:{}>'.format(
             self.pk, unicode(self.tag).encode('utf-8'), unicode(self.message).encode('utf-8')
         )
 
@@ -153,4 +153,4 @@ class ObjectData(models.Model):
         verbose_name = _('linked object')
 
     def __str__(self):
-        return u'{0}:{1}:{2}'.format(self.journal.id, self.tag, self.content_object)
+        return f'{self.journal.id}:{self.tag}:{self.content_object}'
diff --git a/setup.py b/setup.py
index 0483281..f740cb2 100755
--- a/setup.py
+++ b/setup.py
@@ -86,7 +86,7 @@ def get_version():
     tag exists, take 0.0- and add the length of the commit log.
     """
     if os.path.exists('VERSION'):
-        with open('VERSION', 'r') as v:
+        with open('VERSION') as v:
             return v.read()
     if os.path.exists('.git'):
         p = subprocess.Popen(
diff --git a/tests/test_main.py b/tests/test_main.py
index cac9458..4491db9 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -32,7 +32,7 @@ class JournalTestCase(TestCase):
 
     def test_login(self):
         for i, event in zip(range(20), Journal.objects.for_tag('login').order_by('id')):
-            self.assertEqual(force_text(event), 'user{0} logged in'.format(i))
+            self.assertEqual(force_text(event), f'user{i} logged in')
 
     def test_groups(self):
         for i, event in zip(range(40), Journal.objects.for_tag('group-changed').order_by('id')):
@@ -42,7 +42,7 @@ class JournalTestCase(TestCase):
 
     def test_logout(self):
         for i, event in zip(range(20), Journal.objects.for_tag('logout').order_by('id')):
-            self.assertEqual(force_text(event), 'user{0} logged out'.format(i))
+            self.assertEqual(force_text(event), f'user{i} logged out')
 
     def test_export_as_csv(self):
         qs = Journal.objects.all()
@@ -64,7 +64,7 @@ class JournalTestCase(TestCase):
             },
         )
         l = list(export_as_csv_generator(qs[:5]))
-        self.assertEquals(set(l[0]), set(['time', 'tag', 'message', 'user', 'user__id']))
+        self.assertEquals(set(l[0]), {'time', 'tag', 'message', 'user', 'user__id'})
         for user in self.users:
             user.delete()
         qs = Journal.objects.all()
@@ -75,8 +75,8 @@ class JournalTestCase(TestCase):
 def test_error_record(db):
     error_record('error', 'error message')
     journal = Journal.objects.first()
-    assert journal.tag.name == u'error'
-    assert journal.message == u'error message'
+    assert journal.tag.name == 'error'
+    assert journal.message == 'error message'
 
     # specifying None as database use the defaut one
     error_record('error', 'error message', using=None)
-- 
2.32.0

