Example #1
0
def show_update_comments_stat_update(request, info_id):
    print('index show_update_comments_stat_update')

    # 权限检查
    auth_data = {
        'request': request,
        'net': False,
        'login': True,
        'debug': False,
        'perm': '',
        'perm_group': '知识库管理员'
    }
    resp_auth = main.auth(auth_data)
    print('user : '******'code') == False:
        return render(request, 'alarm/resp.html',
                      {"message": resp_auth.get('msg')})

    r = info_comments.objects.get(id=request.POST.get('comments_id'))
    r_old = info_comments.objects.get(id=request.POST.get('comments_id'))
    r.i_stat = info_comments_stat.objects.get(
        code=request.POST.get('comment_stat_code'))
    r.save()

    try:
        r_old_stat_code = r_old.i_stat.code
    except:
        r_old_stat_code = 999
    print(r.i_stat.code)

    if r_old_stat_code != 0 and r.i_stat.code == 0:
        # 积分计算
        main.action_log(
            request, {
                "app_type": "search_problem",
                'action_type': "comments",
                'info_id': info_id,
                'text': r.id,
                'oper': r.update_oper
            })
    if r_old_stat_code == 0 and r.i_stat.code != 0:
        # 积分计算
        main.action_log(
            request, {
                "app_type": "search_problem",
                'action_type': "comments_close",
                'info_id': info_id,
                'text': r.id,
                'oper': r.update_oper
            })

    resp = {"code": 0}
    return HttpResponse(json.dumps(resp), content_type="application/json")
Example #2
0
def show_update_close(request, info_id):
    print('index show_update_close')

    # 权限检查
    auth_data = {
        'request': request,
        'net': False,
        'login': True,
        'debug': False,
        'perm': '',
        'perm_group': '知识库管理员'
    }
    resp_auth = main.auth(auth_data)
    print('user : '******'code') == False:
        return render(request, 'alarm/resp.html',
                      {"message": resp_auth.get('msg')})

    r = info.objects.get(id=info_id)
    r_old = info.objects.get(id=info_id)

    r.t_close = info_close.objects.get(code=999)
    r.save()

    try:
        r_old_close_code = r_old.t_close.code
    except:
        r_old_close_code = 0

    if r_old_close_code != 999 and r.t_close.code == 999:
        # 积分计算
        if r.t_stat.stat_id == 1:
            main.action_log(
                request, {
                    "app_type": "search_problem",
                    'action_type': "answer_close",
                    'info_id': info_id,
                    'oper': r.answer_oper
                })
        main.action_log(
            request, {
                "app_type": "search_problem",
                'action_type': "input_close",
                'info_id': info_id,
                'oper': r.input_oper
            })

    resp = {"code": 0}
    return HttpResponse(json.dumps(resp), content_type="application/json")
