def edit_page(section_id, page_uid): section = CountrySection.retrieve_by_id(section_id) if not section: return redirect(url_for('country.admin.index')) for i, p in enumerate(section.pages): if page_uid == p.uid: break else: return redirect(url_for('country.admin.view_section', section_id=section_id)) if request.method == 'POST' and 'delete_page' in request.form: del section.pages[i] section.put() return redirect(url_for('country.admin.view_section', section_id=section_id)) page = section.pages[i] form = SimplePageForm(obj=page) if form.validate_on_submit(): form.populate_obj(section.pages[i]) section.put() return redirect(url_for('country.admin.view_section', section_id=section_id)) sections = CountrySection.query() country = section.country_key if country: country=country.get() return render_template( 'country/admin/edit_page.html', form=form, country=country, section=section, sections=sections, cur_section=section_id )
def add_page(section_id): section = CountrySection.retrieve_by_id(section_id) if not section: return redirect(url_for('country.admin.index')) country = section.country_key if country: country = country.get() form = SimplePageForm() if form.validate_on_submit(): page_ = SimplePage() page_.uid = uuid() form.populate_obj(page_) section.pages.append(page_) section.put() return redirect(url_for('country.admin.view_section', section_id=section_id)) sections = CountrySection.query() return render_template( 'country/admin/add_page.html', form=form, country=country, sections=sections, cur_section=section_id )