views.py 1.4 KB
Newer Older
1

2
import logging
3
from rest_framework import generics, views
4
from rest_framework.authentication import TokenAuthentication, BasicAuthentication
5
from rest_framework.response import Response
6
from .serializers import SiteSerializer, ServiceSerializer
7

8
9
10
LOGGER = logging.getLogger(__name__)


11
# authentication class for the client api
12
AUTHENTICATION_CLASSES = (BasicAuthentication, )
13

14

15
class DeploymentsView(generics.RetrieveAPIView):
Lukas Burgey's avatar
Lukas Burgey committed
16
    authentication_classes = AUTHENTICATION_CLASSES
17
    serializer_class = SiteSerializer
18
19

    def get_object(self):
20
        return self.request.user.site
21
22


23
24
# the client has to fetch the configuration (like services etc.) here
class ConfigurationView(generics.ListAPIView):
Lukas Burgey's avatar
Lukas Burgey committed
25
    authentication_classes = AUTHENTICATION_CLASSES
26
    serializer_class = ServiceSerializer
27
28

    def get_queryset(self):
29
30
        site = self.request.user.site
        return site.services.all()
31
32
33


class AckView(views.APIView):
Lukas Burgey's avatar
Lukas Burgey committed
34
    authentication_classes = AUTHENTICATION_CLASSES
35

36
    def delete(self, request, task_id=None):
37
38
        # find the corresponding task for this item
        for item in request.user.site.task_items.all():
39
            if item.task.id == int(task_id):
40
41
42
                item.task.item_finished(request.user.site)
                return Response({'ok': True})

43
44
45
        # this is no critical
        LOGGER.info('%s executed the obsolete task#%s', request.user, task_id)
        return Response({'ok': True})