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.

58 lines
1.6 KiB

10 years ago
  1. from django.contrib import admin
  2. from django.contrib.auth.admin import UserAdmin
  3. from django.contrib.auth.models import User
  4. from hc.accounts.models import Profile
  5. from hc.api.models import Channel, Check
  6. @admin.register(Profile)
  7. class ProfileAdmin(admin.ModelAdmin):
  8. list_display = ("id", "email", "reports_allowed", "next_report_date",
  9. "ping_log_limit")
  10. search_fields = ["user__email"]
  11. def email(self, obj):
  12. return obj.user.email
  13. class HcUserAdmin(UserAdmin):
  14. actions = ["send_report"]
  15. list_display = ('id', 'username', 'email', 'date_joined', 'involvement',
  16. 'is_staff')
  17. ordering = ["-id"]
  18. def involvement(self, user):
  19. result = ""
  20. num_checks = Check.objects.filter(user=user).count()
  21. num_channels = Channel.objects.filter(user=user).count()
  22. if num_checks == 0:
  23. result += "0 checks, "
  24. elif num_checks == 1:
  25. result += "1 check, "
  26. else:
  27. result += "<strong>%d checks</strong>, " % num_checks
  28. if num_channels == 0:
  29. result += "0 channels"
  30. elif num_channels == 1:
  31. result += "1 channel, "
  32. else:
  33. result += "<strong>%d channels</strong>, " % num_channels
  34. return result
  35. involvement.allow_tags = True
  36. def send_report(self, request, qs):
  37. for user in qs:
  38. profile = Profile.objects.for_user(user)
  39. profile.send_report()
  40. self.message_user(request, "%d email(s) sent" % qs.count())
  41. admin.site.unregister(User)
  42. admin.site.register(User, HcUserAdmin)