Exemple #1
0
def posts_subject():

    sub = request.args.get('subject')

    #推荐post
    filter = {
        'status': 1,
        'subject': sub,
        "pv": {
            "$gte": config['post'].NEW_PV
        }
    }
    sort_f = [('praise', -1), ('pv', -1)]
    view_data = p_posts(request, filter=filter)
    view_data['recommend'] = recommend_posts(sort=sort_f, filter=filter)

    # 标签
    view_data['post_tags'] = post_tags()
    #type
    view_data['subject'] = sub
    if sub == "tech":
        view_data['name'] = "科技有趣"
    elif sub == "art":
        view_data['name'] = "音悦 | 文艺"

    view_data['title'] = '{}-{}'.format(view_data['name'],
                                        config['title'].TITLE)
    view_data['profile'] = {'user_id': 'all'}

    return render_template('post/show/posts_subject.html', view_data=view_data)
Exemple #2
0
def post_search():

    user_id = request.args.get('user_id')
    s = request.args.get('s', "").strip()
    if not s:
        return {'post_cnt': 0, 'page_cnt': 0, 'all_page': []}
    filter = {
        "title": {
            "$regex": ".*{}.*".format(s),
            "$options": 'i'
        },
        'status': 1
    }
    if user_id:
        filter['user_id'] = int(user_id)
        is_paging = False
    else:
        is_paging = True
    _data = p_posts(request,
                    filter=filter,
                    pre=config['paging'].POST_SEARCH,
                    is_paging=is_paging)

    if (_data['page_num'] > _data['page_cnt']
            and _data['page_cnt'] > 0) or _data['page_num'] < 0:
        abort(404)
    _data['post_cnt'] = len(_data['posts'])
    return _data
Exemple #3
0
def get_post_type(type, tag):

    if type:
        filter = {'status': 1, 'type': type}
    elif tag:
        filter = {'status': 1, 'tag': tag}

    # 推荐post
    sort_f = [('praise', -1), ('pv', -1)]
    view_data = p_posts(request, filter=filter)
    view_data['recommend'] = list(recommend_posts(sort=sort_f, filter=filter))

    # 类型
    view_data['post_types'] = post_types()
    # 标签
    view_data['post_tags'] = post_tags()
    #
    view_data['type'] = type
    view_data['tag'] = tag
    if type:
        view_data['title'] = '{}-{}'.format(type, config['title'].TITLE)
    else:
        view_data['title'] = '{}-{}'.format(tag, config['title'].TITLE)
    view_data['profile'] = {'user_id': 'all'}

    return view_data
Exemple #4
0
def site_map():

    is_paging = True
    view_data = p_posts(request,pre=20,is_paging=is_paging)
    view_data['post_cnt'] = len(view_data['posts'])
    view_data['title'] = "网站地图-{}".format(config['title'].TITLE)
    if not view_data['post_cnt']:
        abort(404)
    return render_template('search/site_post_map.html',  view_data=view_data)
Exemple #5
0
def posts_type():
    request_path(['type','tag'])
    type = request.args.get('type')
    tag = request.args.get('tag')
    if type:
        filter = {'status':1, 'type':type}
    elif tag:
        filter = {'status':1, 'tag':tag}
    view_data = p_posts(request, filter=filter)

    return jsonify(view_data)
Exemple #6
0
def posts():
    '''
    文章api查询
    :return:
    '''
    request_path(['sub','user_id','type','tag'])
    sub = request.args.get('sub')
    user_id = request.args.get('user_id')
    type = request.args.get('type')
    tag = request.args.get('tag')
    sort_f = [('time',-1)]
    if user_id:
        if sub == "draft" or sub == "review":
            if current_user.is_anonymous() or (int(user_id) != current_user.id and not current_user.can(Permission.ADMINISTER)):
                abort(404)
        filter = {'user_id':int(user_id)}
    else:
        filter = {'subject':{'$ne':'sys'}}
    if type:
        filter['type'] = type
    elif tag:
        filter['tag'] = type

    if sub == 'hot':
        sort_f = [('praise',-1),('pv',-1)]
        filter['status'] = 1
    elif sub == "draft":
        filter['status'] = 0
    elif sub == "review":
        filter['$or'] = [{'status':2},{'status':3},{'status':5}]
    elif sub=="new":
        filter['status'] = 1
        if not user_id:
            filter['pv'] = {"$gte":config['post'].NEW_PV}

    else:
        filter['status'] = 1
        filter['subject'] = sub
        filter['pv'] = {"$gte":config['post'].NEW_PV}
    view_data = p_posts(request, sort = sort_f,filter=filter)
    if user_id:
        for data in view_data['posts']:
            if data['status'] == 3:
                data['title'] = '{}<span  style="color: #ea1717; display: inline;" >[不通过]</span>'.format(data['title'])
    return jsonify(view_data)
Exemple #7
0
def get_user_posts(id):

    sub = request.args.get('sub')
    sort_f = [('time',-1)]
    if sub == 'hot':
        sort_f = [('praise',-1),('pv',-1)]

    temp_data = {}
    try:
        id = ObjectId(id)
        temp_data['profile'] = mdb_user.user_profile.find_one({"user_id":id})
    except:
        temp_data['profile'] = mdb_user.db.user_profile.find_one_or_404({"user_domain":id})
        id = temp_data['profile']["user_id"]

    user = mdb_user.db.user.find_one({"_id":id})
    filter = {'user_id':id, 'status':1}
    view_data = p_posts(request, filter = filter, sort=sort_f, pre=config['paging'].POST_PER_PAGE)
    view_data = dict(view_data, **temp_data)
    view_data['post_tags'] = post_tags(filter={'user_id':id})

    view_data['title'] = "{}的主页-{}".format(user['username'], config['title'].TITLE)

    return view_data
Exemple #8
0
def posts_subject():
    request_path(['subject'])
    subject = request.args.get('subject')
    filter = {'status':1, 'subject':subject}
    view_data = p_posts(request, filter=filter)
    return jsonify(view_data)