You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
1.5 KiB

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from hc.accounts.models import Profile
from hc.api.models import Channel, Check
@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):
list_display = ("id", "email", "reports_allowed", "next_report_date")
search_fields = ["user__email"]
def email(self, obj):
return obj.user.email
class HcUserAdmin(UserAdmin):
actions = ["send_report"]
list_display = ('id', 'username', 'email', 'date_joined', 'involvement',
'is_staff')
ordering = ["-id"]
def involvement(self, user):
result = ""
num_checks = Check.objects.filter(user=user).count()
num_channels = Channel.objects.filter(user=user).count()
if num_checks == 0:
result += "0 checks, "
elif num_checks == 1:
result += "1 check, "
else:
result += "<strong>%d checks</strong>, " % num_checks
if num_channels == 0:
result += "0 channels"
elif num_channels == 1:
result += "1 channel, "
else:
result += "<strong>%d channels</strong>, " % num_channels
return result
involvement.allow_tags = True
def send_report(self, request, qs):
for user in qs:
profile = Profile.objects.for_user(user)
profile.send_report()
self.message_user(request, "%d email(s) sent" % qs.count())
admin.site.unregister(User)
admin.site.register(User, HcUserAdmin)