示例#1
0
    def validation_status(self, request, *args, **kwargs):
        """
        View or modify validation status of specific instance.
        User needs 'validate_xform' permission to update the data.

        :param request: Request
        :return: Response
        """
        http_status = status.HTTP_200_OK
        instance = self.get_object()
        data = {}

        if request.method != "GET":
            if request.user.has_perm("validate_xform", instance.asset):
                if request.method == "PATCH" and not add_validation_status_to_instance(request, instance):
                    http_status = status.HTTP_400_BAD_REQUEST
                elif request.method == "DELETE":
                    if remove_validation_status_from_instance(instance):
                        http_status = status.HTTP_204_NO_CONTENT
                        data = None
                    else:
                        http_status = status.HTTP_400_BAD_REQUEST
            else:
                raise PermissionDenied(_(u"You do not have validate permissions."))

        if http_status == status.HTTP_200_OK:
            data = instance.validation_status

        return Response(data, status=http_status)
示例#2
0
    def validation_status(self, request, *args, **kwargs):
        """
        View or modify validation status of specific instance.
        User needs 'validate_xform' permission to update the data.

        :param request: Request
        :return: Response
        """
        http_status = status.HTTP_200_OK
        instance = self.get_object()
        data = {}

        if request.method != 'GET':
            if (
                request.method == 'PATCH'
                and not add_validation_status_to_instance(request, instance)
            ):
                http_status = status.HTTP_400_BAD_REQUEST
            elif request.method == 'DELETE':
                if remove_validation_status_from_instance(instance):
                    http_status = status.HTTP_204_NO_CONTENT
                    data = None
                else:
                    http_status = status.HTTP_400_BAD_REQUEST

        if http_status == status.HTTP_200_OK:
            data = instance.validation_status

        return Response(data, status=http_status)