def location_create(): form = LocationForm(request.form) if not form.validate(): return render_template("location/new.html", form=form) n = Location(form.name.data, form.price.data, current_user.id) db.session().add(n) db.session().commit() return redirect(url_for("location_list"))
def modify(): form = ModifyForm() form2 = LocationForm() u = Accounts.query.filter_by(id=current_user.id).first() u_home = Location.query.filter_by(id=u.loacation_id).first() current_user.address = u_home.address current_user.postal_code = u_home.postal_code current_user.post_office = u_home.post_office if request.method == 'GET': return render_template("registration/modify.html", form=ModifyForm(), form2=LocationForm()) if request.method == 'POST': u = Accounts.query.filter_by(id=current_user.id).first() u_home = Location.query.filter_by(id=u.loacation_id).first() if form.validate_on_submit(): new_name = form.name.data new_addr = form2.address.data new_postalC = form2.postal_code.data new_postF = form2.post_office.data new_email = form.email.data if new_name != u.name: u.name = new_name if new_addr != u_home.address: u_home.address = new_addr if new_postalC != u_home.address: u_home.postal_code = new_postalC if new_postF != u_home.post_office: u_home.post_office = new_postF if new_email != u.email: u.email = new_email db.session.commit() flash('The update was successful!') return redirect(url_for('index')) return render_template("registration/modify.html", form=form, form2=form2)
def get_location(): form = LocationForm() if request.method == 'GET': return render_template('/registration/register.html',form = RegistrationForm()) if request.method == 'POST': if form.validate_on_submit(): u = Accounts(name=form.name.data,email=form.email.data,address = form.address.data,postal_code = form.postal_code.data, post_office = form.post_office.data, password=form.password.data) db.session.add(u) db.session.commit() flash('Rekisteröityminen onnistui, voit kirjautua palveluun!') return redirect(url_for('login')) return render_template('/registration/register.html',form = form)
def location_edit(locId): locUpdate = Location.query.get(locId) form = LocationForm(request.form) form.name.data = locUpdate.name form.price.data = locUpdate.price if request.method == "GET": return render_template("location/edit.html", form=form, location=locUpdate) if not form.validate(): return render_template("location/edit.html", form=form) form = LocationForm(request.form) locUpdate.name = form.name.data locUpdate.price = form.price.data db.session().commit() return redirect(url_for("location_list"))
def location_list(): return render_template("location/list.html", form=LocationForm(), loc=Location.query.all())
def location_form(): return render_template("location/new.html", form=LocationForm())