Merge pull request #19630 from netbox-community/19599-user-changelog-sorting

Fixes #19599: Prevent exception when sorting user's recent activity
This commit is contained in:
bctiemann 2025-06-04 16:17:34 -04:00 committed by GitHub
commit 5fe5b2e7c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 24 deletions

View File

@ -191,12 +191,9 @@ class ProfileView(LoginRequiredMixin, View):
def get(self, request):
# Compile changelog table
changelog = ObjectChange.objects.valid_models().restrict(request.user, 'view').filter(
user=request.user
).prefetch_related(
'changed_object_type'
)[:20]
changelog = ObjectChange.objects.valid_models().restrict(request.user, 'view').filter(user=request.user)[:20]
changelog_table = ObjectChangeTable(changelog)
changelog_table.orderable = False
changelog_table.configure(request)
return render(request, self.template_name, {

View File

@ -1,12 +1,10 @@
{% extends 'account/base.html' %}
{% load helpers %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% block title %}{% trans "User Profile" %}{% endblock %}
{% block content %}
<div class="row mb-3">
<div class="row">
<div class="col-md-6">
<div class="card">
<h2 class="card-header">{% trans "Account Details" %}</h2>
@ -64,12 +62,7 @@
{% if perms.core.view_objectchange %}
<div class="row">
<div class="col-md-12">
<div class="card">
<h2 class="card-header text-center">{% trans "Recent Activity" %}</h2>
<div class="table-responsive">
{% render_table changelog_table 'inc/table.html' %}
</div>
</div>
{% include 'users/inc/user_activity.html' with user=user table=changelog_table %}
</div>
</div>
{% endif %}

View File

@ -0,0 +1,16 @@
{% load i18n %}
{% load render_table from django_tables2 %}
<div class="card">
<h2 class="card-header text-center">
{% trans "Recent Activity" %}
<div class="card-actions">
<a href="{% url 'core:objectchange_list' %}?user_id={{ user.pk }}" class="btn btn-ghost-primary btn-sm">
<i class="mdi mdi-arrow-right-thick" aria-hidden="true"></i> {% trans "View All" %}
</a>
</div>
</h2>
<div class="table-responsive">
{% render_table table 'inc/table.html' %}
</div>
</div>

View File

@ -1,14 +1,12 @@
{% extends 'generic/object.html' %}
{% load i18n %}
{% load helpers %}
{% load render_table from django_tables2 %}
{% block title %}{% trans "User" %} {{ object.username }}{% endblock %}
{% block subtitle %}{% endblock %}
{% block content %}
<div class="row mb-3">
<div class="row">
<div class="col-md-6">
<div class="card">
<h2 class="card-header">{% trans "User" %}</h2>
@ -74,12 +72,7 @@
{% if perms.core.view_objectchange %}
<div class="row">
<div class="col-md-12">
<div class="card">
<h2 class="text-center">{% trans "Recent Activity" %}</h2>
<div class="card-body table-responsive">
{% render_table changelog_table 'inc/table.html' %}
</div>
</div>
{% include 'users/inc/user_activity.html' with user=object table=changelog_table %}
</div>
</div>
{% endif %}

View File

@ -75,8 +75,9 @@ class UserView(generic.ObjectView):
template_name = 'users/user.html'
def get_extra_context(self, request, instance):
changelog = ObjectChange.objects.restrict(request.user, 'view').filter(user=instance)[:20]
changelog = ObjectChange.objects.valid_models().restrict(request.user, 'view').filter(user=instance)[:20]
changelog_table = ObjectChangeTable(changelog)
changelog_table.orderable = False
changelog_table.configure(request)
return {