Exemplo n.º 1
0
def doc_view(doc_id):
    """
    View a document. This renders a "definitive" HTML version of the
    document, and offers the possibility to download it, in pdf form,
    or maybe others.
    """
    doc = models.get_document(doc_id)
    return render_template('doc.view.html', rendered_md=doc.render())
Exemplo n.º 2
0
def doc_edit(doc_id):
    "Main page to edit a document"
    if(doc_id not in app.deltas):
        app.deltas[doc_id] = []

    if('client_id' not in session):
        session['client_id'] = models.gen_random_str(32)
        app.client_states.update({
            session['client_id']: {
                doc_id: len(app.deltas[doc_id]) - 1
            }
        })
    if(session['client_id'] not in app.client_states):
        app.client_states.update({session['client_id']:{}})
    if(doc_id not in app.client_states[session['client_id']]):
        app.client_states[session['client_id']][doc_id] = len(app.deltas[doc_id])
    doc = models.get_document(doc_id)
    return render_template('doc.edit.html', doc=doc)
Exemplo n.º 3
0
def doc_update(doc_id):
    "JSON endpoint for document updates. I still have to define protocol."
    doc = models.get_document(doc_id)
    if('client_id' not in session):
        flash("an error occured. Please contact <*****@*****.**>, with all the information you can provide. Please do not forget to include the exact time at which this occured.")
        logger.error("on /update, we don't have any client_id information. document: {doc_id}".format(doc_id=doc_id))
        return abort()
    deltas_to_send = app.deltas[doc_id][
        app.client_states[session['client_id']][doc_id]:
    ]
    app.client_states[session['client_id']][doc_id] = len(app.deltas[doc_id])   
    if(request.json):
        doc.update(request.json['data'])

    return json.dumps({
            "events": deltas_to_send,
            "render":doc.render()
            })