Beispiel #1
0
def show_post(post_id):
    post = PostFacade.get(id=ObjectId(post_id)) if post_id else None

    if not post:
        return 'post not found', 404

    j_template = env.get_template(post.template)

    return j_template.render(db=get_theme_db(), post=post, page=post)
Beispiel #2
0
def show_post(post_id):
    post = PostFacade.get(id=ObjectId(post_id)) if post_id else None
    templates = get_theme_templates()
    assets = AssetFacade.get_all()
    theme_db = get_theme_db()
    kinds = theme_db['post_kinds'] if 'post_kinds' in theme_db else []

    if request.method == 'POST':
        if request.form.get('delete'):
            post.delete()
            return redirect('/admin/posts')

        if request.form.get('submit'):
            name = request.form.get('post-name')
            content = request.form.get('post-content')
            template = request.form.get('post-template')
            post_kind = request.form.get('post-kind')
            is_published = request.form.get('post-is_published') is not None
            new_asset_files = request.files.getlist('new-assets')
            new_assets = []

            post_kind = None if not post_kind else post_kind

            for new_asset_file in new_asset_files:
                filename = upload_file(new_asset_file)
                asset = AssetFacade.create(name=new_asset_file.filename,
                                           filename=filename)
                new_assets.append(asset)

            if post:
                new_assets = post.assets + new_assets
            else:
                pass

            if not post:
                post = PostFacade.create(name=name,
                                         content=content,
                                         template=template,
                                         kind=post_kind,
                                         is_published=is_published,
                                         created_at=datetime.datetime.now(),
                                         assets=new_assets)
                return redirect('/admin/post/{}'.format(str(post.id)))
            else:
                post.update(name=name,
                            content=content,
                            template=template,
                            kind=post_kind,
                            is_published=is_published,
                            assets=new_assets)
                post = PostFacade.get(id=ObjectId(post_id))

    return render_template('admin/post.html',
                           templates=templates,
                           assets=assets,
                           kinds=kinds,
                           post=post)
Beispiel #3
0
def show(page_name):
    page = PageFacade.get(name=page_name) if page_name\
        else PageFacade.get(is_startpage=True)

    if not page:
        return 'page not found', 404

    j_template = env.get_template(page.template)

    return j_template.render(db=get_theme_db(), page=page)
Beispiel #4
0
def show_theme_db():
    db = get_theme_db()

    if request.method == 'POST':
        if request.form.get('submit'):
            for k, v in request.form.items():
                if k == 'submit':
                    continue

                db[k] = v

            set_theme_db(db)

    return render_template('admin/theme_db.html', db=db)