mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-10 15:37:30 +00:00
Admin improvements.
This commit is contained in:
parent
f35f5893d8
commit
229e2a3922
6 changed files with 91 additions and 29 deletions
hc/accounts
static/css/admin
templates/admin
|
@ -41,8 +41,8 @@ class ProfileAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = ("user", "email")
|
readonly_fields = ("user", "email")
|
||||||
raw_id_fields = ("current_project", )
|
raw_id_fields = ("current_project", )
|
||||||
list_select_related = ("user", )
|
list_select_related = ("user", )
|
||||||
list_display = ("id", "users", "checks", "invited",
|
list_display = ("id", "email", "last_login", "projects", "checks", "invited",
|
||||||
"reports_allowed", "ping_log_limit", "sms")
|
"reports_allowed", "sms")
|
||||||
search_fields = ["id", "user__email"]
|
search_fields = ["id", "user__email"]
|
||||||
list_filter = ("team_limit", "reports_allowed",
|
list_filter = ("team_limit", "reports_allowed",
|
||||||
"check_limit", "next_report_date")
|
"check_limit", "next_report_date")
|
||||||
|
@ -55,14 +55,17 @@ class ProfileAdmin(admin.ModelAdmin):
|
||||||
qs = qs.annotate(num_checks=Count("user__project__check", distinct=True))
|
qs = qs.annotate(num_checks=Count("user__project__check", distinct=True))
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
@mark_safe
|
def email(self, obj):
|
||||||
def users(self, obj):
|
|
||||||
if obj.num_members == 0:
|
|
||||||
return obj.user.email
|
return obj.user.email
|
||||||
else:
|
|
||||||
return render_to_string("admin/profile_list_team.html", {
|
def last_login(self, obj):
|
||||||
"profile": obj
|
return obj.user.last_login
|
||||||
})
|
|
||||||
|
@mark_safe
|
||||||
|
def projects(self, obj):
|
||||||
|
return render_to_string("admin/profile_list_projects.html", {
|
||||||
|
"profile": obj
|
||||||
|
})
|
||||||
|
|
||||||
@mark_safe
|
@mark_safe
|
||||||
def checks(self, obj):
|
def checks(self, obj):
|
||||||
|
@ -80,23 +83,72 @@ class ProfileAdmin(admin.ModelAdmin):
|
||||||
def sms(self, obj):
|
def sms(self, obj):
|
||||||
return "%d of %d" % (obj.sms_sent, obj.sms_limit)
|
return "%d of %d" % (obj.sms_sent, obj.sms_limit)
|
||||||
|
|
||||||
def email(self, obj):
|
|
||||||
return obj.user.email
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Project)
|
@admin.register(Project)
|
||||||
class ProjectAdmin(admin.ModelAdmin):
|
class ProjectAdmin(admin.ModelAdmin):
|
||||||
list_select_related = ("owner", )
|
list_select_related = ("owner", )
|
||||||
list_display = ("id", "name", "email")
|
list_display = ("id", "name_", "users", "engagement", "switch")
|
||||||
|
|
||||||
|
class Media:
|
||||||
|
css = {
|
||||||
|
'all': ('css/admin/projects.css',)
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_queryset(self, request):
|
||||||
|
qs = super(ProjectAdmin, self).get_queryset(request)
|
||||||
|
qs = qs.annotate(num_channels=Count("channel", distinct=True))
|
||||||
|
qs = qs.annotate(num_checks=Count("check", distinct=True))
|
||||||
|
qs = qs.annotate(num_members=Count("member", distinct=True))
|
||||||
|
return qs
|
||||||
|
|
||||||
|
def name_(self, obj):
|
||||||
|
if obj.name:
|
||||||
|
return obj.name
|
||||||
|
|
||||||
|
return "Default Project for %s" % obj.owner.email
|
||||||
|
|
||||||
|
@mark_safe
|
||||||
|
def users(self, obj):
|
||||||
|
if obj.num_members == 0:
|
||||||
|
return obj.owner.email
|
||||||
|
else:
|
||||||
|
return render_to_string("admin/project_list_team.html", {
|
||||||
|
"project": obj
|
||||||
|
})
|
||||||
|
|
||||||
def email(self, obj):
|
def email(self, obj):
|
||||||
return obj.owner.email
|
return obj.owner.email
|
||||||
|
|
||||||
|
@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 switch(self, obj):
|
||||||
|
url = reverse("hc-switch-project", args=[obj.code])
|
||||||
|
return "<a href='%s'>Show Checks</a>" % url
|
||||||
|
|
||||||
|
|
||||||
class HcUserAdmin(UserAdmin):
|
class HcUserAdmin(UserAdmin):
|
||||||
actions = ["send_report"]
|
actions = ["send_report"]
|
||||||
list_display = ('id', 'email', 'date_joined', 'last_login', 'engagement',
|
list_display = ('id', 'email', 'engagement', 'date_joined', 'last_login',
|
||||||
'is_staff', 'checks')
|
'is_staff')
|
||||||
|
|
||||||
list_display_links = ("id", "email")
|
list_display_links = ("id", "email")
|
||||||
list_filter = ("last_login", "date_joined", "is_staff", "is_active")
|
list_filter = ("last_login", "date_joined", "is_staff", "is_active")
|
||||||
|
@ -130,11 +182,6 @@ class HcUserAdmin(UserAdmin):
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@mark_safe
|
|
||||||
def checks(self, user):
|
|
||||||
url = reverse("hc-switch-team", args=[user.username])
|
|
||||||
return "<a href='%s'>Checks</a>" % url
|
|
||||||
|
|
||||||
def send_report(self, request, qs):
|
def send_report(self, request, qs):
|
||||||
for user in qs:
|
for user in qs:
|
||||||
user.profile.send_report()
|
user.profile.send_report()
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
.field-users ul {
|
.field-projects ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
color: #888;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.field-users ul li {
|
.field-projects ul li {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
static/css/admin/projects.css
Normal file
11
static/css/admin/projects.css
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
.field-users ul {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-users ul li {
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
|
5
templates/admin/profile_list_projects.html
Normal file
5
templates/admin/profile_list_projects.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<ul>
|
||||||
|
{% for project in profile.user.project_set.all %}
|
||||||
|
<li><a href="{% url 'hc-switch-project' project.code %}">{{ project }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
|
@ -1,6 +0,0 @@
|
||||||
{{ profile.user.email }}
|
|
||||||
<ul>
|
|
||||||
{% for member in profile.members %}
|
|
||||||
<li>{{ member.user.email }}</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
6
templates/admin/project_list_team.html
Normal file
6
templates/admin/project_list_team.html
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{{ project.owner.email }}
|
||||||
|
<ul>
|
||||||
|
{% for member in project.member_set.all %}
|
||||||
|
<li>{{ member.user.email }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
Loading…
Add table
Reference in a new issue