def delete_async(self, request, *args, **kwargs):
        if request.method == 'DELETE':
            xform = self.get_object()
            resp = {
                u'job_uuid': tasks.delete_xform_async.delay(xform).task_id,
                u'time_async_triggered': datetime.now()}
            resp_code = status.HTTP_202_ACCEPTED

        elif request.method == 'GET':
            job_uuid = request.query_params.get('job_uuid')
            resp = tasks.get_async_status(job_uuid)
            resp_code = status.HTTP_202_ACCEPTED
            self.etag_data = '{}'.format(timezone.now())

        return Response(data=resp, status=resp_code)
Beispiel #2
0
    def delete_async(self, request, *args, **kwargs):
        if request.method == 'DELETE':
            xform = self.get_object()
            resp = {
                u'job_uuid': tasks.delete_xform_async.delay(xform.pk).task_id,
                u'time_async_triggered': datetime.now()}
            resp_code = status.HTTP_202_ACCEPTED

        elif request.method == 'GET':
            job_uuid = request.query_params.get('job_uuid')
            resp = tasks.get_async_status(job_uuid)
            resp_code = status.HTTP_202_ACCEPTED
            self.etag_data = '{}'.format(timezone.now())

        return Response(data=resp, status=resp_code)
Beispiel #3
0
    def create_async(self, request, *args, **kwargs):
        """ Temporary Endpoint for Async form creation """
        resp = headers = {}
        resp_code = status.HTTP_400_BAD_REQUEST

        if request.method == 'GET':
            self.etag_data = '{}'.format(timezone.now())
            survey = tasks.get_async_status(
                request.query_params.get('job_uuid'))

            if 'pk' in survey:
                xform = XForm.objects.get(pk=survey.get('pk'))
                serializer = XFormSerializer(xform,
                                             context={'request': request})
                headers = self.get_success_headers(serializer.data)
                resp = serializer.data
                resp_code = status.HTTP_201_CREATED
            else:
                resp_code = status.HTTP_202_ACCEPTED
                resp.update(survey)
        else:
            try:
                owner = _get_owner(request)
            except ValidationError as e:
                return Response({'message': e.messages[0]},
                                status=status.HTTP_400_BAD_REQUEST)

            fname = request.FILES.get('xls_file').name
            resp.update({
                u'job_uuid':
                tasks.publish_xlsform_async.delay(
                    request.user, request.POST, owner,
                    ({
                        'name': fname,
                        'data': request.FILES.get('xls_file').read()
                    } if isinstance(request.FILES.get('xls_file'),
                                    InMemoryUploadedFile) else
                     {
                         'name':
                         fname,
                         'path':
                         request.FILES.get('xls_file').temporary_file_path()
                     })).task_id
            })
            resp_code = status.HTTP_202_ACCEPTED

        return Response(data=resp, status=resp_code, headers=headers)
    def delete_async(self, request, *args, **kwargs):
        if request.method == 'DELETE':
            time_async_triggered = datetime.now()
            self.object = self.get_object()
            self.object.deleted_at = time_async_triggered
            self.object.save()
            xform = self.object
            resp = {
                u'job_uuid': tasks.delete_xform_async.delay(xform).task_id,
                u'time_async_triggered': time_async_triggered}
            resp_code = status.HTTP_202_ACCEPTED

        elif request.method == 'GET':
            job_uuid = request.QUERY_PARAMS.get('job_uuid')
            resp = tasks.get_async_status(job_uuid)
            resp_code = status.HTTP_202_ACCEPTED
        return Response(data=resp, status=resp_code)
Beispiel #5
0
    def delete_async(self, request, *args, **kwargs):
        if request.method == 'DELETE':
            time_async_triggered = datetime.now()
            self.object = self.get_object()
            self.object.deleted_at = time_async_triggered
            self.object.save()
            xform = self.object
            resp = {
                u'job_uuid': tasks.delete_xform_async.delay(xform).task_id,
                u'time_async_triggered': time_async_triggered
            }
            resp_code = status.HTTP_202_ACCEPTED

        elif request.method == 'GET':
            job_uuid = request.QUERY_PARAMS.get('job_uuid')
            resp = tasks.get_async_status(job_uuid)
            resp_code = status.HTTP_202_ACCEPTED
        return Response(data=resp, status=resp_code)
Beispiel #6
0
    def create_async(self, request, *args, **kwargs):
        """ Temporary Endpoint for Async form creation """
        resp = headers = {}
        resp_code = status.HTTP_400_BAD_REQUEST

        if request.method == 'GET':
            self.etag_data = '{}'.format(timezone.now())
            survey = tasks.get_async_status(
                request.query_params.get('job_uuid'))

            if 'pk' in survey:
                xform = XForm.objects.get(pk=survey.get('pk'))
                serializer = XFormSerializer(
                    xform, context={'request': request})
                headers = self.get_success_headers(serializer.data)
                resp = serializer.data
                resp_code = status.HTTP_201_CREATED
            else:
                resp_code = status.HTTP_202_ACCEPTED
                resp.update(survey)
        else:
            try:
                owner = _get_owner(request)
            except ValidationError as e:
                return Response({'message': e.messages[0]},
                                status=status.HTTP_400_BAD_REQUEST)

            fname = request.FILES.get('xls_file').name
            resp.update(
                {u'job_uuid':
                 tasks.publish_xlsform_async.delay(
                     request.user, request.POST, owner,
                     ({'name': fname,
                       'data': request.FILES.get('xls_file').read()}
                      if isinstance(request.FILES.get('xls_file'),
                                    InMemoryUploadedFile) else
                      {'name': fname,
                       'path': request.FILES.get(
                           'xls_file').temporary_file_path()})).task_id})
            resp_code = status.HTTP_202_ACCEPTED

        return Response(data=resp, status=resp_code, headers=headers)
Beispiel #7
0
    def delete_async(self, request, *args, **kwargs):
        if request.method == 'DELETE':
            xform = self.get_object()
            resp = {
                u'job_uuid': tasks.delete_xform_async.delay(
                    xform.pk,
                    request.user.id).task_id,
                u'time_async_triggered': datetime.now()}

            # clear project from cache
            safe_delete(f'{PROJ_OWNER_CACHE}{xform.project.pk}')
            resp_code = status.HTTP_202_ACCEPTED

        elif request.method == 'GET':
            job_uuid = request.query_params.get('job_uuid')
            resp = tasks.get_async_status(job_uuid)
            resp_code = status.HTTP_202_ACCEPTED
            self.etag_data = '{}'.format(timezone.now())

        return Response(data=resp, status=resp_code)