47 lines
2.7 KiB
Python
47 lines
2.7 KiB
Python
from django.shortcuts import render
|
|
from .serializers import *
|
|
from .models import *
|
|
from rest_framework.views import APIView
|
|
from rest_framework.response import Response
|
|
|
|
class CalendarEventsAPIView(APIView):
|
|
|
|
def get(self, request):
|
|
cal = CalendarEventsName.objects.all()
|
|
|
|
return Response(CalendarEventsNameSerializer(cal, many=True).data)
|
|
|
|
def post(self, request):
|
|
""" Записываем или обновляем глобальное название в таблицу, если есть участники так же пишем в соотвтв. таблицу с привязкой к событию.
|
|
Добавляем или удаляяем запись о событии
|
|
"""
|
|
namecalendar, created = CalendarEventsName.objects.update_or_create(name=request.data['participants'],
|
|
defaults = {'name':request.data['participants'], 'author_id': self.request.user.id})
|
|
|
|
|
|
for cal in request.data['calendar']:
|
|
|
|
CalendarEvents.objects.update_or_create(calendarname_id=namecalendar.pk,
|
|
name = cal['summary'],
|
|
author_id = self.request.user.id,
|
|
defaults = {'name': cal['summary'],
|
|
'description': cal['description'],
|
|
'cdate':cal['start'],
|
|
'enddate': cal['end'],
|
|
'author_id': self.request.user.id,
|
|
'place': cal['location'],
|
|
'calendarname_id': namecalendar.pk,
|
|
'frequency': 'repeat: {weekdays: [5] }'
|
|
})
|
|
# if len(cal['attendees']) > 0 :
|
|
# for player in cal['attendees']:
|
|
# print(player, '5555555555555')
|
|
# ParticipantsEvent.objects.update_or_create(participant=player,
|
|
# event=envent.pk,
|
|
# defaults= {'participant':player,
|
|
# 'event':envent.pk
|
|
|
|
# })
|
|
|
|
|
|
return Response('ru') |