P-44
This commit is contained in:
1 parent
043575f962
commit
0c60252b52
6 files changed
+85
-16
No files matched your search
@@ -7,7 +7,7 @@ from rest_framework.response import Response
|
||||
import json
|
||||
from django.db.models.functions import TruncYear
|
||||
from django.db.models import Q
|
||||
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
|
||||
|
||||
|
||||
@@ -22,13 +22,47 @@ class ExclusionDatesAPIView(APIView):
|
||||
return Response({year:months})
|
||||
|
||||
|
||||
class GetCalendars(APIView):
|
||||
def get(self, request):
|
||||
|
||||
class MyCalendars(APIView):
|
||||
|
||||
def get(self, request):
|
||||
calendars = Calendar.objects.filter(Q(get_participants__participant_calendar__id=request.user.user.id) | Q(author__id=request.user.user.id)).distinct()
|
||||
return Response(CalendarsSerializer(calendars,many=True).data)
|
||||
# return Response(CalendarsSerializer(calendars,context={'request': request},many=True).data)
|
||||
#
|
||||
|
||||
@swagger_auto_schema(request_body=MyCalendarPostParameters)
|
||||
def post(self,request):
|
||||
'''
|
||||
Создание/редактирование календаря
|
||||
если нет id = пойдет создавать календарь. В противном случае - на обновление
|
||||
|
||||
|
||||
'''
|
||||
try:
|
||||
ob=MyCalendarPostParameters(data=request.data)
|
||||
if ob.is_valid():
|
||||
ob = ob.data
|
||||
if 'id' in ob:
|
||||
newcal,created = Calendar.objects.update_or_create(id=ob['id'],defaults=ob)
|
||||
|
||||
else:
|
||||
newcal=Calendar.objects.create(**ob, author=DictEmployee(id=request.user.user.id))
|
||||
|
||||
if 'participant' in ob:
|
||||
ptspnt = []
|
||||
for x in ob['participant']:
|
||||
x['participant_calendar']=DictEmployee(id=x['participant_calendar'])
|
||||
print(x['participant_calendar'])
|
||||
CalendarParticipants.objects.update_or_create(calendar=newcal, participant_calendar=x['participant_calendar'],
|
||||
defaults=x)
|
||||
ptspnt.append(x['participant_calendar'])
|
||||
print(ptspnt)
|
||||
CalendarParticipants.objects.exclude(calendar=newcal,participant_calendar__in=ptspnt).delete()
|
||||
else:
|
||||
return Response({"mess":"Ошибка валидации полей"})
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return Response({"mess":"Ошибка операции"})
|
||||
|
||||
return Response({"mess": f"Календарь успешно {'обновлен' if 'id' in ob else 'создан'}"})
|
||||
|
||||
|
||||
class GetEmployees(APIView):
|
||||
|
||||
Reference in new issue
Block a user