-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from rest_framework import serializers | ||
|
||
from apps.events.models import Event | ||
from apps.training.models import TrainingSession | ||
from apps.users.serializers import BaseUserSerializer | ||
|
||
|
||
class EventCalendarSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Event | ||
fields = ['id', 'name', 'host', 'start', 'end'] | ||
|
||
|
||
class TrainingCalendarSerializer(serializers.ModelSerializer): | ||
student = BaseUserSerializer() | ||
|
||
class Meta: | ||
model = TrainingSession | ||
fields = ['id', 'student', 'level', 'type', 'position', 'start', 'end'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path('events/', views.EventCalendarView.as_view()), | ||
path('events/<int:year>/<int:month>/', views.EventCalendarView.as_view()), | ||
path('training/', views.TrainingCalendarView.as_view()), | ||
path('training/<int:year>/<int:month>/', views.TrainingCalendarView.as_view()), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from datetime import datetime | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from zhu_core.permissions import ReadOnly | ||
from .serializers import * | ||
from ..training.models import Status | ||
|
||
|
||
class EventCalendarView(APIView): | ||
permission_classes = [ReadOnly] | ||
|
||
def get(self, request, year=datetime.now().year, month=datetime.now().month): | ||
""" | ||
Get all events for given month and year. | ||
Defaults to current month of current year. | ||
""" | ||
events = Event.objects.filter(start__month=month, start__year=year) | ||
|
||
if not (request.user.is_authenticated and request.user.is_staff): | ||
events = events.exclude(hidden=True) | ||
|
||
serializer = EventCalendarSerializer(events, many=True) | ||
return Response(serializer.data) | ||
|
||
|
||
class TrainingCalendarView(APIView): | ||
permission_classes = [ReadOnly] | ||
|
||
def get(self, request, year=datetime.now().year, month=datetime.now().month): | ||
""" | ||
Get all training sessions for given month and year. | ||
Defaults to current month of current year. | ||
""" | ||
sessions = TrainingSession.objects.filter(start__month=month, start__year=year).exclude(status=Status.CANCELLED) | ||
|
||
serializer = TrainingCalendarSerializer(sessions, many=True) | ||
return Response(serializer.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters