feat: Add basic metrics

This commit is contained in:
moanos [he/him] 2024-06-06 23:16:57 +02:00
parent 4857447c29
commit c38f1d2244
3 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,22 @@
from fellchensammlung.models import User, AdoptionNotice, AdoptionNoticeStatus
def gather_metrics_data():
"""USERS"""
num_user = User.objects.count()
num_staff = User.objects.filter(is_staff=True).count()
"""Adoption notices"""
num_adoption_notices = AdoptionNotice.objects.count()
num_adoption_notices_active = AdoptionNotice.objects.filter(adoptionnoticestatus__major_status=AdoptionNoticeStatus.ACTIVE).count()
adoption_notices_without_location = AdoptionNotice.objects.filter(location__isnull=True).count()
data = {
'users': num_user,
'staff': num_staff,
'adoption_notices': num_adoption_notices,
'adoption_notices_active': num_adoption_notices_active,
'adoption_notices_without_location': adoption_notices_without_location
}
return data

View File

@ -9,6 +9,7 @@ from . import views
urlpatterns = [ urlpatterns = [
path("", views.index, name="index"), path("", views.index, name="index"),
path("rss/", LatestAdoptionNoticesFeed(), name="rss"), path("rss/", LatestAdoptionNoticesFeed(), name="rss"),
path("metrics/", views.metrics, name="metrics"),
# ex: /animal/5/ # ex: /animal/5/
path("tier/<int:animal_id>/", views.animal_detail, name="animal-detail"), path("tier/<int:animal_id>/", views.animal_detail, name="animal-detail"),
# ex: /animal/5/edit # ex: /animal/5/edit

View File

@ -1,6 +1,6 @@
import logging import logging
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect, JsonResponse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
@ -17,6 +17,7 @@ from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, Comm
AdoptionNoticeSearchForm AdoptionNoticeSearchForm
from .models import Language, Announcement from .models import Language, Announcement
from .tools.geo import GeoAPI from .tools.geo import GeoAPI
from .tools.metrics import gather_metrics_data
def index(request): def index(request):
@ -298,3 +299,8 @@ def modqueue(request):
open_reports = Report.objects.filter(status=Report.WAITING) open_reports = Report.objects.filter(status=Report.WAITING)
context = {"reports": open_reports} context = {"reports": open_reports}
return render(request, 'fellchensammlung/modqueue.html', context=context) return render(request, 'fellchensammlung/modqueue.html', context=context)
def metrics(request):
data = gather_metrics_data()
return JsonResponse(data)