feat: Add basic metrics
This commit is contained in:
parent
4857447c29
commit
c38f1d2244
22
src/fellchensammlung/tools/metrics.py
Normal file
22
src/fellchensammlung/tools/metrics.py
Normal 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
|
@ -9,6 +9,7 @@ from . import views
|
||||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
path("rss/", LatestAdoptionNoticesFeed(), name="rss"),
|
||||
path("metrics/", views.metrics, name="metrics"),
|
||||
# ex: /animal/5/
|
||||
path("tier/<int:animal_id>/", views.animal_detail, name="animal-detail"),
|
||||
# ex: /animal/5/edit
|
||||
|
@ -1,6 +1,6 @@
|
||||
import logging
|
||||
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.http import HttpResponseRedirect, JsonResponse
|
||||
from django.shortcuts import render, redirect
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
@ -17,6 +17,7 @@ from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, Comm
|
||||
AdoptionNoticeSearchForm
|
||||
from .models import Language, Announcement
|
||||
from .tools.geo import GeoAPI
|
||||
from .tools.metrics import gather_metrics_data
|
||||
|
||||
|
||||
def index(request):
|
||||
@ -298,3 +299,8 @@ def modqueue(request):
|
||||
open_reports = Report.objects.filter(status=Report.WAITING)
|
||||
context = {"reports": open_reports}
|
||||
return render(request, 'fellchensammlung/modqueue.html', context=context)
|
||||
|
||||
|
||||
def metrics(request):
|
||||
data = gather_metrics_data()
|
||||
return JsonResponse(data)
|
||||
|
Loading…
Reference in New Issue
Block a user