Ejemplo n.º 1
0
def upload_document(request, fingerprint_id, template_name='documents_upload_form.html'):
    """Store the files at the backend
    """

    # compute revision
    revision = get_revision()

    # Create the backend to store the file
    fh = FileSystemHandleFile()
    g_fh = HandleFile(fh)

    files = []
    # Run it for all the sent files (apply the persistence storage)
    path_file = None
    file_name = None
    if request.FILES:
        for name, f in request.FILES.items():
            # Handle file
            path_file = g_fh.handle_file(f, revision=revision)
            file_name = f.name
            # Serialize the response
            files.append(serialize(f))


    data = {'files': files}

    # Store the metadata in the database
    fd = FingerprintDocuments()
    fd.user = request.user
    fd.fingerprint_id = fingerprint_id
    fd.revision = revision
    fd.path = path_file
    fd.file_name = file_name
    fd.name = request.POST['pc_name']
    fd.description = request.POST['pc_comments']
    fd.save()

    response = JSONResponse(data, mimetype=response_mimetype(request))
    response['Content-Disposition'] = 'inline; filename=files.json'
    return response
Ejemplo n.º 2
0
def document_form_view_upload(request, template_name='documents_upload_form.html'):
    """Store the files at the backend
    """

    # Create the backend to store the file
    fh = FileSystemHandleFile()
    g_fh = HandleFile(fh)

    files = []
    # Run it for all the sent files (apply the persistence storage)
    if request.FILES:
        for name, f in request.FILES.items():
            # Handle file
            g_fh.handle_file(f)

            # Serialize the response
            files.append(serialize(f))

    data = {'files': files}
    response = JSONResponse(data, mimetype=response_mimetype(request))
    response['Content-Disposition'] = 'inline; filename=files.json'
    return response
Ejemplo n.º 3
0
def document_form_view_upload(request,
                              template_name='documents_upload_form.html'):
    """Store the files at the backend
    """

    # Create the backend to store the file
    fh = FileSystemHandleFile()
    g_fh = HandleFile(fh)

    files = []
    # Run it for all the sent files (apply the persistence storage)
    if request.FILES:
        for name, f in request.FILES.items():
            # Handle file
            g_fh.handle_file(f)

            # Serialize the response
            files.append(serialize(f))

    data = {'files': files}
    response = JSONResponse(data, mimetype=response_mimetype(request))
    response['Content-Disposition'] = 'inline; filename=files.json'
    return response
Ejemplo n.º 4
0
def upload_document_aux(request, fingerprint_id):
    # compute revision
    revision = get_revision()

    # Create the backend to store the file
    fh = FileSystemHandleFile()
    g_fh = HandleFile(fh)

    files = []
    # Run it for all the sent files (apply the persistence storage)
    path_file = None
    file_name = None

    print request.FILES

    if request.FILES:
        for name, f in request.FILES.items():
            # Handle file
            path_file = g_fh.handle_file(f, revision=revision)
            file_name = f.name
            # Serialize the response
            files.append(serialize(f))

    data = {'files': files}

    # Store the metadata in the database
    fd = FingerprintDocuments()
    fd.user = request.user
    fd.fingerprint_id = fingerprint_id
    fd.revision = revision
    fd.path = path_file
    fd.file_name = file_name
    fd.name = request.POST['pc_name']
    fd.description = request.POST['pc_comments']
    fd.save()

    return data