|
1 | 1 | from django.urls import reverse |
2 | | -from django.views.generic.base import RedirectView |
| 2 | +from django.http import HttpResponseRedirect |
| 3 | +from django.views.generic.base import RedirectView, TemplateView |
| 4 | +from django.db.models.functions import TruncMonth |
| 5 | +from django.db.models import Count |
| 6 | + |
| 7 | +from skills_matcher_db.users.models import User |
| 8 | +from skills_matcher_db.project_owners.models import Project |
3 | 9 |
|
4 | 10 |
|
5 | 11 | class AdminLoginView(RedirectView): |
6 | 12 | def get(self, request, *args, **kwargs): |
7 | 13 | """ |
8 | | - Assuming the name of the external system's login url is "login" |
| 14 | + Assuming the name of the external system's login url is "login |
9 | 15 | """ |
10 | 16 | return HttpResponseRedirect(reverse("login")) |
| 17 | + |
| 18 | + |
| 19 | +class AdminMetricsView(TemplateView): |
| 20 | + template_name = "admin/core/metrics.html" |
| 21 | + |
| 22 | + def get_context_data(self, **kwargs): |
| 23 | + context = super(AdminMetricsView, self).get_context_data(**kwargs) |
| 24 | + # get user metric data |
| 25 | + user_metrics_qs = ( |
| 26 | + User.objects.annotate(month=TruncMonth("date_joined")) |
| 27 | + .values("month") |
| 28 | + .annotate(user_count=Count("id")) |
| 29 | + .order_by("month") |
| 30 | + ) |
| 31 | + |
| 32 | + # get user metric data |
| 33 | + projects_metrics_qs = ( |
| 34 | + Project.objects.annotate(month=TruncMonth("date_created")) |
| 35 | + .values("month") |
| 36 | + .annotate(project_count=Count("id")) |
| 37 | + .order_by("month") |
| 38 | + ) |
| 39 | + |
| 40 | + context.update( |
| 41 | + { |
| 42 | + "node_type": "assemblies", |
| 43 | + "user_metrics": user_metrics_qs, |
| 44 | + "project_metrics": projects_metrics_qs, |
| 45 | + } |
| 46 | + ) |
| 47 | + return context |
0 commit comments