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)
def recommend_posts(sort=[('time', -1)], filter={ 'status': 1, 'subject': { '$ne': 'sys' } }, field={'body': 0}): request_path(filter) recommend = get_recommend_posts(sort, filter, field) return recommend
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)
def new_comments( sort=[('time', -1)], filter={ 'status': 1, '$or': [{ 'reply': { '$exists': False } }, { 'reply': None }, { 'reply': False }] }): request_path(filter) _data = get_new_comments(sort, filter) return _data
def p_comments(request, post_id, filter={ "$or": [{ 'status': 1 }, { 'status': 2 }, { 'status': 3 }, { 'status': 5 }] }, sort=[('time', -1)]): t_filter = filter.copy() t_filter['post-id'] = post_id request_path(t_filter) view_data = get_p_comments(request, post_id, filter, sort) return view_data
def p_posts(request, filter={ 'status': 1, 'subject': { '$ne': 'sys' } }, sort=[('time', -1)], field={'body': 0}, pre=config['paging'].POST_PER_PAGE_HOME, is_paging=False): t_filter = filter.copy() t_filter['field'] = field t_filter['pre'] = pre request_path(t_filter) if "user_id" in filter: view_data = get_user_p_posts(filter, sort, field, pre, is_paging) else: view_data = get_p_posts(filter, sort, field, pre, is_paging) return view_data
def post_tags(filter={'user_id': 0}): # 标签 request_path(filter) _post_tags = get_post_tags(filter) return _post_tags
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)