Beispiel #1
0
def view_topic(key):
    """管理员浏览话题的详细页"""
    form = RequestLoginForm()
    result = topic.manage_topic_admin(top_id=key, the_type="single")
    topic_info = result['data']
    surplus = surplus_datetime(topic_info['end_date'])  # 剩余时间
    all_view_count = vote_tools.get_view_count(topic_id=key)  # 浏览总数
    query_vote = vote_tools.get_vote_count(key)  # 查询 投票人数
    support_a = query_vote['support_a']
    support_b = query_vote['support_b']
    join_count = support_b + support_a  # 投票总人数
    if support_a == 0 and join_count == 0:
        blue_width = 50
    else:
        blue_width = int((support_a / join_count) * 1000) / 10
    red_width = 100 - blue_width
    """计算争议度"""
    val = topic_info.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
    topic_info['bomb_count'] = bomb_count

    return render_template("detail.html",
                           topic_info=topic_info,
                           surplus=surplus,
                           join_count=join_count,
                           blue_width=blue_width,
                           red_width=red_width,
                           all_view_count=all_view_count,
                           form=form)
Beispiel #2
0
def view_topic(key):
    """管理员浏览话题的详细页"""
    form = RequestLoginForm()
    result = topic.manage_topic_admin(top_id=key, the_type="single")
    topic_info = result['data']
    surplus = surplus_datetime(topic_info['end_date'])  # 剩余时间
    all_view_count = vote_tools.get_view_count(topic_id=key)  # 浏览总数
    query_vote = vote_tools.get_vote_count(key)  # 查询 投票人数
    support_a = query_vote['support_a']
    support_b = query_vote['support_b']
    join_count = support_b + support_a  # 投票总人数
    if support_a == 0 or join_count == 0:
        blue_width = 50
    else:
        blue_width = int((support_a / join_count) * 1000) / 10
    red_width = 100 - blue_width
    return render_template("detail.html",
                           topic_info=topic_info,
                           surplus=surplus,
                           join_count=join_count,
                           blue_width=blue_width,
                           red_width=red_width,
                           all_view_count=all_view_count,
                           form=form)
Beispiel #3
0
def manage_handler(key1, key2):
    """对后台的编辑接口"""
    message = {"message": "未知操作类型"}
    if key1 == "user":
        """管理用户"""
        """取参数集"""
        the_form = request.form
        arg_dict = {key: the_form[key] for key in the_form.keys()}
        if key2 == "up_user":
            message = up_user(arg_dict['user_id'])
        elif key2 == "down_user":
            message = down_user(arg_dict['user_id'])
        elif key2 == "drop_user":
            message = drop_user(arg_dict['user_id'])
        else:
            pass

    elif key1 == "class":
        """对类别的操作"""
        if key2 == "save":
            the_form = request.form
            arg_dict = {
                key: json.loads(the_form[key])
                for key in the_form.keys()
            }
            result = channel.save_class(arg_dict)
            if result:
                message = result
            else:
                message = {"message": "保存类别信息失败"}

    elif key1 == "topic":
        """对话题的操作"""
        if key2 == "edit":
            """编辑话题"""
            the_form = request.form
            arg_dict = dict()
            for key in the_form.keys():
                temp = the_form[key]
                if temp is not None:
                    arg_dict[key] = temp
            result = topic.manage_topic_admin(**arg_dict)
            return json.dumps(result)
        elif key2 == "up_topic":
            """审核帖子"""
            the_form = request.form
            arg_dict = dict()
            for key in the_form.keys():
                temp = the_form[key]
                if temp is not None:
                    arg_dict[key] = temp
            result = topic.manage_topic_admin(**arg_dict)
            return json.dumps(result)

        elif key2 == "down_topic":
            """停用帖子"""
            the_form = request.form
            arg_dict = dict()
            for key in the_form.keys():
                temp = the_form[key]
                if temp is not None:
                    arg_dict[key] = temp
            result = topic.manage_topic_admin(**arg_dict)
            return json.dumps(result)

        elif key2 == "drop_topic":
            """删除帖子"""
            the_form = request.form
            arg_dict = dict()
            for key in the_form.keys():
                temp = the_form[key]
                if temp is not None:
                    arg_dict[key] = temp
            result = topic.manage_topic_admin(**arg_dict)
            return json.dumps(result)

    else:
        abort(403)
    return json.dumps(message)
