Пример #1
0
def scan_replace(request, scan_id=None):
    try:
        scan = Scan.objects.org_filter(request.user, pk=scan_id).get()
    except Scan.DoesNotExist:
        raise PermissionDenied
    form = ScanUploadForm(request.POST or None, request.FILES or None, types={"pdf": "application/pdf"})
    if form.is_valid():
        filepath = tasks.move_scan_file(uploaded_file=request.FILES["file"])
        scan.full_delete(filesonly=True)
        scan.uploader = request.user
        scan.pdf = os.path.relpath(filepath, settings.MEDIA_ROOT)
        scan.save()

        task_id = tasks.split_scan.delay(scan_id=scan.pk, redirect=reverse("moderation.edit_scan", args=[scan.pk]))
        return redirect("moderation.wait_for_processing", task_id)
    return render(request, "scanning/replace.html", {"form": form})
Пример #2
0
def scan_merge(request, scan_id):
    """ Merge an existing scan with a new file """
    try:
        scan = Scan.objects.org_filter(request.user, pk=scan_id).get()
    except Scan.DoesNotExist:
        raise Http404
    form = ScanUploadForm(request.POST or None, request.FILES or None, types={"pdf": "application/pdf"})
    if form.is_valid():
        with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as fh:
            for chunk in request.FILES["file"].chunks():
                fh.write(chunk)
            name = fh.name
        task_id = tasks.merge_scans.delay(
            scan_id=scan_id, filename=name, redirect=reverse("moderation.edit_scan", args=[scan.pk])
        )
        return redirect("moderation.wait_for_processing", task_id)
    return render(request, "scanning/merge.html", {"form": form})
Пример #3
0
def scan_replace(request, scan_id=None):
    try:
        scan = Scan.objects.org_filter(request.user, pk=scan_id).get()
    except Scan.DoesNotExist:
        raise PermissionDenied
    form = ScanUploadForm(request.POST or None, request.FILES or None, types={
        "pdf": "application/pdf",
    })
    if form.is_valid():
        filepath = tasks.move_scan_file(uploaded_file=request.FILES['file'])
        scan.full_delete(filesonly=True)
        scan.uploader = request.user
        scan.pdf = os.path.relpath(filepath, settings.MEDIA_ROOT)
        scan.save()

        task_id = tasks.split_scan.delay(
            scan_id=scan.pk, 
            redirect=reverse("moderation.edit_scan", args=[scan.pk])
        )
        return redirect('moderation.wait_for_processing', task_id)
    return render(request, "scanning/replace.html", {'form': form})
Пример #4
0
def scan_merge(request, scan_id):
    """ Merge an existing scan with a new file """
    try:
        scan = Scan.objects.org_filter(request.user, pk=scan_id).get()
    except Scan.DoesNotExist:
        raise Http404
    form = ScanUploadForm(request.POST or None, request.FILES or None, types={
        'pdf': 'application/pdf',
    })
    if form.is_valid():
        with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as fh:
            for chunk in request.FILES['file'].chunks():
                fh.write(chunk)
            name = fh.name
        task_id = tasks.merge_scans.delay(
                scan_id=scan_id, 
                filename=name,
                redirect=reverse("moderation.edit_scan", args=[scan.pk])
            )
        return redirect("moderation.wait_for_processing", task_id)
    return render(request, "scanning/merge.html", {'form': form})