Пример #1
0
def index():
    form = AddNoteForm()
    user = get_current_user()
    if form.validate_on_submit():
        if form.note.data:
            # Create a new note in db
            note = Note.create(user=user.id, content=form.note.data, timestamp=datetime.now())

            # Render a single panel with new note and return the HTML
            rendered = render_template('note.html', note=note)
            return jsonify({'note': rendered, 'success': True})
        # If there no content in form, indicate a failure
        return jsonify({'success': False})
    notes = Note.user_notes(user)
    return render_template('index.html',
                           user=user,
                           title='%s notes' % user.username,
                           notes=notes,
                           form=form)