Browse Source

Admin improvements.

pull/217/head
Pēteris Caune 6 years ago
parent
commit
6d7942d7f9
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 41 additions and 36 deletions
  1. +37
    -16
      hc/accounts/admin.py
  2. +1
    -1
      hc/payments/admin.py
  3. +3
    -19
      static/css/admin/profiles.css

+ 37
- 16
hc/accounts/admin.py View File

@ -1,9 +1,10 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.db.models import Count
from django.db.models import Count, F
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.html import escape
from django.utils.safestring import mark_safe
from hc.accounts.models import Profile, Project
@ -41,11 +42,11 @@ class ProfileAdmin(admin.ModelAdmin):
readonly_fields = ("user", "email")
raw_id_fields = ("current_project", )
list_select_related = ("user", )
list_display = ("id", "email", "last_login", "projects", "checks", "invited",
"reports_allowed", "sms")
list_display = ("id", "email", "engagement", "date_joined", "last_login",
"projects", "invited", "sms", "reports_allowed")
search_fields = ["id", "user__email"]
list_filter = ("team_limit", "reports_allowed",
"check_limit", "next_report_date")
list_filter = ("user__date_joined", "user__last_login",
"team_limit", "reports_allowed", "check_limit")
fieldsets = (ProfileFieldset.tuple(), TeamFieldset.tuple())
@ -53,30 +54,50 @@ class ProfileAdmin(admin.ModelAdmin):
qs = super(ProfileAdmin, self).get_queryset(request)
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
@mark_safe
def engagement(self, obj):
result = ""
if obj.num_checks == 0:
result += "0 checks, "
elif obj.num_checks == 1:
result += "1 check, "
else:
result += "<strong>%d checks</strong>, " % obj.num_checks
if obj.num_channels == 0:
result += "0 channels"
elif obj.num_channels == 1:
result += "1 channel, "
else:
result += "<strong>%d channels</strong>, " % obj.num_channels
return result
@mark_safe
def email(self, obj):
return obj.user.email
s = escape(obj.user.email)
if obj.plan:
return "<span title='%s'>%s</span>" % (obj.plan, s)
return s
def last_login(self, obj):
return obj.user.last_login
def date_joined(self, obj):
return obj.user.date_joined
@mark_safe
def projects(self, obj):
return render_to_string("admin/profile_list_projects.html", {
"profile": obj
})
@mark_safe
def checks(self, obj):
pct = 100 * obj.num_checks / max(obj.check_limit, 1)
pct = min(100, int(pct))
return """
<span class="bar"><span style="width: %dpx"></span></span>
&nbsp; %d of %d
""" % (pct, obj.num_checks, obj.check_limit)
def invited(self, obj):
return "%d of %d" % (obj.num_members, obj.team_limit)


+ 1
- 1
hc/payments/admin.py View File

@ -13,7 +13,7 @@ class SubsAdmin(admin.ModelAdmin):
"user__email")
list_display = ("id", "email", "customer_id", "address_id",
"payment_method_token", "subscription_id", "plan_id",
"profile")
"plan_name", "profile")
list_filter = ("plan_id", )
raw_id_fields = ("user", )


+ 3
- 19
static/css/admin/profiles.css View File

@ -8,22 +8,6 @@
list-style-type: none;
}
.field-checks {
color: #888;
}
.bar {
display: inline-block;
width: 100px;
height: 10px;
border-radius: 5px;
overflow: hidden;
background: #ddd;
}
.bar span {
display: block;
height: 10px;
background: #79aec8;
}
.field-email span {
border-bottom: 2px solid #FFEB3B;
}

Loading…
Cancel
Save