|
|
@ -1,6 +1,7 @@ |
|
|
|
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.template.loader import render_to_string |
|
|
|
from django.urls import reverse |
|
|
|
from django.utils.safestring import mark_safe |
|
|
@ -25,7 +26,7 @@ class ProfileFieldset(Fieldset): |
|
|
|
|
|
|
|
class TeamFieldset(Fieldset): |
|
|
|
name = "Team" |
|
|
|
fields = ("team_name", "team_access_allowed", "check_limit", |
|
|
|
fields = ("team_name", "team_limit", "check_limit", |
|
|
|
"ping_log_limit", "sms_limit", "sms_sent", "last_sms_date", |
|
|
|
"bill_to") |
|
|
|
|
|
|
@ -41,17 +42,23 @@ class ProfileAdmin(admin.ModelAdmin): |
|
|
|
readonly_fields = ("user", "email") |
|
|
|
raw_id_fields = ("current_team", ) |
|
|
|
list_select_related = ("user", ) |
|
|
|
list_display = ("id", "users", "checks", "team_access_allowed", |
|
|
|
list_display = ("id", "users", "checks", "invited", |
|
|
|
"reports_allowed", "ping_log_limit", "sms") |
|
|
|
search_fields = ["id", "user__email"] |
|
|
|
list_filter = ("team_access_allowed", "reports_allowed", |
|
|
|
list_filter = ("team_access_allowed", "team_limit", "reports_allowed", |
|
|
|
"check_limit", "next_report_date") |
|
|
|
|
|
|
|
fieldsets = (ProfileFieldset.tuple(), TeamFieldset.tuple()) |
|
|
|
|
|
|
|
def get_queryset(self, request): |
|
|
|
qs = super(ProfileAdmin, self).get_queryset(request) |
|
|
|
qs = qs.annotate(Count("member", distinct=True)) |
|
|
|
qs = qs.annotate(Count("user__check", distinct=True)) |
|
|
|
return qs |
|
|
|
|
|
|
|
@mark_safe |
|
|
|
def users(self, obj): |
|
|
|
if obj.member_set.count() == 0: |
|
|
|
if obj.member__count == 0: |
|
|
|
return obj.user.email |
|
|
|
else: |
|
|
|
return render_to_string("admin/profile_list_team.html", { |
|
|
@ -60,7 +67,7 @@ class ProfileAdmin(admin.ModelAdmin): |
|
|
|
|
|
|
|
@mark_safe |
|
|
|
def checks(self, obj): |
|
|
|
num_checks = Check.objects.filter(user=obj.user).count() |
|
|
|
num_checks = obj.user__check__count |
|
|
|
pct = 100 * num_checks / max(obj.check_limit, 1) |
|
|
|
pct = min(100, int(pct)) |
|
|
|
|
|
|
@ -69,6 +76,9 @@ class ProfileAdmin(admin.ModelAdmin): |
|
|
|
%d of %d |
|
|
|
""" % (pct, num_checks, obj.check_limit) |
|
|
|
|
|
|
|
def invited(self, obj): |
|
|
|
return "%d of %d" % (obj.member__count, obj.team_limit) |
|
|
|
|
|
|
|
def sms(self, obj): |
|
|
|
return "%d of %d" % (obj.sms_sent, obj.sms_limit) |
|
|
|
|
|
|
|