def edit_study(study_id): form = AddStudyForm() study = models.Study.query.get(study_id) studyfields = models.StudyField.query.all() if form.validate_on_submit(): name = form.name.data url = form.url.data studyfield_id = form.studyfield_id.data models.Study.update(study, name, url, study.university_id, studyfield_id) flash("The study %r has been updated!" % str(name), "success") return redirect(url_for('edit_university', university_id=study.university_id)) return render_template("edit_study.html", study=study, page_id="admin", studyfields=studyfields, title="Edit study", form=form, u=g.user)
def add_study(university_id): form = AddStudyForm() studyfields = models.StudyField.query.all() if form.validate_on_submit(): name = form.name.data url = form.url.data studyfield_id = form.studyfield_id.data studyfield = models.StudyField.query.get(studyfield_id) university = models.University.query.get(university_id) study = models.Study(name=name, url=url, university=university, studyfield=studyfield) db.session.add(study) db.session.commit() flash("The study %r has been created!" % str(name), "success") return redirect(url_for('edit_university', university_id=university_id)) return render_template("add_study.html", page_id="admin", title="Add study", studyfields=studyfields, form=form, u=g.user)