Skip to content

Commit 8f8b416

Browse files
committed
Better user profile admin page
1 parent 208d89b commit 8f8b416

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

pgcommitfest/userprofile/admin.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
from django.contrib import admin
2+
from django.db.models import Count, Q
23

34
from .models import UserProfile
45

56

67
class UserProfileAdmin(admin.ModelAdmin):
7-
list_display = ("user",)
8+
list_display = (
9+
"user",
10+
"notify_all_author",
11+
"notify_all_reviewer",
12+
"notify_all_committer",
13+
"show_relative_timestamps",
14+
)
15+
list_filter = (
16+
"notify_all_author",
17+
"notify_all_reviewer",
18+
"notify_all_committer",
19+
"show_relative_timestamps",
20+
)
21+
search_fields = ("user__username", "user__first_name", "user__last_name")
22+
23+
def changelist_view(self, request, extra_context=None):
24+
stats = UserProfile.objects.aggregate(
25+
total=Count("id"),
26+
author_on=Count("id", filter=Q(notify_all_author=True)),
27+
author_off=Count("id", filter=Q(notify_all_author=False)),
28+
reviewer_on=Count("id", filter=Q(notify_all_reviewer=True)),
29+
reviewer_off=Count("id", filter=Q(notify_all_reviewer=False)),
30+
committer_on=Count("id", filter=Q(notify_all_committer=True)),
31+
committer_off=Count("id", filter=Q(notify_all_committer=False)),
32+
timestamps_on=Count("id", filter=Q(show_relative_timestamps=True)),
33+
timestamps_off=Count("id", filter=Q(show_relative_timestamps=False)),
34+
)
35+
extra_context = extra_context or {}
36+
extra_context["notification_stats"] = stats
37+
return super().changelist_view(request, extra_context=extra_context)
838

939

1040
admin.site.register(UserProfile, UserProfileAdmin)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{% extends "admin/change_list.html" %}
2+
3+
{% block content %}
4+
{% if notification_stats %}
5+
<div style="margin-bottom: 20px; padding: 15px; background: #f8f8f8; border: 1px solid #ddd; border-radius: 4px;">
6+
<h3 style="margin-top: 0;">Notification Settings Statistics ({{ notification_stats.total }} profiles)</h3>
7+
<table style="border-collapse: collapse; width: 100%; max-width: 600px;">
8+
<thead>
9+
<tr>
10+
<th style="text-align: left; padding: 8px; border-bottom: 2px solid #ddd;">Setting</th>
11+
<th style="text-align: right; padding: 8px; border-bottom: 2px solid #ddd;">On</th>
12+
<th style="text-align: right; padding: 8px; border-bottom: 2px solid #ddd;">Off</th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
<tr>
17+
<td style="padding: 8px; border-bottom: 1px solid #eee;">Notify on all where author</td>
18+
<td style="text-align: right; padding: 8px; border-bottom: 1px solid #eee;">{{ notification_stats.author_on }}</td>
19+
<td style="text-align: right; padding: 8px; border-bottom: 1px solid #eee;">{{ notification_stats.author_off }}</td>
20+
</tr>
21+
<tr>
22+
<td style="padding: 8px; border-bottom: 1px solid #eee;">Notify on all where reviewer</td>
23+
<td style="text-align: right; padding: 8px; border-bottom: 1px solid #eee;">{{ notification_stats.reviewer_on }}</td>
24+
<td style="text-align: right; padding: 8px; border-bottom: 1px solid #eee;">{{ notification_stats.reviewer_off }}</td>
25+
</tr>
26+
<tr>
27+
<td style="padding: 8px; border-bottom: 1px solid #eee;">Notify on all where committer</td>
28+
<td style="text-align: right; padding: 8px; border-bottom: 1px solid #eee;">{{ notification_stats.committer_on }}</td>
29+
<td style="text-align: right; padding: 8px; border-bottom: 1px solid #eee;">{{ notification_stats.committer_off }}</td>
30+
</tr>
31+
<tr>
32+
<td style="padding: 8px;">Show relative timestamps</td>
33+
<td style="text-align: right; padding: 8px;">{{ notification_stats.timestamps_on }}</td>
34+
<td style="text-align: right; padding: 8px;">{{ notification_stats.timestamps_off }}</td>
35+
</tr>
36+
</tbody>
37+
</table>
38+
</div>
39+
{% endif %}
40+
{{ block.super }}
41+
{% endblock %}

0 commit comments

Comments
 (0)