def edit(id): """Edit table shape with id""" table = models.TableShape.query.get(id) if not table: return abort(HTTPStatus.NOT_FOUND) if request.method == "POST": form = forms.TableShapeForm(request.form, instance=table) if not form.validate(): return abort(HTTPStatus.BAD_REQUEST) form.save() return redirect(url_for("table_shape.list")) form = forms.TableShapeForm(instance=table) return render_template("restaurants/table_shapes/create_edit.html", form=form)
def edit(id): """ Edit table shape with id @todo #162:30min Implement edit() method of TableShape model and update template. Use TableShapeForm for that, see how in works in create function. Check and update html template if it's needed. """ if request.method == "POST": flash("Edit not yet implemented") form = forms.TableShapeForm() return render_template( "restaurants/table_shapes/create_edit.html", form=form)
def create(): """ Create new table shape""" form = forms.TableShapeForm(request.form) if request.method == "POST" and form.validate(): """ @todo #162:30min This form currenly cannot save pictures. Need have a look how WTF form processes files. Implement generic solution to use it everywhere when it's needed. """ """ Uncomment after correction form.save() """ return redirect(url_for("table_shape.list")) return render_template("restaurants/table_shapes/create_edit.html", form=form)
def create(): """ Create new table shape""" form = forms.TableShapeForm(request.form) if request.method == "POST" and form.validate(): """ @todo #162:30min Initialize CSRF token protection for app and add token to this template. Implementation detail you can find by the following page: https://flask-wtf.readthedocs.io/en/stable/csrf.html @todo #162:30min This form currenly cannot save pictures. Need have a look how WTF form processes files. Implement generic solution to use it everywhere when it's needed. """ form.save() return redirect(url_for("table_shape.list")) return render_template( "restaurants/table_shapes/create_edit.html", form=form)