def add_requirement(): form = RequirementsValidForm() if request.method == 'GET': return render_template('requirement/add_requirement.html', form=form, form_name="add requirement form") else: if form.validate(): new_req = ormRequirement( requirement_name=form.requirement_name.data, requirement_point=form.requirement_point.data) try: db.session.add(new_req) db.session.commit() return redirect('/requirement') except: form.requirement_name.errors = [ 'Requirement with this name already exists!' ] return render_template('requirement/add_requirement.html', form=form, form_name="add requirement form") else: return render_template('requirement/add_requirement.html', form=form, form_name="add requirement form")
def edit_requirement(current_requirement): requirements = db.session.query(ormRequirement).filter( ormRequirement.requirement_name == current_requirement).one() form = RequirementsValidForm() if request.method == 'GET': form.requirement_name.data = requirements.requirement_name form.requirement_point.data = requirements.requirement_point return render_template('requirement/requirement_edit_page.html', form=form, form_name="Edit requirement") else: if form.validate(): requirements.requirement_name = form.requirement_name.data requirements.requirement_point = form.requirement_point.data try: db.session.commit() return redirect('/requirement') except: form.requirement_name.errors = [ 'Requirement with this name already exists!' ] return render_template( 'requirement/requirement_edit_page.html', form=form, form_name="Edit requirement") else: return render_template('requirement/requirement_edit_page.html', form=form, form_name="Edit requirement")