Пример #1
0
def delete():
    article_id = request.args.get("id", None)
    current_page = request.args.get("page", None)
    uri = request.url_rule
    logging.info("uri: {}".format(uri))

    if article_id is None or current_page is None:
        return redirect(url_for("admin.manage"))

    # delete the article by id
    Article(id=article_id).delete()
    current_page = int(current_page)

    # check data of current page
    articles = Article.get_articles_of_current_page(current_page=current_page, article_status=STATUS_PUBLISH)
    if not articles:
        current_page = current_page - 1 if current_page - 1 else current_page
    url = "{}?page={}".format(str(uri)[:-7], current_page)
    logging.info("url: {}".format(url))
    return redirect(url)
Пример #2
0
def list_articles():
    current_page = request.args.get("page", 1)
    label_id = request.args.get("labelid", None)

    try:
        current_page = int(current_page)
    except:
        abort(404)

    if current_page < 1:
        abort(404)

    if label_id is not None:
        try:
            label_id = int(label_id)
        except:
            abort(404)

    articles = Article.get_articles_of_current_page(current_page, label_id=label_id, article_status=STATUS_PUBLISH, rows=FRONTEND_ARTICLE_ROWS)

    # Deal with paging
    paging_amount = Article.get_articles_paging_amount(article_status=STATUS_PUBLISH, rows=FRONTEND_ARTICLE_ROWS)

    if current_page > paging_amount: # Deal url current_page error
        abort(404)

    labels, has_login = _prepare_base_data()
    uri = str(request.url_rule)


    return render_template('/frontend/list_articles.html',
                            articles=articles,
                            labels=labels,
                            has_login=has_login,
                            current_page=current_page,
                            paging_amount=paging_amount,
                            uri=uri
                        )
Пример #3
0
def manage():

    page = request.args.get("page", 1)
    logging.info("page: {}".format(page))
    try:
        current_page = int(page)
    except Exception:
        return abort(404)

    uri = str(request.url_rule)
    template = "/backend/manage_articles.html"
    # Choose article status
    article_status = STATUS_PUBLISH
    if len(uri) > 5 and uri[-5:] == "draft":
        article_status = STATUS_SAVE
        template = "/backend/draft.html"

    logging.info("uri: {}".format(uri))

    paging_amount = Article.get_articles_paging_amount()
    # Deal with current_page params error
    if current_page > paging_amount or current_page < 1:
        return abort(404)

    articles = Article.get_articles_of_current_page(current_page=current_page, article_status=article_status)
    logging.info("articles: {}".format(articles))
    label = Label.get_labels()
    status = {STATUS_PUBLISH: u"发布", STATUS_SAVE: u"保存"}

    for article in articles:
        article.label = label[article.labelid - 1]["name"]
        article.status = status[article.status]

    username = session.get("username", "")
    return render_template(
        template, username=username, articles=articles, current_page=current_page, paging_amount=paging_amount, uri=uri
    )