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
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)
def sys_agr_show(): type = request.args.get('type') t = request.args.get('t') # post filter = {'subject': 'sys', 'status': 1} filter['title'] = t filter['type'] = type view_data = p_post(filter=filter) if "redirect" in view_data: abort(404) if not current_user.is_anonymous(): if current_user.id in view_data['post']['praise_id']: view_data['praise_status'] = True view_data['title'] = "{}-{}".format(view_data['post']['title'], config['title'].TITLE) # 推荐 filter = {'status': 1, 'type': '协议政策', 'subject': 'sys'} view_data['recommend'] = recommend_posts(filter=filter) return render_template('post/show/sys_agr.html', view_data=view_data)
def on_search(): if current_user.is_anonymous() and mdb_sys.db.search_log.find_one({'ip':request.remote_addr, 'time':{'$gt':time.time()-10}}): view_data = {} view_data['flash'] = {'msg':'未登录用户10秒内只能搜索1次[防机器人]', 'type':'w'} view_data['all_page'] = [] view_data['page_cnt'] = 0 view_data['post_cnt'] = 0 else: view_data = post_search() if current_user.is_anonymous(): r = mdb_sys.db.search_log.update({'ip':request.remote_addr}, {'$set':{'time':time.time()}},True) if not view_data['page_cnt']: view_data['flash'] = {'msg':'没有相关内容', 'type':'s'} else: view_data['flash'] = {'msg':'', 'type':'s'} #推荐post sort_f = [('praise',-1),('pv',-1)] view_data['recommend'] = recommend_posts(sort=sort_f) view_data['title'] = "站内搜索-{}".format(config['title'].TITLE) view_data['s'] = request.args.get('s',"") return render_template('search/posts.html', view_data=view_data)
def show(post_id): ''' comment status 1:通过 2:待审核 3:未通过 4:已删除 5:自动审核通过 :return: ''' # post view_data = p_post(filter={'_id': ObjectId(post_id), 'status': 1}) if "redirect" in view_data: return redirect(view_data['redirect']) if not current_user.is_anonymous(): if current_user.id in view_data['post']['praise_id']: view_data['praise_status'] = True # comment c_filter = { 'case_id': ObjectId(post_id), "$or": [{ 'status': 1 }, { 'status': 2 }, { 'status': 3 }, { 'status': 5 }] } view_data = dict(view_data, **p_comments(request, post_id, filter=c_filter)) # 侧边栏 # 推荐 sort_f = [('praise', -1), ('pv', -1)] filter = { 'status': 1, 'type': view_data['post']['type'], '_id': { '$ne': ObjectId(post_id) } } view_data['recommend'] = recommend_posts(sort=sort_f, filter=filter) # 标签 view_data['post_tags'] = post_tags( filter={'user_id': view_data['post']['user_id']}) view_data['title'] = "{}-{}".format(view_data['post']['title'], config['title'].TITLE) view_data['post_url'] = "{}{}".format( config['post'].DOMAIN, url_for('post.show', post_id=post_id)) view_data['dest'] = "" for tag in view_data["post"]["tag"]: view_data['dest'] = "{},{}".format(view_data['dest'], tag) if "redirect" in view_data: return redirect(view_data['redirect']) ua_key = 'noobw_ua' if ua_key in request.cookies: ua_id = request.cookies.get(ua_key) r = p_post_pv_1(post_id, ua_id) if r: view_data['post']['pv'] += 1 else: r = p_post_pv_1(post_id, 0) if r: view_data['post']['pv'] += 1 resp = make_response( render_template('post/show/post.html', view_data=view_data)) resp.set_cookie('noobw_ua', uuid(), config['cookie'].POST_TIMEOUT) return resp return render_template('{}/post/show/post.html'.format(Theme.THEME_NAME), view_data=view_data)