Esempio n. 1
0
 def partial_update(self, request, pk=None, partial=True):
     task = self.get_object()
     if 'state' not in request.data:
         raise ValidationError(_("'state' must be provided with the request."))
     if request.data['state'] != 'canceled':
         raise ValidationError(_("The only acceptable value for 'state' is 'canceled'."))
     task = cancel_task(task.pk)
     serializer = self.serializer_class(task, context={'request': request})
     return Response(serializer.data)
Esempio n. 2
0
 def partial_update(self, request, pk=None, partial=True):
     task = self.get_object()
     if "state" not in request.data:
         raise ValidationError(
             _("'state' must be provided with the request."))
     if request.data["state"] != "canceled":
         raise ValidationError(
             _("The only acceptable value for 'state' is 'canceled'."))
     task = cancel_task(task.pk)
     # Check whether task is actually canceled
     http_status = None if task.state == TASK_STATES.CANCELED else status.HTTP_409_CONFLICT
     serializer = self.serializer_class(task, context={"request": request})
     return Response(serializer.data, status=http_status)
Esempio n. 3
0
 def cancel(self, request, pk=None):
     task = self.get_object()
     cancel_task(task.pk)
     return Response(status=status.HTTP_204_NO_CONTENT)
Esempio n. 4
0
 def cancel(self, request, pk=None):
     task = self.get_object()
     cancel_task(task.pk)
     return Response(status=status.HTTP_204_NO_CONTENT)