예제 #1
0
def doc(doc_id):
    """Presentation of a single document"""
    docu = document.retrieve_document(doc_id)
    if not docu:
        abort(404)

    return render_template('doc.html', page='doc', **docu)
예제 #2
0
def doc(doc_id):
    """Presentation of a single document"""
    docu = document.retrieve_document(doc_id)
    if not docu:
        abort(404)

    return render_template('doc.html', page='doc', **docu)
예제 #3
0
def listing(page=0):
    """Create a list of all available documents"""
    # 1. request all documents from DB
    documents = Document.query.order_by(Document.timestamp.desc()).all()
    all_docs = []

    for doc in documents:
        all_docs.append(document.retrieve_document(doc.id))

    # 2. provide data to template engine
    return render_template('list.html', documents=all_docs, page='listing')
예제 #4
0
def listing(page=0):
    """Create a list of all available documents"""
    # 1. request all documents from DB
    documents = Document.query.order_by(Document.timestamp.desc()).all()
    all_docs = []

    for doc in documents:
        all_docs.append(document.retrieve_document(doc.id))

    # 2. provide data to template engine
    return render_template('list.html',
        documents=all_docs, page='listing'
    )
예제 #5
0
def create():
    """Create a new document (POST) or provide new document form."""
    if request.method == 'POST':
        data = normalize_data(request.form, request.files)

        if data['id'] == 0:
            doc_id = document.create_document(data['title'],
              data['author'], data['doi'], data['tags'])
            document.index_document_by_id(es, doc_id)
        else:
            d = {}
            whitelist = ['id', 'title', 'author', 'doi']
            for key in whitelist:
                if data[key]:
                    d[key] = data[key]
            document.update_document(data['id'], **d)
            doc_id = data['id']

        if data['doc']:
            filename = document.upload_doc(es, data['doc'], doc_id)
        else:
            filename = document.get_filename(doc_id)

        # tags get inherited
        if data['attachment']['doc']:
            at = document.create_attachment(doc_id,
                    data['attachment']['title'],
                    data['attachment']['author'],
                    data['attachment']['doi'],
                    data['tags'])
            document.index_document_by_id(es, at)
            attach = document.upload_doc(es, data['attachment']['doc'], at)

        docu = document.retrieve_document(doc_id)
    else:
        # create empty document
        docu = create_empty_doc()

    op = request.form.get('op')

    if not op or op == u'Attach':
        return render_template('create.html', **docu)
    else:
        return redirect(url_for('doc', doc_id=docu['id']))
예제 #6
0
def create():
    """Create a new document (POST) or provide new document form."""
    if request.method == 'POST':
        data = normalize_data(request.form, request.files)

        if data['id'] == 0:
            doc_id = document.create_document(data['title'], data['author'],
                                              data['doi'], data['tags'])
            document.index_document_by_id(es, doc_id)
        else:
            d = {}
            whitelist = ['id', 'title', 'author', 'doi']
            for key in whitelist:
                if data[key]:
                    d[key] = data[key]
            document.update_document(data['id'], **d)
            doc_id = data['id']

        if data['doc']:
            filename = document.upload_doc(es, data['doc'], doc_id)
        else:
            filename = document.get_filename(doc_id)

        # tags get inherited
        if data['attachment']['doc']:
            at = document.create_attachment(doc_id,
                                            data['attachment']['title'],
                                            data['attachment']['author'],
                                            data['attachment']['doi'],
                                            data['tags'])
            document.index_document_by_id(es, at)
            attach = document.upload_doc(es, data['attachment']['doc'], at)

        docu = document.retrieve_document(doc_id)
    else:
        # create empty document
        docu = create_empty_doc()

    op = request.form.get('op')

    if not op or op == u'Attach':
        return render_template('create.html', **docu)
    else:
        return redirect(url_for('doc', doc_id=docu['id']))