Remove unnecessary code in created method. (#438)

This commit is contained in:
Youngkwang Yang 2022-10-06 01:39:48 +09:00 committed by GitHub
parent 993cd847fb
commit 487b8ab5f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 12 deletions

View file

@ -2,6 +2,7 @@ import json
from django import urls as urlresolvers
from django.conf import settings
from django.contrib import admin
from django.core.exceptions import FieldDoesNotExist
from django.forms.utils import pretty_name
from django.urls.exceptions import NoReverseMatch
@ -16,11 +17,11 @@ MAX = 75
class LogEntryAdminMixin:
@admin.display(description="Created")
def created(self, obj):
return localtime(obj.timestamp).strftime("%Y-%m-%d %H:%M:%S")
created.short_description = "Created"
return localtime(obj.timestamp)
@admin.display(description="User")
def user_url(self, obj):
if obj.actor:
app_label, model = settings.AUTH_USER_MODEL.split(".")
@ -33,8 +34,7 @@ class LogEntryAdminMixin:
return "system"
user_url.short_description = "User"
@admin.display(description="Resource")
def resource_url(self, obj):
app_label, model = obj.content_type.app_label, obj.content_type.model
viewname = f"admin:{app_label}_{model}_change"
@ -48,8 +48,7 @@ class LogEntryAdminMixin:
'<a href="{}">{} - {}</a>', link, obj.content_type, obj.object_repr
)
resource_url.short_description = "Resource"
@admin.display(description="Changes")
def msg_short(self, obj):
if obj.action == LogEntry.Action.DELETE:
return "" # delete
@ -61,8 +60,7 @@ class LogEntryAdminMixin:
fields = fields[:i] + " .."
return "%d change%s: %s" % (len(changes), s, fields)
msg_short.short_description = "Changes"
@admin.display(description="Changes")
def msg(self, obj):
changes = json.loads(obj.changes)
@ -114,8 +112,6 @@ class LogEntryAdminMixin:
return mark_safe("".join(msg))
msg.short_description = "Changes"
def _format_header(self, *labels):
return format_html(
"".join(["<tr>", "<th>{}</th>" * len(labels), "</tr>"]), *labels

View file

@ -1294,7 +1294,8 @@ class AdminPanelTest(TestCase):
("Asia/Kathmandu", "2022-08-01 17:45:00"),
]:
with self.settings(TIME_ZONE=tz):
self.assertEqual(self.admin.created(log_entry), timestamp)
created = self.admin.created(log_entry)
self.assertEqual(created.strftime("%Y-%m-%d %H:%M:%S"), timestamp)
class DiffMsgTest(TestCase):