Browse Source

Profiles admin: filtering by number of checks, show check count by project.

pull/366/head
Pēteris Caune 5 years ago
parent
commit
e04a92ccf1
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 40 additions and 7 deletions
  1. +28
    -6
      hc/accounts/admin.py
  2. +12
    -1
      templates/admin/profile_list_projects.html

+ 28
- 6
hc/accounts/admin.py View File

@ -65,6 +65,28 @@ class TeamFieldset(Fieldset):
)
class NumChecksFilter(admin.SimpleListFilter):
title = "Checks"
parameter_name = "num_checks"
def lookups(self, request, model_admin):
return (
("20", "more than 20"),
("50", "more than 50"),
("100", "more than 100"),
("500", "more than 500"),
("1000", "more than 1000"),
)
def queryset(self, request, queryset):
if not self.value():
return
value = int(self.value())
return queryset.filter(num_checks__gt=value)
@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):
class Media:
@ -72,15 +94,15 @@ class ProfileAdmin(admin.ModelAdmin):
readonly_fields = ("user", "email")
search_fields = ["id", "user__email"]
list_per_page = 50
list_per_page = 30
list_select_related = ("user",)
list_display = (
"id",
"email",
"usage",
"date_joined",
"last_active_date",
"projects",
"checks",
"invited",
"sms",
"reports_allowed",
@ -90,6 +112,7 @@ class ProfileAdmin(admin.ModelAdmin):
"last_active_date",
"reports_allowed",
"check_limit",
NumChecksFilter,
)
fieldsets = (ProfileFieldset.tuple(), TeamFieldset.tuple())
@ -99,13 +122,9 @@ class ProfileAdmin(admin.ModelAdmin):
qs = qs.prefetch_related("user__project_set")
qs = qs.annotate(num_members=Count("user__project__member", distinct=True))
qs = qs.annotate(num_checks=Count("user__project__check", distinct=True))
qs = qs.annotate(num_channels=Count("user__project__channel", distinct=True))
qs = qs.annotate(plan=F("user__subscription__plan_name"))
return qs
def usage(self, obj):
return _format_usage(obj.num_checks, obj.num_channels)
@mark_safe
def email(self, obj):
s = escape(obj.user.email)
@ -121,6 +140,9 @@ class ProfileAdmin(admin.ModelAdmin):
def projects(self, obj):
return render_to_string("admin/profile_list_projects.html", {"profile": obj})
def checks(self, obj):
return "%d of %d" % (obj.num_checks, obj.check_limit)
def invited(self, obj):
return "%d of %d" % (obj.num_members, obj.team_limit)


+ 12
- 1
templates/admin/profile_list_projects.html View File

@ -1,5 +1,16 @@
<ul>
{% for project in profile.user.project_set.all %}
<li><a href="{% url 'hc-checks' project.code %}">{{ project }}</a></li>
<li>
<a href="{% url 'hc-checks' project.code %}">{{ project }}</a>
{% if profile.num_checks > 1 %}
{% with project.num_checks as n %}
{% if n > 1 %}
<strong>({{ n }})</strong>
{% else %}
({{ n }})
{% endif %}
{% endwith %}
{% endif %}
</li>
{% endfor %}
</ul>

Loading…
Cancel
Save