def my_channel(channel_id): """列表页""" try: channel_id = int(channel_id) except ValueError: channel_id = 1 login_flag = is_login(session) # 用户是否已登录 channel_list = channel.channel_list() # 获取频道列表 channel_name = "" # 当前频道名称 class_list = channel.get_class_dict()[channel_id] # 获取频道所有小类 current_class_id = int(get_arg(request, "class_id", 0)) # 获取当前小类id for x in range(len(channel_list)): temp = channel_list[x] if temp['channel_id'] == channel_id: channel_name = temp['channel_name'] channel_list.pop(x) break if login_flag: try: user_img_url = session['user_img_url'] except KeyError: user_img_url = "" user_img_url = '../static/image/guest.png' if user_img_url == "" else session[ 'user_img_url'] user_level = 1 # 暂时替代 return render_template("channel.html", login_flag=login_flag, user_level=user_level, user_img_url=user_img_url) else: return render_template("channel.html", login_flag=login_flag, channel_list=channel_list, current_channel_name=channel_name, class_list=class_list, current_channel_id=channel_id, current_class_id=current_class_id)
def admin_center(key): """后台管理页""" if key == "user": """用户管理""" user_count = user.user_count() current_index = int(get_arg(request, "index", 1)) # 取页码 page_length = int(get_arg(request, "page_length", 20)) # 每页多少记录 max_index = math.ceil(user_count / page_length) # 最大页码 if max_index < current_index: current_index = max_index if 1 > current_index: current_index = 1 """每页显示5个可点击页码""" range_min = current_index - 2 if current_index > 2 else 1 rang_max = max_index if (range_min + 4) > max_index else (range_min + 4) index_range = [x for x in range(range_min, rang_max + 1)] user_data = user.page(current_index, page_length)['data'] return render_template("admin_center_user.html", user_count=user_count, index_range=index_range, max_index=max_index, current_index=current_index, prev_index=current_index if (current_index - 1) > 1 else 1, next_index=current_index + 1 if (current_index + 1) < max_index else max_index, user_data=user_data) elif key == "channel": """频道管理""" channel_list = channel.channel_list(1) small_class_dict = channel.get_class_dict(1) return render_template("admin_center_channel.html", channel_list=channel_list, small_class_dict=small_class_dict) elif key == "topic": """话题管理""" form = SearchLoginForm() topic_count = topic.topic_count() current_index = int(get_arg(request, "index", 1)) # 取页码 page_length = int(get_arg(request, "page_length", 5)) # 每页多少记录 max_index = math.ceil(topic_count / page_length) # 最大页码 if max_index < current_index: current_index = max_index if 1 > current_index: current_index = 1 """每页显示5个可点击页码""" range_min = current_index - 2 if current_index > 2 else 1 rang_max = max_index if (range_min + 4) > max_index else (range_min + 4) index_range = [x for x in range(range_min, rang_max + 1)] topic_data = topic.manage_topic_admin(the_type="page", index=current_index, page_length=page_length) topic_data = topic_data['data'] channel_list = channel.channel_list() return render_template("admin_center_topic.html", channel_list=channel_list, topic_count=topic_count, index_range=index_range, max_index=max_index, current_index=current_index, prev_index=current_index if (current_index - 1) > 1 else 1, next_index=current_index + 1 if (current_index + 1) < max_index else max_index, topic_data=topic_data, form=form)
def get_class_dict(): """返回小类数据""" data = json.dumps(channel.get_class_dict(1)) return data
def my_channel(channel_id): """列表页""" form = SearchLoginForm() # 搜索from try: channel_id = int(channel_id) except ValueError: channel_id = 1 login_flag = is_login(session) # 用户是否已登录 channel_list = channel.channel_list() # 获取频道列表 channel_name = "" # 当前频道名称 class_list = channel.get_class_dict()[channel_id] # 获取频道所有小类 current_class_id = int(get_arg(request, "class_id", 0)) # 获取当前小类id for x in range(len(channel_list)): temp = channel_list[x] if temp['channel_id'] == channel_id: """获取频道名""" channel_name = temp['channel_name'] break """获取频道的话题列表""" topic_list = topic.channel_topic_list(channel_id=channel_id, class_id=current_class_id) """计算争议度""" for x in topic_list: val = x.pop("a_vs_b") val_list = val.decode(encoding='utf8').split(" vs ") if len(val_list) != 2: """防止新帖子查询到的值是空字符的问题""" val_a = 0 val_b = 0 else: val_a = int(val_list[0]) val_b = int(val_list[1]) temp_per = 0 if val_a + val_b == 0 else ( val_a if val_a < val_b else val_b) / (val_a + val_b) if 0.4 <= temp_per <= 0.5: bomb_count = 3 elif 0.3 < temp_per < 0.4: bomb_count = 2 elif temp_per <= 0.3: bomb_count = 1 else: bomb_count = 0 x['bomb_count'] = bomb_count if login_flag: # 如果用户已登录 try: user_img_url = session['user_img_url'] except KeyError: user_img_url = "" user_img_url = '../static/image/guest.png' if user_img_url == "" else session[ 'user_img_url'] user_level = 1 # 暂时替代用户等级 return render_template("channel.html", login_flag=login_flag, channel_list=channel_list, current_channel_name=channel_name, class_list=class_list, current_channel_id=channel_id, current_class_id=current_class_id, topic_list=topic_list, user_level=user_level, user_img_url=user_img_url, form=form) else: return render_template("channel.html", login_flag=login_flag, channel_list=channel_list, current_channel_name=channel_name, class_list=class_list, current_channel_id=channel_id, current_class_id=current_class_id, topic_list=topic_list, form=form)