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 view_section(section_id): section = CountrySection.retrieve_by_id(section_id) if not section: return redirect(url_for('country.admin.index')) form = SectionForm(obj=section) country = section.country_key if request.method == 'POST' and 'delete_section' in request.form: section.key.delete() if country: return redirect(url_for('country.admin.pages', key_id=country.id())) return redirect(url_for('country.admin.index')) if form.validate_on_submit(): form.populate_obj(section) section.put() return redirect(url_for('country.admin.view_section', section_id=section_id)) sections = CountrySection.query() if country: country = country.get() return render_template( 'country/admin/section_view.html', form=form, section=section, country=country, sections=sections, cur_section=section_id )
def pages(key_id): country = Country.retrieve_by_id(key_id) sections = CountrySection.query(CountrySection.country_key == country.key) if not country: return redirect(url_for('country.admin.index')) return render_template( 'country/admin/pages.html', country=country, sections=sections )
def get_country(key_id): country = Country.retrieve_by_id(key_id) if not country: return redirect(url_for('country.index')) sections = CountrySection.query(CountrySection.country_key == country.key) return render_template( 'country/get.html', html_class='country_page', country=country, sections=sections, active_country_id=country.key.id() )
def get_page(key_id, section_id, page_id): country = Country.retrieve_by_id(key_id) if not country: return redirect(url_for('country.index')) section = CountrySection.retrieve_by_id(section_id) if not section: return redirect(url_for('country.get', key_id=key_id)) for i, p in enumerate(section.pages): if p.uid == page_id: break else: return redirect(url_for('country.get', key_id=key_id)) sections = CountrySection.query(CountrySection.country_key == country.key) return render_template( 'country/get_page.html', html_class='country_page', country=country, section=section, sections=sections, active_page=page_id, page=section.pages[i] )
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 )