Пример #1
0
def paginate(page):
    page = int(page)
    article = Article()
    result = article.find_with_all((page - 1) * 10, 10)
    total = math.ceil(article.get_total_count() / 10)
    last = article.find_last_9()
    most = article.find_most_9()
    content = render_template('index.html',
                              result=result,
                              page=page,
                              total=total,
                              last=last,
                              most=most)
    return content
Пример #2
0
def home():

    article = Article()
    result = article.find_with_all(0, 10)
    last = article.find_last_9()
    most = article.find_most_9()
    total = math.ceil(article.get_total_count() / 10)
    content = render_template('index.html',
                              result=result,
                              page=1,
                              total=total,
                              last=last,
                              most=most)
    return content
Пример #3
0
def classify(type, page):
    start = (page - 1) * 10
    article = Article()
    result = article.find_by_type(type, start, 10)
    total = math.ceil(article.get_count_by_type(type) / 10)
    last = article.find_last_9()
    most = article.find_most_9()

    return render_template('type.html',
                           result=result,
                           page=page,
                           total=total,
                           type=type,
                           last=last,
                           most=most)
Пример #4
0
def search(page, keyword):
    keyword = keyword.strip()
    if keyword is None or keyword == '' or '%' in keyword or len(keyword) > 10:
        abort(404)
    start = (page - 1) * 10
    article = Article()
    result = article.find_by_headline(keyword, start, 10)
    total = math.ceil(article.get_count_by_headline(keyword) / 10)
    last = article.find_last_9()
    most = article.find_most_9()

    return render_template('search.html',
                           result=result,
                           page=page,
                           total=total,
                           keyword=keyword,
                           last=last,
                           most=most)
Пример #5
0
def read(articleid):
    try:
        result, user = Article().find_by_id(articleid)
        if result is None:
            abort(404)
    except Exception as e:
        abort(500)
    article = Article()
    last = article.find_last_9()
    most = article.find_most_9()

    payed = Credit().check_payed_article(articleid)

    position = 0
    if not payed:
        content = result.content
        temp = content[0:int(len(content) / 2)]
        try:
            position = temp.rindex('</p>') + 4
            content = temp[0:position]

        except:
            content = temp
            position = int(len(content) / 2)

    else:
        content = result.content

    Article().update_read_count(articleid)

    is_favorited = Favorite().check_favorite(articleid)

    total = 0

    return render_template('article-user.html',
                           article=result,
                           position=position,
                           payed=payed,
                           is_favorited=is_favorited,
                           content=content,
                           total=total,
                           user=user,
                           last=last,
                           most=most)