import logging from rest_framework import generics, views from rest_framework.authentication import TokenAuthentication, BasicAuthentication from rest_framework.response import Response from .serializers import SiteSerializer, ServiceSerializer LOGGER = logging.getLogger(__name__) # authentication class for the client api AUTHENTICATION_CLASSES = (BasicAuthentication, ) class DeploymentsView(generics.RetrieveAPIView): authentication_classes = AUTHENTICATION_CLASSES serializer_class = SiteSerializer def get_object(self): return self.request.user.site # the client has to fetch the configuration (like services etc.) here class ConfigurationView(generics.ListAPIView): authentication_classes = AUTHENTICATION_CLASSES serializer_class = ServiceSerializer def get_queryset(self): site = self.request.user.site return site.services.all() class AckView(views.APIView): authentication_classes = AUTHENTICATION_CLASSES def delete(self, request, task_id=None): # find the corresponding task for this item for item in request.user.site.task_items.all(): if item.task.id == int(task_id): item.task.item_finished(request.user.site) return Response({'ok': True}) # this is no critical LOGGER.info('%s executed the obsolete task#%s', request.user, task_id) return Response({'ok': True})