2018-12-10 02:11:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2017-03-22 16:15:25 +00:00
|
|
|
|
2017-12-10 16:29:25 +00:00
|
|
|
from django.shortcuts import get_object_or_404
|
2018-01-08 11:16:28 +00:00
|
|
|
from rest_framework import viewsets, generics
|
|
|
|
from rest_framework.views import Response
|
2017-03-22 16:15:25 +00:00
|
|
|
|
2022-10-24 12:14:18 +00:00
|
|
|
from common.drf.serializers import CeleryTaskExecutionSerializer
|
2022-10-08 08:55:14 +00:00
|
|
|
from ..models import AdHoc, AdHocExecution
|
2020-06-15 11:42:36 +00:00
|
|
|
from ..serializers import (
|
|
|
|
AdHocSerializer,
|
|
|
|
AdHocExecutionSerializer,
|
|
|
|
AdHocDetailSerializer,
|
|
|
|
)
|
2018-12-10 02:11:54 +00:00
|
|
|
|
|
|
|
__all__ = [
|
2022-10-08 08:55:14 +00:00
|
|
|
'AdHocViewSet', 'AdHocExecutionViewSet'
|
2018-12-10 02:11:54 +00:00
|
|
|
]
|
2017-03-22 16:15:25 +00:00
|
|
|
|
|
|
|
|
2017-12-10 16:29:25 +00:00
|
|
|
class AdHocViewSet(viewsets.ModelViewSet):
|
2018-07-14 16:55:05 +00:00
|
|
|
queryset = AdHoc.objects.all()
|
2017-12-10 16:29:25 +00:00
|
|
|
serializer_class = AdHocSerializer
|
|
|
|
|
2020-06-15 11:42:36 +00:00
|
|
|
def get_serializer_class(self):
|
|
|
|
if self.action == 'retrieve':
|
|
|
|
return AdHocDetailSerializer
|
|
|
|
return super().get_serializer_class()
|
|
|
|
|
2017-12-10 16:29:25 +00:00
|
|
|
|
2022-10-08 08:55:14 +00:00
|
|
|
class AdHocExecutionViewSet(viewsets.ModelViewSet):
|
2020-03-12 08:24:38 +00:00
|
|
|
queryset = AdHocExecution.objects.all()
|
|
|
|
serializer_class = AdHocExecutionSerializer
|
2017-12-10 16:29:25 +00:00
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
task_id = self.request.query_params.get('task')
|
2017-12-20 03:30:15 +00:00
|
|
|
adhoc_id = self.request.query_params.get('adhoc')
|
2022-10-08 08:55:14 +00:00
|
|
|
|
2017-12-10 16:29:25 +00:00
|
|
|
if task_id:
|
2022-10-08 08:55:14 +00:00
|
|
|
task = get_object_or_404(AdHoc, id=task_id)
|
2017-12-10 16:29:25 +00:00
|
|
|
adhocs = task.adhoc.all()
|
|
|
|
self.queryset = self.queryset.filter(adhoc__in=adhocs)
|
2017-12-20 03:30:15 +00:00
|
|
|
|
|
|
|
if adhoc_id:
|
|
|
|
adhoc = get_object_or_404(AdHoc, id=adhoc_id)
|
|
|
|
self.queryset = self.queryset.filter(adhoc=adhoc)
|
2017-12-10 16:29:25 +00:00
|
|
|
return self.queryset
|
2018-03-30 14:03:43 +00:00
|
|
|
|
|
|
|
|
2018-04-01 15:45:37 +00:00
|
|
|
|
2018-03-30 14:03:43 +00:00
|
|
|
|
2018-04-02 07:54:49 +00:00
|
|
|
|