示例#1
0
def search_topics():
    """
    返回搜索的全部内容
    """
    c_u = current_user()
    page = int(request.args.get('page', 1))
    content = request.args.get('content', '')
    limit = 20
    skip = limit * (page - 1)

    topics = Topic.find_lss(
        limit=limit,
        skip=skip,
        sort=-1,
        title={'$regex': '{}'.format(content)}
    )
    topic_count = Topic.count(title={'$regex': '{}'.format(content)})
    if topic_count % limit == 0:
        pages = topic_count // limit
    else:
        pages = topic_count // limit + 1
    # 5 个最近无人回复的话题
    ts = Topic.topic_noreply()
    return render_template(
        '/search/topics.html',
        current_user=c_u,
        content=content,
        topics=topics,
        ts=ts,
        page=page,
        pages=pages
    )
示例#2
0
def index():
    board_id = int(request.args.get('board_id', -1))
    page_num = int(request.args.get('page_num', 1))
    page_limit = int(request.args.get('page_limit', 3))

    topics = topics_for_index(board_id, page_num, page_limit)
    log('board_id', board_id)
    if board_id != -1:
        count = Topic.all_count(board_id=board_id)
        log('count', count)
    else:
        count = Topic.count()
        log('count', count)

    return json_succeed(
        topics=topics,
        count=ceil(count / page_limit),
    )
示例#3
0
文件: user.py 项目: snzhaoch/bbs
def user_topics(username):
    """
    用户创建话题页面
    """
    u = User.find_by(username=username)
    c_u = current_user()
    page = int(request.args.get('page', 1))
    if u is None:
        abort(404)
    else:
        # 全部创建的话题,每页 20 个
        limit = 5
        skip = limit * (page - 1)

        topics = Topic.find_lss(
            limit=limit,
            skip=skip,
            sort=-1,
            user_id=u.id
        )
        # 当前用户的 topic 一共有多少页
        topic_count = Topic.count(user_id=u.id)
        if topic_count % limit == 0:
            pages = topic_count // limit
        else:
            pages = topic_count // limit + 1
        # 5 个最近无人回复的话题
        ts = Topic.topic_noreply()
        return render_template(
            '/user/topics.html',
            user=u,
            current_user=c_u,
            ts=ts,
            topics=topics,
            page=page,
            pages=pages,
        )
示例#4
0
文件: topic.py 项目: snzhaoch/bbs
def index():
    """
    论坛主页
    """
    c_u = current_user()

    page = int(request.args.get('page', 1))
    if page is None:
        page = 1
    else:
        page = int(page)
    limit = 20
    skip = limit * (page - 1)

    board_id = request.args.get('board_id', '-1')
    # 首页不展示测试板块内容
    if board_id == '-1':
        tm = Topic.find_lss(
            limit=limit,
            skip=skip,
            sort=('lastreply_time', -1),
            top=True,
            test=False,
        )
        ms = Topic.find_lss(limit=limit,
                            skip=skip,
                            sort=('lastreply_time', -1),
                            top=False,
                            test=False)
        topic_count = Topic.count()
    else:
        # 每个测试板块置顶消息独立
        board = Board.find(board_id)
        if board.test is False:
            tm = Topic.find_lss(limit=limit,
                                skip=skip,
                                sort=('lastreply_time', -1),
                                top=True,
                                test=False)
        else:
            tm = Topic.find_lss(limit=limit,
                                skip=skip,
                                sort=('lastreply_time', -1),
                                board_id=board_id,
                                top=True,
                                test=True)
        ms = Topic.find_lss(limit=limit,
                            skip=skip,
                            sort=('lastreply_time', -1),
                            board_id=board_id,
                            top=False)
        topic_count = Topic.count(board_id=board_id)
    if topic_count % limit == 0:
        pages = topic_count // limit
    else:
        pages = topic_count // limit + 1

    ts = Topic.topic_noreply()
    bs = Board.all()
    return render_template(
        "topic/index.html",
        current_user=c_u,
        tm=tm,
        ms=ms,
        ts=ts,
        bs=bs,
        bid=board_id,
        page=page,
        pages=pages,
    )