示例#1
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)
示例#2
0
    def decorated_function(*args, **kwargs):
        site_title = kwargs.pop('site_title')

        if site_title == "example":
            return "HelloWorld"

        if site_title in IGNORE_NAMES:
            # faviconやrobots.txtにアクセスされた場合
            app_log(logging.ERROR, "File does not exist :{}".format(site_title))
            return "File does not exist"
        try:
            site = Site.get_title(site_title)
        except IndexError:
            # サイトトップにリダイレクト
            app_log(logging.ERROR, "Site title does not exist :{}".format(site_title))
            return redirect(url_for('site_top.index'))
        return f(site, **kwargs)
示例#3
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)