mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Moved url logic away from render method and to entry model
This commit is contained in:
parent
0d971ab7ca
commit
adb6fac844
@ -162,6 +162,16 @@ class LogEntry(models.Model):
|
||||
def is_deletion(self):
|
||||
return self.action_flag == DELETION
|
||||
|
||||
def get_url_for_user(self):
|
||||
if not self.content_type:
|
||||
return self.get_admin_url()
|
||||
|
||||
view_permission_name = f"{self.content_type.app_label}.view_{self.content_type.model}"
|
||||
if self.user.has_perm(view_permission_name):
|
||||
return self.get_admin_url()
|
||||
|
||||
return None
|
||||
|
||||
def get_change_message(self):
|
||||
"""
|
||||
If self.change_message is a JSON structure, interpret it as a change
|
||||
|
@ -19,22 +19,9 @@ class AdminLogNode(template.Node):
|
||||
if not user_id.isdigit():
|
||||
user_id = context[self.user].pk
|
||||
entries = entries.filter(user__pk=user_id)
|
||||
filtered_context = entries.select_related("content_type", "user")[
|
||||
: int(self.limit)
|
||||
]
|
||||
for entry in filtered_context:
|
||||
content_type = entry.content_type
|
||||
if not content_type:
|
||||
entry.url = entry.get_admin_url()
|
||||
continue
|
||||
user = entry.user
|
||||
view_permission_name = f"{content_type.app_label}.view_{content_type.model}"
|
||||
user_has_permission = user.has_perm(view_permission_name)
|
||||
if user_has_permission:
|
||||
entry.url = entry.get_admin_url()
|
||||
else:
|
||||
entry.url = None
|
||||
context[self.varname] = filtered_context
|
||||
for entry in entries:
|
||||
entry.url = entry.get_url_for_user()
|
||||
context[self.varname] = entries[: int(self.limit)]
|
||||
return ""
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user