Пример #1
0
def index():
    return render_template("index.html",
                           articles=Article.query.order_by(
                               db.desc(Article.date_time_)).all(),
                           title=config.WEBSITE_NAME,
                           navbar=get_navbar("Home"),
                           sidebar=gen_sidebar())
Пример #2
0
def archives_get():
    time_and_posts = []
    for (year, month), group in archives_data():
        articles = list(group)
        count = len(articles)
        time_and_posts.append(((year, month), count, articles))
    return render_template("archives.html",
                           title="Archives" + " - " + config.WEBSITE_NAME,
                           time_and_posts=time_and_posts,
                           navbar=get_navbar("Archives"),
                           sidebar=gen_sidebar())
Пример #3
0
def categories_get():
    category_and_articles = []
    for category in Category.query.all():
        articles = category.articles
        count = len(articles)
        if count > 0:
            category_and_articles.append((category, count, articles))
    return render_template("categories.html",
                           category_and_articles=category_and_articles,
                           title="Categories" + " - " + config.WEBSITE_NAME,
                           navbar=get_navbar("Categories"),
                           sidebar=gen_sidebar())
Пример #4
0
def tags_get():
    tags = Tag.query.all()
    tag_and_articles = []
    for tag in tags:
        articles = tag.articles
        count = len(articles)
        if count > 0:
            tag_and_articles.append((tag, count, articles))
    return render_template("tags.html",
                           tag_and_articles=tag_and_articles,
                           title="Tags" + " - " + config.WEBSITE_NAME,
                           navbar=get_navbar("Tags"),
                           sidebar=gen_sidebar())
Пример #5
0
def archives_year_month_get(year, month):
    articles = Article.query.filter(
        Article.date_time_.between(
            datetime.datetime(year, month, 1, 0, 0, 0),
            datetime.datetime(year, month + 1, 1, 0, 0, 0)
            if month < 12 else datetime.datetime(year + 1, 1, 1, 0, 0, 0) -
            datetime.timedelta(days=1))).all()
    count = len(articles)
    monthname = datetime.datetime(year, month, 1, 0, 0, 0).strftime("%B")
    return render_template("archives.html",
                           title=monthname + ", " + str(year) + " - " +
                           config.WEBSITE_NAME,
                           time_and_posts=[((year, month), count, articles)],
                           navbar=get_navbar("Archives"),
                           sidebar=gen_sidebar())
Пример #6
0
def categories_category_name(category_name):
    category = Category.query.filter_by(name_=category_name).first()
    category_and_articles = []
    if category is None:
        return render_template("not_found.html", text="")
    else:
        articles = category.articles
        count = len(articles)
        if count > 0:
            category_and_articles.append((category, count, articles))
        return render_template("categories.html",
                               category_and_articles=category_and_articles,
                               title="Category: " + category_name + " - " +
                               config.WEBSITE_NAME,
                               navbar=get_navbar("Categories"),
                               sidebar=gen_sidebar())
Пример #7
0
def tags_tag_name(tag_name):
    tag = Tag.query.filter_by(name_=tag_name).first()
    tag_and_articles = []
    if tag is None:
        return redirect("/", code=404)
    else:
        articles = tag.articles
        count = len(articles)
        if count > 0:
            tag_and_articles.append((tag, count, articles))
        return render_template("tags.html",
                               tag_and_articles=tag_and_articles,
                               title="Tag: " + tag_name + " - " +
                               config.WEBSITE_NAME,
                               navbar=get_navbar("Tags"),
                               sidebar=gen_sidebar())
Пример #8
0
def article_year_month_title(year, month, title):
    article = Article.query.filter_by(title_=title).first()
    if article is not None:
        date = article.date_time_
        if date.year == year and date.month == month:
            return render_template(
                "article.html",
                title=title + " - " + config.WEBSITE_NAME,
                article=article,
                html_content=Markup(article.html_content_),
                page_id=article.page_id_,
                user=None if current_user.is_anonymous else current_user,
                comment=True,
                navbar=get_navbar(None),
                sidebar=gen_sidebar())
    else:
        return redirect("/", code=404)
Пример #9
0
def login():
    return render_template("user/login.html", navbar=get_navbar("Login"))
Пример #10
0
def register():
    return render_template("user/register.html", navbar=get_navbar("Register"))
Пример #11
0
def logout():
    return render_template("user/logout.html",
                           current_user=current_user,
                           navbar=get_navbar("Logout"))