Beispiel #1
0
def index(pn=1, size=10, catalog_id=None):
    # flash("asdsdsad")

    print(datetime.now())
    sort_key = request.values.get('sort_key', '_id')
    sort_by = (sort_key, pymongo.DESCENDING)
    post_type = request.values.get('type')
    filter1 = {}
    if post_type == 'not_closed':
        filter1['is_closed'] = {'$ne': True}
    if post_type == 'is_closed':
        filter1['is_closed'] = True
    if post_type == 'is_cream':
        filter1['is_cream'] = True
    if catalog_id:
        filter1['catalog_id'] = catalog_id
    page = db_utils.get_page('posts',
                             pn=pn,
                             filter1=filter1,
                             size=size,
                             sort_by=sort_by)
    # print(page)
    return render_template("post_list.html",
                           is_index=catalog_id is None,
                           page=page,
                           sort_key=sort_key,
                           catalog_id=catalog_id,
                           post_type=post_type)
Beispiel #2
0
def post_list(pn=1):
    # posts = mongo.db.posts.find({"user_id": current_user.user['_id']})
    page = db_utils.get_page('posts',
                             1,
                             sort_by=('_id', -1),
                             filter1={"user_id": current_user.user['_id']})
    data = models.R.ok().put('rows', page.result).put('count', page.total)
    return dumps(data)
Beispiel #3
0
def post_detail(post_id, pn=1):
    post = mongo.db.posts.find_one_or_404({'_id': post_id})
    if post:
        post['view_count'] = post.get('view_count', 0) + 1
        mongo.db.posts.save(post)
    post['user'] = db_utils.find_one('users', {'_id': post['user_id']}) or {}

    page = db_utils.get_page('comments', pn=pn, size=10, filter1={'post_id': post_id}, sort_by=('is_adopted', -1))
    return render_template('jie/detail.html', post=post, title=post['title'], page_name='jie', comment_page=page, catalog_id=post['catalog_id'])
Beispiel #4
0
def user_message(pn=1):
    user = current_user.user
    if user.get('unread', 0) > 0:
        mongo.db.users.update({'_id': user['_id']}, {'$set': {'unread': 0}})
    message_page = db_utils.get_page('messages',
                                     pn,
                                     filter1={'user_id': user['_id']},
                                     sort_by=('_id', -1))
    return render_template('user/message.html',
                           user_page='message',
                           page_name='user',
                           page=message_page)