Commit bfa966e3 authored by Sli's avatar Sli

Birthday API and some more enhacements

parent 8e8ee808
Pipeline #101 failed with stage
in 2 minutes and 8 seconds
import datetime
from django.shortcuts import get_object_or_404
from rest_framework.response import Response
from rest_framework.decorators import api_view
......@@ -7,7 +9,7 @@ from rest_framework.decorators import list_route
from core.templatetags.renderer import markdown
from counter.models import Counter
from core.models import User, Group
from core.models import User, RealGroup
from club.models import Club
from api.views import serializers
from api.views import RightManagedModelViewSet
......@@ -42,10 +44,21 @@ class CounterViewSet(RightManagedModelViewSet):
class UserViewSet(RightManagedModelViewSet):
"""
Manage Users (api/v1/user/)
Only show active users
"""
serializer_class = serializers.UserRead
queryset = User.objects.all()
queryset = User.objects.filter(is_active=True)
@list_route()
def birthday(self, request):
"""
Return all users born today (api/v1/user/birstdays)
"""
date = datetime.datetime.today()
self.queryset = self.queryset.filter(date_of_birth=date)
serializer = self.get_serializer(self.queryset, many=True)
return Response(serializer.data)
class ClubViewSet(RightManagedModelViewSet):
......@@ -62,4 +75,4 @@ class GroupViewSet(RightManagedModelViewSet):
"""
serializer_class = serializers.GroupRead
queryset = Group.objects.all()
queryset = RealGroup.objects.all()
from rest_framework import serializers
from counter.models import Counter
from core.models import User, Group
from core.models import User, RealGroup
from club.models import Club
......@@ -20,15 +20,18 @@ class UserRead(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'first_name', 'last_name', 'email',
'date_of_birth', 'nick_name', 'is_active', 'date_joined')
class ClubRead(serializers.ModelSerializer):
class Meta:
model = Club
fields = ('id', 'name', 'unix_name', 'address', 'members')
class GroupRead(serializers.ModelSerializer):
class Meta:
model = Group
model = RealGroup
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment