mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 10:34:21 +00:00
Birthday API and some more enhacements
This commit is contained in:
parent
8e8ee808b5
commit
bfa966e3d8
@ -1,3 +1,5 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.decorators import api_view
|
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 core.templatetags.renderer import markdown
|
||||||
from counter.models import Counter
|
from counter.models import Counter
|
||||||
from core.models import User, Group
|
from core.models import User, RealGroup
|
||||||
from club.models import Club
|
from club.models import Club
|
||||||
from api.views import serializers
|
from api.views import serializers
|
||||||
from api.views import RightManagedModelViewSet
|
from api.views import RightManagedModelViewSet
|
||||||
@ -42,10 +44,21 @@ class CounterViewSet(RightManagedModelViewSet):
|
|||||||
class UserViewSet(RightManagedModelViewSet):
|
class UserViewSet(RightManagedModelViewSet):
|
||||||
"""
|
"""
|
||||||
Manage Users (api/v1/user/)
|
Manage Users (api/v1/user/)
|
||||||
|
Only show active users
|
||||||
"""
|
"""
|
||||||
|
|
||||||
serializer_class = serializers.UserRead
|
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):
|
class ClubViewSet(RightManagedModelViewSet):
|
||||||
@ -62,4 +75,4 @@ class GroupViewSet(RightManagedModelViewSet):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
serializer_class = serializers.GroupRead
|
serializer_class = serializers.GroupRead
|
||||||
queryset = Group.objects.all()
|
queryset = RealGroup.objects.all()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from counter.models import Counter
|
from counter.models import Counter
|
||||||
from core.models import User, Group
|
from core.models import User, RealGroup
|
||||||
from club.models import Club
|
from club.models import Club
|
||||||
|
|
||||||
|
|
||||||
@ -20,15 +20,18 @@ class UserRead(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
|
fields = ('id', 'first_name', 'last_name', 'email',
|
||||||
|
'date_of_birth', 'nick_name', 'is_active', 'date_joined')
|
||||||
|
|
||||||
|
|
||||||
class ClubRead(serializers.ModelSerializer):
|
class ClubRead(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Club
|
model = Club
|
||||||
|
fields = ('id', 'name', 'unix_name', 'address', 'members')
|
||||||
|
|
||||||
|
|
||||||
class GroupRead(serializers.ModelSerializer):
|
class GroupRead(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Group
|
model = RealGroup
|
||||||
|
Loading…
Reference in New Issue
Block a user