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 add_note(): form = NotesForm() if form.validate_on_submit(): # create new note with the form data new_note = Note(title=form.title.data, text=form.text.data, user_id=current_user.id) # add the new note to the database db.session.add(new_note) db.session.commit() flash('You have successfully added a note.','success') return redirect(url_for('notes.show_notes')) return render_template("notes_add.html", title='Add Note', 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 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")
def process(request): """Takes form submission and runs bots on uploaded form.""" if request.method != 'POST': raise Http404 else: record_log_form = RecordLoadLogForm(request.POST,request.FILES) bot_name,bot = request.POST['bot'],None for active_bot in active_bots: if active_bot.__name__ == bot_name: if request.POST.has_key('databases'): bot = active_bot(marc_file=request.FILES['original_file'], type_of=request.POST['databases']) else: bot = active_bot(marc_file=request.FILES['original_file']) if not bot: raise Http404 bot.load() if not record_log_form.is_valid(): logging.error("Errors = %s" % record_log_form.errors) record_log = record_log_form.save() record_log.process_id = bot_name record_log.save() mod_filename = '%s-%s.mrc' % (datetime.datetime.today().strftime("%Y-%m-%d"), record_log.process_id.replace('Bot','')) #record_log.modified_file_content = File(mod_filename) #record_log.modified_file_content.write(bot.to_text()) record_log.modified_file.save(mod_filename,ContentFile(bot.to_text())) request.session['log_pk'] = record_log.pk note_form = NotesForm(request.POST) note_form.record_load_log_id = record_log.pk if note_form.is_valid(): note_form.save() else: logging.error("Note form is not valid %s" % note_form.errors) return HttpResponseRedirect("/marc/update")