You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

64 lines
1.9 KiB

from django.shortcuts import render
import datetime
import json
from collections import OrderedDict
from django.db.models import Q
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView, status
from apps.account.models import User
from apps.dobodbi_calendar.models import CalendarOccasions
from apps.dobodbi_calendar.serializer import CalendarSerializer
from utils.config_getter import get_config
class CalendarList(ListAPIView):
serializer_class = CalendarSerializer
pagination_class = None
permission_classes = (IsAuthenticated,)
# @method_decorator(cache_page(60 * 15)) # Cache for 1 Hour
# def dispatch(self, *args, **kwargs):
# return super().dispatch(*args, **kwargs)
def get_queryset(self):
queryset = CalendarOccasions.objects.all()
req = self.request
if v := req.query_params.get('last_updated'):
query &= Q(
updated_at__gte=v
)
return queryset
def list(self, request, *args, **kwargs):
q = self.get_queryset()
last_item_date = q.first()
if last_item_date:
last_updated = last_item_date.updated_at + datetime.timedelta(microseconds=1)
last_updated = str(last_updated)
else:
last_updated = None
d = self.get_serializer(q, many=True).data
data = OrderedDict({
'last_updated': last_updated,
'total': len(d),
'data': d,
})
return Response(data)
class AdjustmentConfigView(APIView):
def get(self, request):
adjustment_config = get_config('calendar__Adjustment')
return Response(json.loads(adjustment_config))