Beispiel #4
0
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)
Beispiel #5
0
def manage_handler(key1, key2):
    """对后台的编辑接口"""
    message = {"message": "未知操作类型"}
    if key1 == "user":
        """管理用户"""
        """取参数集"""
        the_form = request.form
        arg_dict = {key: the_form[key] for key in the_form.keys()}
        if key2 == "up_user":
            message = up_user(arg_dict['user_id'])
        elif key2 == "down_user":
            message = down_user(arg_dict['user_id'])
        elif key2 == "drop_user":
            message = drop_user(arg_dict['user_id'])
        else:
            pass

    elif key1 == "class":
        """对类别的操作"""
        if key2 == "save":
            the_form = request.form
            arg_dict = {
                key: json.loads(the_form[key])
                for key in the_form.keys()
            }
            result = channel.save_class(arg_dict)
            if result:
                message = result
            else:
                message = {"message": "保存类别信息失败"}

    elif key1 == "topic":
        """对话题的操作"""
        if key2 == "edit":
            """编辑话题"""
            the_form = request.form
            arg_dict = dict()
            for key in the_form.keys():
                temp = the_form[key]
                if temp is not None:
                    arg_dict[key] = temp
            result = topic.manage_topic_admin(**arg_dict)
            return json.dumps(result)
        elif key2 == "up_topic":
            """审核帖子"""
            the_form = request.form
            arg_dict = dict()
            for key in the_form.keys():
                temp = the_form[key]
                if temp is not None:
                    arg_dict[key] = temp
            result = topic.manage_topic_admin(**arg_dict)
            return json.dumps(result)

        elif key2 == "down_topic":
            """停用帖子"""
            the_form = request.form
            arg_dict = dict()
            for key in the_form.keys():
                temp = the_form[key]
                if temp is not None:
                    arg_dict[key] = temp
            result = topic.manage_topic_admin(**arg_dict)
            return json.dumps(result)

        elif key2 == "drop_topic":
            """删除帖子"""
            the_form = request.form
            arg_dict = dict()
            for key in the_form.keys():
                temp = the_form[key]
                if temp is not None:
                    arg_dict[key] = temp
            result = topic.manage_topic_admin(**arg_dict)
            return json.dumps(result)

    elif key1 == 'banner':
        """对banner的操作"""
        """取参数集"""
        the_form = request.form
        arg_dict = {key: the_form[key] for key in the_form.keys()}
        if key2 in ['add', 'delete', 'edit']:
            arg_dict['the_type'] = key2
            message = banner_manage.manage_banner(**arg_dict)
        else:
            message = {"message": "操作指定错误"}

    elif key1 == "keywords":
        """对搜索热词,keywords,title,description的操作"""
        """取参数集"""
        the_form = request.form
        arg_dict = {key: the_form[key] for key in the_form.keys()}
        if key2 in ['add', 'delete', 'edit']:
            arg_dict['the_type'] = key2
            message = banner_manage.manage_keywords(**arg_dict)
        else:
            message = {"message": "操作指定错误"}

    elif key1 == "comment":
        """对评论的操作"""
        the_form = request.form
        arg_dict = {key: the_form[key] for key in the_form.keys()}
        if key2 in ['add', 'delete', 'edit']:
            arg_dict['the_type'] = key2
            message = comment.manage_comment(**arg_dict)
        else:
            message = {"message": "操作指定错误"}

    else:
        message = {"message": "无法理解的操作"}

    return json.dumps(message)