Пример #1
0
def blog_list_preview(lang_override):
    current_lang, lang_fallback = langService.get_user_settings(request, lang_override)
    db_data = BlogPostHeader.query.filter().order_by(BlogPostHeader.created_at.desc())
    base_url = "{0}/{1}".format(request.url_root[:request.url_root.find("/", 8)], current_lang)
    posts = [BlogPost.populate_from_db(d, lang_fallback, base_url) for d in db_data]
    return render_template("admin/blog/list_preview.html", v={
        "posts": posts
    })
Пример #2
0
def blog_post_preview(lang_override, post_id):
    current_lang, lang_fallback = langService.get_user_settings(request, lang_override)
    base_url = "{0}/{1}".format(lang_override, request.url_root[:request.url_root.find("/", 8)])
    db_data = BlogPostHeader.query.get(post_id)
    post = BlogPost.populate_from_db(db_data, lang_fallback, base_url)
    return render_template("admin/blog/preview.html", v={
        "post": post
    })
Пример #3
0
def detail(lang_override, post_url):
    current_lang, lang_fallback = langService.get_user_settings(request, lang_override)
    base_url = "{0}/{1}".format(request.url_root[:request.url_root.find("/", 8)], current_lang)
    db_data = BlogPostHeader.query.filter(BlogPostHeader.url == post_url).one()
    post = BlogPost.populate_from_db(db_data, lang_fallback, base_url)

    db_data = BlogPostHeader.query.filter(BlogPostHeader.visible).order_by(BlogPostHeader.created_at.desc()).limit(2)
    recent_posts = [BlogPost.populate_from_db(d, lang_fallback, base_url) for d in db_data]
    links = {lang: url_for(".detail", lang_override=lang, post_url=post_url) for lang in cfg.SUPPORTED_LANGS}
    html = render_template("front/blogpost.html", v={
        "lang_dic": {u"ru": u"Русский", u"en": u"English", u"sv": u"Svenska"},
        "links": links,
        "current_lang": current_lang,
        "meta_language": Language.meta_lang[current_lang],
        "post": post,
        "recent_posts": recent_posts
    })

    response = current_app.make_response(html)
    response.set_cookie('lang', value=current_lang)
    return response
Пример #4
0
def index():
    current_lang, lang_fallback = langService.get_user_settings(request)
    db_data = BlogPostHeader.query.filter(BlogPostHeader.visible).order_by(BlogPostHeader.published_at.desc()).limit(10)
    base_url = "{0}/{1}".format(request.url_root[:request.url_root.find("/", 8)], current_lang)
    posts = [BlogPost.populate_from_db(d, lang_fallback, base_url) for d in db_data]
    recent_posts = posts[:2]

    return render_template("front/index.html", v={
        "meta_language": Language.meta_lang[current_lang],
        "current_lang": current_lang,
        "posts": posts,
        "recent_posts": recent_posts
    })
Пример #5
0
def contact():
    current_lang, lang_fallback = langService.get_user_settings(request)
    db_data = BlogPostHeader.query.filter(BlogPostHeader.visible).order_by(BlogPostHeader.created_at.desc()).limit(2)
    base_url = "{0}/{1}".format(request.url_root[:request.url_root.find("/", 8)], current_lang)
    posts = [BlogPost.populate_from_db(d, lang_fallback, base_url) for d in db_data]
    if current_lang == "ru":
        tpl = "front/contact.ru.html"
    else:
        tpl = "front/contact.en.html"
    return render_template(tpl, v={
        "current_lang": current_lang,
        "meta_language": Language.meta_lang[current_lang],
        "recent_posts": posts
    })
Пример #6
0
def blog_post_update(post_id):
    if request.method == "POST":
        f = BlogPostForm()
        post = BlogPost.populate_from_ui(f)
        post.update()
        return redirect(url_for('.blog_post_list'))
    else:
        post = BlogPost.populate_from_db(BlogPostHeader.query.get(post_id))
        title = u"Update {0}".format(post.name)
        f = BlogPostForm(obj=post)

        return render_template("admin/blog/detail.html", v={
            "title": title,
            "f": f,
            "action": ""
        })