0003-misc-apply-pyupgrade-54260.patch
django_journal/actions.py | ||
---|---|---|
49 | 49 |
return response |
50 | 50 | |
51 | 51 | |
52 |
export_as_csv.short_description = _(u"Export CSV file") |
|
52 |
export_as_csv.short_description = _("Export CSV file") |
django_journal/admin.py | ||
---|---|---|
17 | 17 |
self.filter_link = filter_link |
18 | 18 |
self.object_link = object_link |
19 | 19 |
self.model_admin = model_admin |
20 |
super(ModelAdminFormatter, self).__init__()
|
|
20 |
super().__init__() |
|
21 | 21 | |
22 | 22 |
def build_object_link(self, value): |
23 | 23 |
content_type = ContentType.objects.get_for_model(value.__class__) |
24 |
url = u'{0}:{1}_{2}_change'.format(
|
|
24 |
url = '{}:{}_{}_change'.format(
|
|
25 | 25 |
self.model_admin.admin_site.name, content_type.app_label, content_type.model |
26 | 26 |
) |
27 | 27 |
try: |
28 | 28 |
url = reverse(url, args=(value.pk,)) |
29 | 29 |
except NoReverseMatch: |
30 |
return u''
|
|
31 |
return u'<a href="{0}" class="external-link"></a>'.format(escape(url))
|
|
30 |
return '' |
|
31 |
return f'<a href="{escape(url)}" class="external-link"></a>'
|
|
32 | 32 | |
33 | 33 |
def format_field(self, value, format_spec): |
34 | 34 |
if isinstance(value, models.Model): |
35 | 35 |
res = '' |
36 | 36 |
if self.filter_link: |
37 | 37 |
content_type = ContentType.objects.get_for_model(value.__class__) |
38 |
res = u'<a href="?objectdata__content_type={0}&objectdata__object_id={1}">{2}</a>'.format(
|
|
38 |
res = '<a href="?objectdata__content_type={}&objectdata__object_id={}">{}</a>'.format(
|
|
39 | 39 |
content_type.id, value.pk, escape(force_text(value)) |
40 | 40 |
) |
41 | 41 |
else: |
... | ... | |
43 | 43 |
if self.object_link: |
44 | 44 |
res += self.build_object_link(value) |
45 | 45 |
return res |
46 |
return escape(super(ModelAdminFormatter, self).format_field(value, format_spec))
|
|
46 |
return escape(super().format_field(value, format_spec)) |
|
47 | 47 | |
48 | 48 | |
49 | 49 |
class ObjectDataInlineAdmin(admin.TabularInline): |
... | ... | |
82 | 82 | |
83 | 83 |
def queryset(self, request): |
84 | 84 |
'''Get as much data as possible using the fewest requests possible.''' |
85 |
qs = super(JournalAdmin, self).queryset(request)
|
|
85 |
qs = super().queryset(request) |
|
86 | 86 |
qs = qs.select_related('tag', 'template').prefetch_related( |
87 | 87 |
'objectdata_set__content_type', |
88 | 88 |
'stringdata_set', |
... | ... | |
96 | 96 |
return True |
97 | 97 | |
98 | 98 |
def _tag(self, entry): |
99 |
name = entry.tag.name.replace(u'-', u'\u2011')
|
|
99 |
name = entry.tag.name.replace('-', '\u2011')
|
|
100 | 100 |
res = format_html('<a href="?tag__id__exact={0}">{1}</a>', escape(entry.tag.id), escape(name)) |
101 | 101 |
return res |
102 | 102 | |
... | ... | |
128 | 128 |
if objectdata.content_object is not None: |
129 | 129 |
caption = force_text(objectdata.content_object) |
130 | 130 |
else: |
131 |
caption = _(u'<deleted {content_type} {object_id}>').format(
|
|
131 |
caption = _('<deleted {content_type} {object_id}>').format( |
|
132 | 132 |
content_type=objectdata.content_type, object_id=objectdata.object_id |
133 | 133 |
) |
134 |
return u'<a href="?objectdata__content_type={0}&objectdata__object_id={1}">{2}</a>'.format(
|
|
134 |
return '<a href="?objectdata__content_type={}&objectdata__object_id={}">{}</a>'.format(
|
|
135 | 135 |
objectdata.content_type_id, objectdata.object_id, escape(caption) |
136 | 136 |
) |
137 | 137 | |
138 | 138 |
def object_link(self, obj_data): |
139 | 139 |
if obj_data.content_object is None: |
140 |
return u''
|
|
141 |
url = u'{0}:{1}_{2}_change'.format(
|
|
140 |
return '' |
|
141 |
url = '{}:{}_{}_change'.format(
|
|
142 | 142 |
self.admin_site.name, obj_data.content_type.app_label, obj_data.content_type.model |
143 | 143 |
) |
144 | 144 |
try: |
145 | 145 |
url = reverse(url, args=(obj_data.object_id,)) |
146 | 146 |
except NoReverseMatch: |
147 | 147 |
return '' |
148 |
return u'<a href="{0}" class="external-link"></a>'.format(url)
|
|
148 |
return f'<a href="{url}" class="external-link"></a>'
|
|
149 | 149 | |
150 | 150 |
def message_for_change(self, entry): |
151 | 151 |
ctx = entry.message_context() |
django_journal/decorator.py | ||
---|---|---|
6 | 6 |
atomic = transaction.atomic |
7 | 7 |
else: |
8 | 8 | |
9 |
class Transaction(object):
|
|
9 |
class Transaction: |
|
10 | 10 |
sid = None |
11 | 11 | |
12 | 12 |
def __init__(self, using=None): |
django_journal/managers.py | ||
---|---|---|
65 | 65 |
class JournalManager(Manager.from_queryset(JournalQuerySet)): |
66 | 66 |
def get_query_set(self): |
67 | 67 |
return ( |
68 |
super(JournalManager, self)
|
|
68 |
super() |
|
69 | 69 |
.get_query_set() |
70 | 70 |
.prefetch_related( |
71 | 71 |
'objectdata_set__content_type', |
django_journal/migrations/0001_initial.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
from __future__ import unicode_literals |
|
3 | ||
4 | 1 |
import django.db.models.deletion |
5 | 2 |
from django.db import migrations, models |
6 | 3 | |
... | ... | |
127 | 124 |
), |
128 | 125 |
migrations.AlterUniqueTogether( |
129 | 126 |
name='stringdata', |
130 |
unique_together=set([('journal', 'tag')]),
|
|
127 |
unique_together={('journal', 'tag')},
|
|
131 | 128 |
), |
132 | 129 |
migrations.AlterUniqueTogether( |
133 | 130 |
name='objectdata', |
134 |
unique_together=set([('journal', 'tag')]),
|
|
131 |
unique_together={('journal', 'tag')},
|
|
135 | 132 |
), |
136 | 133 |
] |
django_journal/models.py | ||
---|---|---|
82 | 82 |
if data.content_object is not None: |
83 | 83 |
ctx[data.tag.name] = data.content_object |
84 | 84 |
else: |
85 |
ctx[data.tag.name] = u'<deleted {content_type} {object_id}>'.format(
|
|
85 |
ctx[data.tag.name] = '<deleted {content_type} {object_id}>'.format( |
|
86 | 86 |
content_type=data.content_type, object_id=data.object_id |
87 | 87 |
) |
88 | 88 |
for data in self.stringdata_set.all(): |
... | ... | |
103 | 103 |
return self.template.content.format(**ctx) |
104 | 104 | |
105 | 105 |
def __repr__(self): |
106 |
return '<Journal pk:{0} tag:{1} message:{2}>'.format(
|
|
106 |
return '<Journal pk:{} tag:{} message:{}>'.format(
|
|
107 | 107 |
self.pk, unicode(self.tag).encode('utf-8'), unicode(self.message).encode('utf-8') |
108 | 108 |
) |
109 | 109 | |
... | ... | |
153 | 153 |
verbose_name = _('linked object') |
154 | 154 | |
155 | 155 |
def __str__(self): |
156 |
return u'{0}:{1}:{2}'.format(self.journal.id, self.tag, self.content_object) |
|
156 |
return f'{self.journal.id}:{self.tag}:{self.content_object}' |
setup.py | ||
---|---|---|
86 | 86 |
tag exists, take 0.0- and add the length of the commit log. |
87 | 87 |
""" |
88 | 88 |
if os.path.exists('VERSION'): |
89 |
with open('VERSION', 'r') as v:
|
|
89 |
with open('VERSION') as v: |
|
90 | 90 |
return v.read() |
91 | 91 |
if os.path.exists('.git'): |
92 | 92 |
p = subprocess.Popen( |
tests/test_main.py | ||
---|---|---|
32 | 32 | |
33 | 33 |
def test_login(self): |
34 | 34 |
for i, event in zip(range(20), Journal.objects.for_tag('login').order_by('id')): |
35 |
self.assertEqual(force_text(event), 'user{0} logged in'.format(i))
|
|
35 |
self.assertEqual(force_text(event), f'user{i} logged in')
|
|
36 | 36 | |
37 | 37 |
def test_groups(self): |
38 | 38 |
for i, event in zip(range(40), Journal.objects.for_tag('group-changed').order_by('id')): |
... | ... | |
42 | 42 | |
43 | 43 |
def test_logout(self): |
44 | 44 |
for i, event in zip(range(20), Journal.objects.for_tag('logout').order_by('id')): |
45 |
self.assertEqual(force_text(event), 'user{0} logged out'.format(i))
|
|
45 |
self.assertEqual(force_text(event), f'user{i} logged out')
|
|
46 | 46 | |
47 | 47 |
def test_export_as_csv(self): |
48 | 48 |
qs = Journal.objects.all() |
... | ... | |
64 | 64 |
}, |
65 | 65 |
) |
66 | 66 |
l = list(export_as_csv_generator(qs[:5])) |
67 |
self.assertEquals(set(l[0]), set(['time', 'tag', 'message', 'user', 'user__id']))
|
|
67 |
self.assertEquals(set(l[0]), {'time', 'tag', 'message', 'user', 'user__id'})
|
|
68 | 68 |
for user in self.users: |
69 | 69 |
user.delete() |
70 | 70 |
qs = Journal.objects.all() |
... | ... | |
75 | 75 |
def test_error_record(db): |
76 | 76 |
error_record('error', 'error message') |
77 | 77 |
journal = Journal.objects.first() |
78 |
assert journal.tag.name == u'error'
|
|
79 |
assert journal.message == u'error message'
|
|
78 |
assert journal.tag.name == 'error' |
|
79 |
assert journal.message == 'error message' |
|
80 | 80 | |
81 | 81 |
# specifying None as database use the defaut one |
82 | 82 |
error_record('error', 'error message', using=None) |
83 |
- |