Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def edit_post(slug):
    post = Post.gql("WHERE slug = :1", slug)[0]
    images = Image.all()
    form = PostForm(title=post.title, category=post.category.key(),
                    tags=','.join(post.tags),content=post.content,
                    excerpt=post.excerpt,status=post.status) 
    form.category.choices = controllers.categories_select()
    if form.validate_on_submit():
        excerpt = form.excerpt.data
        if '<div>' in excerpt:
            if '<div><br></div>' not in excerpt[-100:]:
                excerpt = excerpt+'<div><br></div>'
        else:
            excerpt = '<div>'+excerpt+'</div>'+'<div><br></div>'
        post.title = form.title.data
        post.category = db.get(form.category.data)
        post.tags = [x.strip() for x in form.tags.data.split(',')]
        post.author = db.get(current_user.id)
        post.slug = controllers.slugify(form.title.data)
        post.content = form.content.data
        post.excerpt = excerpt
        post.status = form.status.data
        post.date_modified = datetime.now()
        post.put()
        flash('The post has been updated.','event')
        return redirect(url_for('view_posts'))
    return render_template('cms_edit_post.html', form=form, post=post, images=images)
Ejemplo n.º 4
0
def edit_category():
    category = Category.gql("WHERE slug = :1", request.form['slug'])[0]
    if request.method == 'POST':
        category.name = request.form['name']
        category.slug = controllers.slugify(request.form['name'])
        category.put()
        return redirect(url_for('view_categories'))
Ejemplo n.º 5
0
def new_category():
    if request.method == 'POST':
        category = Category(name = request.form['name'],
                            slug = controllers.slugify(request.form['name']))
        category.put()
        flash("The category %s was added." % request.form['name'],'event')
        return redirect(url_for('view_categories'))
Ejemplo n.º 6
0
def new_template():
    form = TemplateForm()
    if form.validate_on_submit():
        try:
            template_check = Template.gql('WHERE template_name = :1', form.template_name.data)[0]
            flash('A template with this name already exists.','event')
        except IndexError:
            template = Template(template_name=form.template_name.data,
                                template_slug=controllers.slugify(form.template_name.data),
                                template_css=form.template_css.data)
            template.put()
            flash('New template has been saved.','event')
            return redirect(url_for('list_templates'))
    return render_template('cms_new_template.html', form=form)
Ejemplo n.º 7
0
def new_page():
    form = PageForm()
    form.template.choices = controllers.templates_select()
    images = Image.all()
    if form.validate_on_submit():
        page = Page(title = form.title.data,
                    slug = controllers.slugify(form.title.data),
                    template = db.get(form.template.data),
                    content = form.content.data,
                    author = db.get(current_user.id),
                    date_created = datetime.now())
        page.put()
        flash('The page has been saved.','event')
        return redirect(url_for('list_pages'))
    return render_template('cms_new_page.html', form=form, images=images)
Ejemplo n.º 8
0
def edit_page(slug):
    page = Page.gql("WHERE slug = :1", slug)[0]
    images = Image.all()
    form = PageForm(title=page.title, template=page.template.key(),
                    content=page.content)
    form.template.choices = controllers.templates_select()
    if form.validate_on_submit():
        page.title = form.title.data
        page.author = db.get(current_user.id)
        page.slug = controllers.slugify(form.title.data)
        page.content = form.content.data
        page.date_modified = datetime.now()
        page.template = db.get(form.template.data)
        page.put()
        flash('The page has been updated.','event')
        return redirect(url_for('list_pages'))
    return render_template('cms_edit_page.html', form=form, images=images)
Ejemplo n.º 9
0
def new_post():
    form = PostForm()
    images = Image.all()
    form.category.choices = controllers.categories_select()
    if form.validate_on_submit():
        excerpt = form.excerpt.data
        if '<div>' in excerpt:
            if '<div><br></div>' not in excerpt[-100:]:
                excerpt = excerpt+'<div><br></div>'
        else:
            excerpt = '<div>'+excerpt+'</div>'+'<div><br></div>'
        post = Post(title = form.title.data,
                    category = db.get(form.category.data),
                    tags = [x.strip() for x in form.tags.data.split(',')],
                    slug = controllers.slugify(form.title.data),
                    content = form.content.data,
                    excerpt = excerpt,
                    status = form.status.data,
                    author = db.get(current_user.id),
                    date_created = datetime.now())
        post.put()
        flash('The new post has been saved.','event')
        return redirect(url_for('view_posts'))
    return render_template('cms_new_post.html', form=form, images=images)
Ejemplo n.º 10
0
    def test_support_func_slugify(self):
        res1 = controllers.slugify('title test')
        res2 = controllers.slugify('4title4 test!!')

        self.assertEqual(res1, 'title-test')
        self.assertEqual(res2, '4title4-test--')
Ejemplo n.º 11
0
import unittest
import controllers

from app import app

client = app.test_client()


class Test(unittest.TestCase):
    def setUp(self):
        pass

    @unittest.skip('skip')
    def test_main(self):
        pass

    def test_support_func_slugify(self):
        res1 = controllers.slugify('title test')
        res2 = controllers.slugify('4title4 test!!')

        self.assertEqual(res1, 'title-test')
        self.assertEqual(res2, '4title4-test--')


if __name__ == '__main__':
    print(controllers.slugify(''))
    unittest.main()