Example #1
0
 def updateBackground(self,
                      request,
                      identifier=None,
                      name=None,
                      format=None):
     try:
         requestBody = json.loads(request.body)["annotationList"]
         activity = Activity(username=request.user.username,
                             requestPath=request.get_full_path(),
                             requestMethod=request.method,
                             remoteAddress=request.META['REMOTE_ADDR'],
                             startTime=datetime.now())
         user = request.user.to_mongo()
         del user["_id"]
         if settings.QUEUE_PUT_ENABLED:
             queue = Queue(status="Pending",
                           activity=activity.to_mongo()).save()
             activity.requestBody = requestBody
             activity.save()
             if settings.QUEUE_RUNNER != "CELERY":
                 Runner(target=updateAnnotationList,
                        args=(user, identifier, name, requestBody, False,
                              str(queue.id), str(activity.id),
                              initializeNewBulkActions())).start()
             else:
                 updateAnnotationList.delay(user, identifier,
                                            name, requestBody, False,
                                            str(queue.id), str(activity.id),
                                            initializeNewBulkActions())
             return Response(status=status.HTTP_202_ACCEPTED,
                             data={
                                 'message':
                                 "Request Accepted",
                                 "status":
                                 settings.IIIF_BASE_URL + '/queue/' +
                                 str(queue.id)
                             })
         else:
             activity.requestBody = requestBody
             activity.save()
             result = updateAnnotationList(user, identifier, name,
                                           requestBody, False, None,
                                           str(activity.id),
                                           initializeNewBulkActions())
             return Response(status=result["status"],
                             data={
                                 "responseBody": result["data"],
                                 "responseCode": result["status"]
                             })
     except Exception as e:  # pragma: no cover
         return Response(status=status.HTTP_400_BAD_REQUEST,
                         data={'error': e.message})
Example #2
0
 def destroyBackground(self, request, name=None, format=None):
     try:
         activity = Activity(username=request.user.username,
                             requestPath=request.get_full_path(),
                             requestMethod=request.method,
                             remoteAddress=request.META['REMOTE_ADDR'],
                             startTime=datetime.now())
         user = request.user.to_mongo()
         del user["_id"]
         if settings.QUEUE_DELETE_ENABLED:
             queue = Queue(status="Pending",
                           activity=activity.to_mongo()).save()
             activity.save()
             if settings.QUEUE_RUNNER != "CELERY":
                 Runner(target=destroyCollection,
                        args=(user, name, False, str(queue.id),
                              str(activity.id))).start()
             else:
                 destroyCollection.delay(user, name, False, str(queue.id),
                                         str(activity.id))
             return Response(status=status.HTTP_202_ACCEPTED,
                             data={
                                 'message':
                                 "Request Accepted",
                                 "status":
                                 settings.IIIF_BASE_URL + '/queue/' +
                                 str(queue.id)
                             })
         else:
             activity.save()
             result = destroyCollection(user, name, False, None,
                                        str(activity.id))
             return Response(status=result["status"],
                             data={
                                 "responseBody": result["data"],
                                 "responseCode": result["status"]
                             })
     except Exception as e:  # pragma: no cover
         return Response(status=status.HTTP_400_BAD_REQUEST,
                         data={'error': e.message})