Пример #1
0
 def put(self, request, pk):
     print('Request PUT:', pk)
     serializer = ReservationListSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
 def get(self, request):
     queryset = ReservationList.objects.all().order_by('-DATE')
     serializer = ReservationListSerializer(queryset, many=True)
     header = {
         "Access-Control-Allow-Origin":
         "*",
         "Access-Control-Allow-Methods":
         "GET,POST,PUT,DELETE,OPTIONS",
         "Access-Control-Allow-Headers":
         "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
     }
     return Response(data=serializer.data, headers=header)
Пример #3
0
    def post(self, request):
        serializer = ReservationListSerializer(data=request.data)
        if serializer.is_valid():

            stol = request.data.get('ID_TABLE')
            date = request.data.get('DATE')
            h_from = request.data.get('HOUR_FROM')
            h_to = request.data.get('HOUR_TO')
            user = get_object_or_404(User, username=request.user)
            subject = 'Potwierdzenie rezerwacji dokonanej na bilardapp'
            from_email = settings.EMAIL_HOST_USER
            to_email = [user.email]
            serializer.save()
            id_res = serializer.data['ID_RES']
            oplata_get = get_object_or_404(ReservationList, pk=id_res)
            serializer_ceny = ReservationListSerializer(oplata_get)
            oplata = serializer_ceny.data['CHARGE']
            imie = user.first_name
            signup_message = "Dziękujemy %s za dokonanie rezerwacji!\nPoniżej znajdują się informacje o rezerwacji:\n ID Rezerwacji: %d,\n Stół: %s, \n Data: %s,\n Godzina od: %s do %s,\n Opłata: %s \nZapraszamy do klubu 15 minut przed dokonaną rezerwacją w celu jej potwierdzenia.\nDziekujemy i zapraszamy ponownie do skorzystania z naszych usług.\nProsimy nie odpowiadać na ten email.\nPozdrawiamy,\nBilardApp" % (
                imie, id_res, stol, date, h_from, h_to, oplata)
            send_mail(subject=subject,
                      message=signup_message,
                      from_email=from_email,
                      recipient_list=to_email,
                      fail_silently=False)

            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #4
0
 def put(self, request):
     serializer = ReservationListSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #5
0
 def get(self, request):
     queryset = ReservationList.objects.all().order_by('-DATE')
     serializer = ReservationListSerializer(queryset, many=True)
     return Response(serializer.data)
Пример #6
0
 def get(self, request, pk):
     testsite = get_object_or_404(ReservationList, pk=pk)
     serializer = ReservationListSerializer(testsite)
     return Response(serializer.data)
Пример #7
0
 def get(self, request):
     user = get_object_or_404(User, username=request.user)
     history = ReservationList.objects.filter(ID_USER=user.pk)
     serializer = ReservationListSerializer(history, many=True)
     return Response(serializer.data)