44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from rest_framework import viewsets
|
|
from rest_framework.decorators import api_view
|
|
from rest_framework.response import Response
|
|
|
|
from plugins import services
|
|
|
|
from .models import Groep, Persoon, Subgroep
|
|
from .serializers import GroepSerializer, PersoonSerializer, SubgroepSerializer
|
|
|
|
|
|
@api_view(["GET"])
|
|
def info(request):
|
|
"""Korte systeeminfo + welke modules actief zijn. Handig als gezondheidscheck."""
|
|
services.sync_states()
|
|
modules = services.describe_all()
|
|
return Response(
|
|
{
|
|
"naam": "Roosterwijs",
|
|
"fase": "1 - kerndomein (personen, groepen, subgroepen)",
|
|
"modules_totaal": len(modules),
|
|
"modules_actief": sum(1 for m in modules if m["enabled"]),
|
|
}
|
|
)
|
|
|
|
|
|
class GroepViewSet(viewsets.ModelViewSet):
|
|
queryset = Groep.objects.all()
|
|
serializer_class = GroepSerializer
|
|
|
|
|
|
class PersoonViewSet(viewsets.ModelViewSet):
|
|
serializer_class = PersoonSerializer
|
|
|
|
def get_queryset(self):
|
|
qs = Persoon.objects.select_related("groep").all()
|
|
rol = self.request.query_params.get("rol")
|
|
if rol:
|
|
qs = qs.filter(rol=rol)
|
|
return qs
|
|
|
|
|
|
class SubgroepViewSet(viewsets.ModelViewSet):
|
|
queryset = Subgroep.objects.prefetch_related("leden").all()
|
|
serializer_class = SubgroepSerializer
|