Esempio n. 1
0
def edit(note_url):
    note_uid = unquote_plus(note_url)
    if request.method == 'GET':
        note = get_note(note_uid)
        return render_template('edit.html',
                               note=note,
                               highlight_css=c.highlight_css)
    else:
        new_text = request.form.get('note_text')
        old_note = get_note(note_uid)
        try:
            new_note = Note(new_text)
        except (ValueError, AttributeError) as e:
            flash(str(e))
            old_note.text = new_text
            return render_template('edit.html',
                                   note=old_note,
                                   highlight_css=c.highlight_css)
        if new_note.uid != old_note.uid and note_exists(new_note.uid):
            flash('Modified note has same date and title as another note. '
                  'File was not created.')
            return render_template('edit.html',
                                   note=new_note,
                                   highlight_css=c.highlight_css)
        else:
            old_note.remove_file()
            new_note.create_file()
            return redirect(url_for('render', note_url=new_note.url))
Esempio n. 2
0
def save(note_url):
    note_uid = unquote_plus(note_url)
    new_text = request.form.get('note_text')
    old_note = get_note(note_uid)
    try:
        new_note = Note(new_text)
    except (ValueError, AttributeError) as e:
        print(str(e))
        return jsonify({
            'message': f'Not saved. {str(e)}',
            'success': False,
            'data': ''
        })
    if new_note.uid != old_note.uid and note_exists(new_note.uid):
        message = 'Not saved. Modified note has same date and title as ' \
                  'another note. File was not created.'
        return jsonify({'message': message, 'success': False, 'data': ''})
    else:
        old_note.remove_file()
        new_note.create_file()
        return jsonify({
            'message': 'File saved.',
            'success': True,
            'old_url': old_note.url,
            'new_url': new_note.url,
            'data': render_markdown(new_text)
        })
Esempio n. 3
0
def render(note_uid):
    note = get_note(note_uid)
    if not note:
        flash(f'Note {note_uid} not found.')
        return redirect(url_for('index'))
    return render_template('note.html',
                           note=note,
                           text=render_markdown(note.text))
Esempio n. 4
0
def pdf(note_uid):
    note = get_note(note_uid)
    make_pdf(note)
    with open(note.pdf_fname, mode='rb') as f:
        response = make_response(f.read())
        response.headers['Content-Type'] = 'application/pdf'
        cd = f'inline; filename={note_uid}.pdf'
        response.headers['Content-Disposition'] = cd
    os.remove(note.pdf_fname)
    return response
Esempio n. 5
0
def render(note_url):
    note_uid = unquote_plus(note_url)
    note = get_note(note_uid)
    if not note and note_uid not in FNAME_WHITELIST:
        flash(f'Note {note_uid} not found.')
        return redirect(url_for('index'))
    return render_template('note.html',
                           note=note,
                           highlight_css=c.highlight_css,
                           text=render_markdown(note.text))
Esempio n. 6
0
def archive(note_uid):
    note = get_note(note_uid)
    if note:
        note.archive()
    return redirect(url_for('index'))
Esempio n. 7
0
def delete(note_uid):
    note = get_note(note_uid)
    if note:
        note.trash()
    return redirect(url_for('index'))
Esempio n. 8
0
def archive(note_url):
    note_uid = unquote_plus(note_url)
    note = get_note(note_uid)
    if note:
        note.archive()
    return redirect(url_for('index'))
Esempio n. 9
0
def delete(note_url):
    note_uid = unquote_plus(note_url)
    note = get_note(note_uid)
    if note:
        note.trash()
    return redirect(url_for('index'))