示例#1
0
def edit_menu(menu_slug):
    menu = Menu.gql("WHERE slug = :1", menu_slug)[0]
    if menu.type == 'page':
        form = MenuForm(name=menu.name,
                        type=menu.type,
                        page_reference=menu.page_reference.key(),
                        internal_link=menu.internal_link,
                        external_url=menu.external_url,
                        ordering=menu.ordering,
                        slug=menu.slug)
    else:
        form = MenuForm(name=menu.name,
                        type=menu.type,
                        internal_link=menu.internal_link,
                        external_url=menu.external_url,
                        ordering=menu.ordering,
                        slug=menu.slug) 
    form.page_reference.choices = controllers.pages_select()
    if form.validate_on_submit():
        menu.name = form.name.data
        menu.type = form.type.data
        menu.page_reference = db.get(form.page_reference.data)
        menu.internal_link = form.internal_link.data
        menu.external_url = form.external_url.data
        menu.ordering = form.ordering.data
        menu.slug = controllers.slugify(menu.name)
        menu.put()
        return redirect(url_for('list_menus'))
    return render_template('cms_edit_menu.html', form=form)
示例#2
0
def change_settings():
    if Setting.all().count() == 0:
        form = SettingsForm()
    else:
        settings = Setting.all().order('-date_created')[0]
        form = SettingsForm(site_title=settings.site_title,
                            site_description=settings.site_description,
                            home_page=settings.home_page.key(),
                            admin_email=settings.admin_email,
                            default_template=settings.default_template.key(),
                            posts_per_page=settings.posts_per_page,
                            disqus_shortname=settings.disqus_shortname,
                            tracking_script = settings.tracking_script)
        form.home_page.choices = controllers.pages_select()
        form.default_template.choices = controllers.templates_select()
    if form.validate_on_submit():
        home_page_slug = form.home_page.data
        settings.site_title = form.site_title.data
        settings.site_description = form.site_description.data
        settings.home_page = db.get(form.home_page.data)
        settings.admin_email = form.admin_email.data
        settings.default_template = db.get(form.default_template.data)
        settings.posts_per_page = form.posts_per_page.data
        settings.disqus_shortname = form.disqus_shortname.data
        settings.tracking_script = form.tracking_script.data
        settings.domain = request.url_root
        settings.put()
        flash('Changes to settings have been saved.','event')
        return redirect(url_for('site_administration'))
    return render_template('cms_settings.html', form=form)
示例#3
0
def new_menu():
    section_name = 'Menus'
    form = MenuForm()
    form.page_reference.choices = controllers.pages_select()
    if form.validate_on_submit():
        if form.type.data == 'page':
            menu = Menu(name = form.name.data,
                        type = form.type.data,
                        page_reference = db.get(form.page_reference.data),
                        ordering = form.ordering.data,
                        slug = controllers.slugify(form.name.data))
        elif form.type.data == 'internal':
            menu = Menu(name = form.name.data,
                        type = form.type.data,
                        internal_link = form.internal_link.data,
                        ordering = form.ordering.data,
                        slug = controllers.slugify(form.name.data))
        elif form.type.data == 'external':
            menu = Menu(name = form.name.data,
                        type = form.type.data,
                        external_url = form.external_url.data,
                        ordering = form.ordering.data,
                        slug = controllers.slugify(form.name.data))
        menu.put()
        flash('New menu item has been saved.','event')
        return redirect(url_for('list_menus'))
    return render_template('cms_new_menu.html', section_name=section_name, form=form)