Esempio n. 1
0
    def post(self, request, *args, **kwargs):
        """Import a manifest at a remote_url."""

        remote_url = request.data.get("remote_url")

        if not remote_url:
            return Response(
                {'error': 'Did not provide remote_url.'},
                status=status.HTTP_400_BAD_REQUEST)

        shared_id = str(uuid.uuid4())
        imp = ManifestPreImporter(remote_url)
        lst = imp.get_all_urls()

        # If there are manifests to import, create a celery group for the task.
        if lst:
            if len(lst) == 1:
                g = group([import_single_manifest.s(imp.text, lst[0])])
            else:
                g = group([import_single_manifest.s(None, url) for url in lst]).skew(start=0, step=0.3)
            task = g.apply_async(task_id=shared_id)
            task.save()
        else:
            if imp.errors:
                return Response({'errors': imp.errors}, status=status.HTTP_400_BAD_REQUEST)
            return Response({'errors': ['Failed to find recognisable IIIF manifest data.']}, status=status.HTTP_400_BAD_REQUEST)

        # Return a URL where the status of the import can be polled.
        status_url = reverse('status', request=request, args=[shared_id])
        return Response({'status': status_url}, status.HTTP_202_ACCEPTED)
Esempio n. 2
0
    def post(self, request, *args, **kwargs):
        """Import a manifest at a remote_url."""

        if request.META.get('CONTENT_TYPE') != 'application/json':
            remote_url = request.POST.get('remote_url')
        else:
            encoding = request.encoding or settings.DEFAULT_CHARSET
            j_dump = json.loads(request.body.decode(encoding))

            if isinstance(j_dump, dict):
                remote_url = j_dump.get('remote_url')
            else:
                remote_url = None

        if not remote_url:
            return Response({'error': 'Did not provide remote_url.'},
                            status=status.HTTP_400_BAD_REQUEST)

        shared_id = str(uuid.uuid4())
        imp = ManifestPreImporter(remote_url)
        lst = imp.get_all_urls()

        # If there are manifests to import, create a celery group for the task.
        if lst:
            g = group([
                get_document.s(url) | import_single_manifest.s(url)
                for url in lst
            ]).skew(start=0, step=0.3)
            task = g.apply_async(task_id=shared_id)
            task.save()
        else:
            if imp.errors:
                return Response({'errors': imp.errors},
                                status=status.HTTP_400_BAD_REQUEST)
            return Response(
                {
                    'errors':
                    ['Failed to find recognisable IIIF manifest data.']
                },
                status=status.HTTP_400_BAD_REQUEST)

        # Return a URL where the status of the import can be polled.
        status_url = reverse('status', request=request, args=[shared_id])
        return Response({'status': status_url}, status.HTTP_202_ACCEPTED)
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        """Import a manifest at a remote_url."""

        if request.META.get('CONTENT_TYPE') != 'application/json':
            remote_url = request.POST.get('remote_url')
        else:
            encoding = request.encoding or settings.DEFAULT_CHARSET
            j_dump = json.loads(request.body.decode(encoding))

            if isinstance(j_dump, dict):
                remote_url = j_dump.get('remote_url')
            else:
                remote_url = None

        if not remote_url:
            return Response(
                {'error': 'Did not provide remote_url.'},
                status=status.HTTP_400_BAD_REQUEST)

        shared_id = str(uuid.uuid4())
        imp = ManifestPreImporter(remote_url)
        lst = imp.get_all_urls()

        # If there are manifests to import, create a celery group for the task.
        if lst:
            g = group([get_document.s(url) | import_single_manifest.s(url) for url in lst]).skew(start=0, step=0.3)
            task = g.apply_async(task_id=shared_id)
            task.save()
        else:
            if imp.errors:
                return Response({'errors': imp.errors}, status=status.HTTP_400_BAD_REQUEST)
            return Response({'errors': ['Failed to find recognisable IIIF manifest data.']}, status=status.HTTP_400_BAD_REQUEST)

        # Return a URL where the status of the import can be polled.
        status_url = reverse('status', request=request, args=[shared_id])
        return Response({'status': status_url}, status.HTTP_202_ACCEPTED)
Esempio n. 4
0
def reimport(modeladmin, request, queryset):
    g = group([import_single_manifest.s(None, man.remote_url, force=True) for man in queryset]).skew(start=1, step=1)
    g.apply_async()