Example #3
0
def show_submit(request, info_id):
    print('index new_submit')

    input_data = json.loads(request.POST.get('input_data'))
    fwb_data = request.POST.get('fwb_data')
    user = request.user

    print(input_data)
    print(fwb_data)

    print('type = [' + request.POST.get('type') + ']')
    r = info.objects.get(id=info_id)
    r_old = info.objects.get(id=info_id)
    r.title = input_data.get('title')
    problem_answer = BeautifulSoup(fwb_data, 'html.parser')
    problem_answer_txt = problem_answer.get_text()
    r.problem_answer = fwb_data
    r.problem_answer_txt = problem_answer_txt
    if len(problem_answer_txt) > 1:
        # 已解答
        r.t_stat = info_stat.objects.get(stat_id=1)
        # 初次时
        if request.POST.get('type') == 'new':
            r.answer_oper = request.user.first_name
            r.answer_date = time.strftime('%Y-%m-%d %H:%M:%S',
                                          time.localtime())
    else:
        # 未解答
        r.t_stat = info_stat.objects.get(stat_id=0)
    r.update_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    r.t_channel = info_channel.objects.get(code=input_data.get('channel'))
    r.t_type = info_type.objects.get(code=input_data.get('info_type'))
    r.info_check_update = 0

    if input_data.get('info_check_flag') == 'on':
        r.info_check_flag = 1
    else:
        r.info_check_flag = 2

    print(r)

    try:
        r.save()
        code = 0
        msg = '感谢您对知识库的完善:)'

        a = action(type=action_type.objects.get(code=4),
                   text=str(r.id),
                   oper=request.user.first_name,
                   date=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
        a.save()

        # 进行解答时
        if r_old.t_stat.stat_id == 0 and r.t_stat.stat_id == 1:
            main.action_log(
                request, {
                    "app_type": "search_problem",
                    'action_type': "answer",
                    'info_id': r.id
                })
        # 进行认证时
        if r_old.info_check_flag != 1 and r.info_check_flag == 1:
            main.action_log(
                request,
                {
                    "app_type": "search_problem",
                    'action_type': "answer_auth"  # 解答人加分
                    ,
                    'info_id': r.id,
                    'oper': r.answer_oper
                })
            main.action_log(
                request,
                {
                    "app_type": "search_problem",
                    'action_type': "auth"  # 操作员加分
                    ,
                    'info_id': r.id
                })
        if r_old.info_check_flag == 1 and r.info_check_flag != 1:
            main.action_log(
                request,
                {
                    "app_type": "search_problem",
                    'action_type': "answer_auth_close"  # 解答人减分
                    ,
                    'info_id': r.id,
                    'oper': r.answer_oper
                })
    except Exception as msg_info:
        code = -1
        print(repr(msg_info))
        print(msg_info)
        msg = '提交失败了。。。<br>报错信息:' + str(msg_info)
        # msg = '录入失败了,可能该标题已存在,无法重复入库~'

    resp = {"code": code, "msg": msg}

    return HttpResponse(json.dumps(resp), content_type="application/json")
Example #4
0
def show(request, info_id):
    print('index show')
    print('info_id = [' + str(info_id) + ']')

    # 计数
    r = info.objects.get(id=info_id)
    r.count_chick += 1
    r.save()

    comments_data = []
    for line in info.objects.filter(id=info_id):
        data = line.__dict__
        data_stat_id = line.t_stat.stat_id
        for line_comments in line.t_comments.all():
            # comments_data.append(model_to_dict(line_comments, exclude=['update_date']))
            try:
                stat_code = line_comments.i_stat.code
            except:
                stat_code = 999
            comments_data.append({
                'id':
                line_comments.id,
                "name":
                line_comments.name,
                "stat_code":
                stat_code,
                "update_oper":
                line_comments.update_oper,
                "update_date":
                line_comments.update_date.strftime("%Y-%m-%d %H:%M:%S")
            })

        try:
            data_channel_id = line.t_channel.code
            data_type_id = line.t_type.code
        except:
            data_channel_id = 666
            data_type_id = 666

    print(data)

    channel_data = []
    for line in info_channel.objects.all():
        channel_data.append(line.__dict__)

    type_data = []
    for line in info_type.objects.all():
        type_data.append(line.__dict__)

    # for line in
    # info_comments

    # 调用数据中台API
    res = requests.post(
        url='http://' + request.META.get('HTTP_HOST') + '/' + 'data_api/oper/',
        data={"comm_i_user_first_name": request.user.first_name})
    resp = json.loads(res.text)

    user_data = {}
    for line in resp.get('data'):
        user_data = line
    app_auth = 0
    for line in user_data.get('group_data'):
        if line.get('name') == '知识库管理员':
            app_auth = 1

    # 操作记录
    a = action(type=action_type.objects.get(code=2),
               text=str(info_id),
               oper=request.user.first_name,
               date=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
    a.save()

    # 积分计算 查看他人知识卡片
    main.action_log(request, {
        "app_type": "search_problem",
        'action_type': "show",
        'info_id': info_id
    })

    # 认证解答被查看
    if r.info_check_flag == 1:
        main.action_log(
            request, {
                "app_type": "search_problem",
                'action_type': "answer_auth_show",
                'info_id': info_id,
                'oper': r.answer_oper
            })
        main.action_log(
            request, {
                "app_type": "search_problem",
                'action_type': "input_auth_show",
                'info_id': info_id,
                'oper': r.input_oper
            })

    resp = {
        "code": 0,
        "data": data,
        "type": 'new',
        "stat": data_stat_id,
        "channel": channel_data,
        'type_data': type_data,
        "data_channel_id": data_channel_id,
        "data_type_id": data_type_id,
        'comments_data': comments_data,
        'app_auth': app_auth
    }
    print(resp)
    return render(request, 'search_problem/show.html', resp)
Example #5
0
def search(request):
    print('def search')
    t1 = time.time()

    problem_id = request.GET.get('keywords')
    print('problem_id = [' + problem_id + ']')

    # 操作记录
    a = action(type=action_type.objects.get(code=1),
               text=problem_id,
               oper=request.user.first_name,
               date=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
    a.save()

    # contains 区分大小写 icontains 不区分
    # Entity.objects.filter(Q(name_icontains='kris') | Q(address_icontains='beijing'))
    # 调用数据中台API
    res = requests.post(url='http://' + request.META.get('HTTP_HOST') + '/' +
                        'data_api/search_problem/',
                        data={'comm_i_search': problem_id})
    resp = json.loads(res.text)

    print(resp)
    data = []
    for line in resp.get('data'):
        # 计数 会严重影响查询时间
        # print(line)
        # r = info.objects.get(id=line.get('id'))
        # r.count_search += 1
        # r.save()

        data.append(line)

    # data.sort(key=lambda item: item.get('id'), reverse=True)
    data.sort(key=lambda item: item.get('t_stat_id'), reverse=True)
    data.sort(key=lambda item: item.get('info_check_flag'), reverse=True)

    tmp_data = []
    for line in data:
        if line.get('info_check_flag') == 1:
            tmp_data.insert(0, line)
        else:
            tmp_data.append(line)
    data = tmp_data

    # 用时计算
    t2 = time.time()
    t3 = (t2 - t1) * 1000

    # 积分计算
    main.action_log(request, {
        "app_type": "search_problem",
        'action_type': "search",
        'text': problem_id
    })

    req = {
        'title': 'search',
        'data': data,
        'len': len(data),
        'problem_id': problem_id,
        'use_time': int(t3)
    }
    return render(request, 'search_problem/search.html', req)
Example #6
0
def new_submit(request):
    print('index new_submit')

    # 权限检查
    auth_data = {
        'request': request,
        'net': False,
        'net_sc': True,
        'login': True,
        'debug': False,
        'perm': 'rjxf_server.view_flow'
    }

    resp_auth = main.auth(auth_data)
    # print('user : '******'code') == False:
        # return render(request, 'alarm/resp.html', {"message": resp_auth.get('msg')})
        resp = {"code": resp_auth.get('code'), "msg": resp_auth.get('msg')}
        return HttpResponse(json.dumps(resp), content_type="application/json")

    input_data = json.loads(request.POST.get('input_data'))
    fwb_data = request.POST.get('fwb_data')
    fwb_text_answer = request.POST.get('fwb_text_answer')
    user = request.user

    print(input_data)
    print(fwb_data)

    if request.POST.get('type') == 'input':
        stat = 1
        answer_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    else:
        stat = 0
        answer_date = None

    print('type = [' + request.POST.get('type') + ']')

    print(fwb_text_answer)
    if fwb_text_answer is None:
        fwb_text_answer = ''
    if input_data.get('comm_i_info_channel') is None:
        info__t_channel = None
    else:
        info__t_channel = info_channel.objects.get(
            code=input_data.get('comm_i_info_channel'))

    if input_data.get('comm_i_info_type') is None:
        info__t_type = None
    else:
        info__t_type = info_type.objects.get(
            code=input_data.get('comm_i_info_type'))

    problem_answer = BeautifulSoup(fwb_text_answer, 'html.parser')

    r = info(title=input_data.get('title'),
             trans_code=input_data.get('trans_code'),
             trans_err=input_data.get('trans_err'),
             problem_info=fwb_data,
             problem_answer=fwb_text_answer,
             problem_answer_txt=problem_answer.get_text(),
             input_oper=user.first_name,
             answer_oper=input_data.get('answer_oper'),
             bank_id=input_data.get('bank_id'),
             bank_oper=input_data.get('bank_oper'),
             problem_source=input_data.get('problem_source'),
             input_date=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),
             update_date=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),
             answer_date=answer_date,
             t_stat=info_stat.objects.get(stat_id=stat),
             t_channel=info__t_channel,
             t_type=info__t_type,
             info_check_flag=0,
             info_check_update=0,
             count_search=0,
             count_chick=0)
    code = 0
    msg = ''

    try:
        r.save()
        code = 0
        msg = '感谢您对知识库的完善:)'

        # 操作记录
        a = action(type=action_type.objects.get(code=3),
                   text=str(r.id),
                   oper=request.user.first_name,
                   date=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
        a.save()

        # 积分计算
        main.action_log(request, {
            "app_type": "search_problem",
            'action_type': "input",
            'info_id': r.id
        })
        if stat == 1:
            main.action_log(
                request, {
                    "app_type": "search_problem",
                    'action_type': "answer",
                    'info_id': r.id,
                    'oper': r.answer_oper
                })
    except Exception as msg_info:
        code = -1
        print(repr(msg_info))
        print(msg_info)
        print(msg_info.args[0])

        if msg_info.args[0] == 1406:
            msg = '录入失败了,答案的内容超出长度限制,入库失败了哟~~~'
        elif msg_info.args[0] == 1062:
            msg = '录入失败了,可能该标题已存在,无法重复入库~'
        else:
            msg = '录入失败了。。。<br>报错信息:' + str(msg_info)
            # msg = '录入失败了~' + str(msg_info)

    resp = {"code": code, "msg": msg}
    return HttpResponse(json.dumps(resp), content_type="application/json")