Пример #1
0
def run_preset(request):
    """
    Execute a script (sent as JSON).
    """
    evalnode = request.POST.get("node", "")
    jsondata = request.POST.get("script")
    nodes = json.loads(jsondata)
    tree = script.Script(nodes)
    errors = tree.validate()
    if errors:
        return HttpResponse(json.dumps(dict(
            status="VALIDATION",
            errors=errors,
        )), mimetype="application/json")

    term = tree.get_node(evalnode)
    if term is None:
        terms = tree.get_terminals()
        if not terms:
            return HttpResponse(json.dumps(dict(
                status="NOSCRIPT",
            )), mimetype="application/json")
        term = terms[0]
    async = OcrTask.run_celery_task("run.script", (evalnode, nodes,
            request.output_path, _cache_name(request)),
            untracked=True, asyncronous=True, queue="interactive")
    out = dict(
        node=evalnode,
        task_id=async.task_id,
        status=async.status,
        results=async.result
    )
    response = HttpResponse(mimetype="application/json")
    json.dump(out, response, ensure_ascii=False)
    return response
Пример #2
0
def binary(request, pid):
    """
    Trigger a re-binarization of the image for viewing purposes.
    """
    taskname = "create.docdzi"
    doc = request.project.get_storage().get(pid)
    if not request.is_ajax():
        response = HttpResponse(mimetype=doc.binary_mimetype)
        with doc.binary_content as handle:
            response.write(handle.read())
        return response
    
    if doc.binary_empty:
        return HttpResponseNotFound
    async = OcrTask.run_celery_task(taskname, (request.project.pk, pid, "binary"),
            untracked=True,
            queue="interactive", asyncronous=request.POST.get("async", False))
    out = dict(task_id=async.task_id, status=async.status,
        results=async.result)
    return HttpResponse(json.dumps(out), mimetype="application/json")
Пример #3
0
def binary(request, pid):
    """
    Trigger a re-binarization of the image for viewing purposes.
    """
    taskname = "create.docdzi"
    doc = request.project.get_storage().get(pid)
    if not request.is_ajax():
        response = HttpResponse(mimetype=doc.binary_mimetype)
        with doc.binary_content as handle:
            response.write(handle.read())
        return response

    if doc.binary_empty:
        return HttpResponseNotFound
    async = OcrTask.run_celery_task(taskname,
                                    (request.project.pk, pid, "binary"),
                                    untracked=True,
                                    queue="interactive",
                                    asyncronous=request.POST.get(
                                        "async", False))
    out = dict(task_id=async .task_id,
               status=async .status,
               results=async .result)
    return HttpResponse(json.dumps(out), mimetype="application/json")