Example #1
0
def index(site, page_id):
    # パラメータチェックとメインコンテンツ生成
    page_id = int(page_id)
    try:
        contents = Page.get_by_site(page_id, site.id)
    except Page.DoesNotExist:
        app_log(logging.ERROR, "Page does not exist site_id:{} page_id:{}".format(site.id, page_id))
        return error_page(site, ErrorPageCategory.DoesNotExist)

    # ページが有効期間外ならエラー
    if not contents.is_enable():
        app_log(logging.ERROR, "Page is not open site_id:{} page_id:{}".format(site.id, page_id))
        return error_page(site, ErrorPageCategory.NotOpen)

    # 追加用ページ
    extend_page = contents.get_history_from_myself()
    if contents and contents.prev_page:
        ignore_ids = [page_id, contents.prev_page.id]
    else:
        ignore_ids = [page_id]

    try:
        svm = generate_index_contents(site, extend_page=extend_page, ignore_ids=ignore_ids)
    except SiteEmptyError:
        app_log(logging.WARNING, "site is empty site_id:{} page_id:{}".format(site.id, page_id))
        return error_page(site, ErrorPageCategory.SiteIsEmpty)

    # pvを記録
    if random.randint(0, 20) == 1:
        contents.count_up(20)

    return render_template('dat/page.html',
                           contents=contents,
                           site=site,
                           svm=svm)
Example #2
0
def index(site):
    """
    各サイト毎のトップページ
    """
    try:
        svm = generate_index_contents(site)
    except SiteEmptyError:
        app_log(logging.WARNING, "site is empty site_id:{}".format(site.id))
        return error_page(site, ErrorPageCategory.SiteIsEmpty)

    return render_template('root/index.html',
                           svm=svm,
                           site=site)