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)
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)
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)
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")
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)
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)
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")