def index(): form = ExcursionTypeForm() if request.method == 'POST' and form.validate_on_submit(): excursion = ExcursionType() form.populate_obj(excursion) excursion.put() return redirect(url_for('excursion.admin.index')) excursions = ExcursionType.query().order(-ExcursionType.order_id) return render_template( 'excursion/admin/index.html', form=form, excursions=excursions )
def edit(key_id): excursion_type = ExcursionType.retrieve_by_id(key_id) if not excursion_type: return redirect(url_for('excursion.admin.index')) add_ex_form = ExcursionForm() form = ExcursionTypeForm(obj=excursion_type) if request.method == 'POST' \ and 'ex_form' in request.form: if add_ex_form.validate_on_submit(): excursion = Excursion() add_ex_form.populate_obj(excursion) excursion.uid = str(uuid.uuid1()).replace('-', '') excursion_type.excursions.append(excursion) excursion_type.put() return redirect(url_for('excursion.admin.edit', key_id=excursion_type.key.id())) return render_template( 'excursion/admin/edit.html', excursion_type=excursion_type, form=form, ex_form=add_ex_form ) if request.method == 'POST' \ and 'ex_form' not in request.form \ and form.validate_on_submit(): form.populate_obj(excursion_type) excursion_type.put() return redirect(url_for('excursion.admin.index')) return render_template( 'excursion/admin/edit.html', excursion_type=excursion_type, form=form, ex_form=add_ex_form )