示例#1
0
文件: notes.py 项目: 5aket/cpfthw
def create():
    form = NotesForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            note = Notes(form.title.data, form.author.data,
                         form.description.data, form.subject.data)
            db.session.add(note)
            db.session.commit()
            flash('Note saved on database.')
            return redirect(url_for('list_notes'))
    return render_template('note.html', form=form)
示例#2
0
def edit_note(id):
    note = Note.query.filter_by(id=int(id)).first()
    form = NotesForm()
    if form.validate_on_submit():

        note.title = form.title.data
        note.text = form.text.data
        db.session.commit()

        flash('You have successfully edited the note.','success')
        return redirect(url_for('notes.show_notes'))
    elif request.method == 'GET':
        form.title.data = note.title
        form.text.data = note.text

    return render_template('notes_edit.html', form=form, note=note)
示例#3
0
def edit(note_id):
    note = Notes.query.get_or_404(note_id)
    form = NotesForm(obj=note)
    if request.method == 'POST':
        print request.form
        if form.validate_on_submit():
            print request.form['title']
            note.title = request.form['title']
            note.author = request.form['author']
            note.description = request.form['description']
            note.subject = request.form['subject']
            db.session.add(note)
            db.session.commit()
        return redirect(url_for('list_notes'))
    else:
        return render_template('note.html', form=form)
示例#4
0
def add_note():
    form = NotesForm()

    try:
        if form.validate_on_submit():
            if form.submit.data:
                insert_record("Notes",
                              title=form.data.get("title"),
                              description=form.data.get("description"))
            return redirect(url_for("notes_bp.list_notes"))
    except Exception as err:
        form.title.errors = [err]
    return render_template("note.html",
                           title="Notes | New",
                           form=form,
                           action="New")
示例#5
0
文件: notes.py 项目: 5aket/cpfthw
def edit(note_id):
    note = Notes.query.get_or_404(note_id)
    form = NotesForm(obj=note)
    if request.method == 'POST':
        print request.form
        if form.validate_on_submit():
            print request.form['title']
            note.title = request.form['title']
            note.author = request.form['author']
            note.description = request.form['description']
            note.subject = request.form['subject']
            db.session.add(note)
            db.session.commit()
        return redirect(url_for('list_notes'))
    else:
        return render_template('note.html', form=form)
示例#6
0
文件: views.py 项目: raikerz/Repos
def eng_lives(id):
    if current_user.is_admin == True or current_user.is_eng == True:

        lives = Lives.query.get_or_404(id)
        form = NotesForm(obj=lives)
        if form.validate_on_submit():
            lives.note = form.note.data
            db.session.commit()
            flash('You have successfully edited the live note.')

            # redirect to the reports page
            return redirect(url_for('its.list_lives'))

        form.note.data = lives.note
        return render_template('its/lives/eng.html', action="Eng Edit", form=form,
                               lives=lives, title="Eng Edit Lives")
    else:
        abort(403)
示例#7
0
def edit_note(note_id):
    form = NotesForm()
    note = show_record("Notes", note_id)

    if request.method == "GET":
        form.title.data = note[1]
        form.description.data = note[2]

    try:
        if form.validate_on_submit():
            if form.submit.data:
                update_record("Notes",
                              id=note[0],
                              title=form.data.get("title"),
                              description=form.data.get("description"))
            return redirect(url_for("notes_bp.list_notes"))
    except Exception as err:
        form.title.errors = [err]
    return render_template("note.html",
                           title="Notes | Edit",
                           form=form,
                           action="Edit")