Example #1
0
def api_mod_account(request):
    log_request(request)
    try:
        name = getp(request.POST.get('name'), nullable=False, para_intro='姓名')
        sex = getp(request.POST.get('sex'), nullable=True, para_intro='性别')
        area_id = getp(request.POST.get('area_id'), nullable=True, para_intro='地区id')
        area_name = getp(request.POST.get("area_name"), u"地域名称", nullable=True)
        manage_direct = getp(request.POST.get("manage_direct"), u"直属标志", nullable=True)
        institution = getp(request.POST.get('institution'), nullable=True, para_intro='机构')
        position = getp(request.POST.get('position'), nullable=True, para_intro='职务')

        region_id = getp(request.POST.get('region_id'), nullable=True, para_intro='区域id')
        email = getp(request.POST.get('email'), nullable=True, para_intro='区域id')

        is_self_reg = getp(request.POST.get('is_self_reg'), nullable=True, para_intro='是否自主注册')

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        result = services.api_mod_account(request, name, sex, area_id, area_name, manage_direct, institution, position, region_id, email, is_self_reg)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Example #2
0
def page_practice_list_answer_his(request):
    """
    功能说明: 查看历史答题记录页面
    """
    log_request(request)
    try:
        user_name = getp(request.GET.get('username'),
                         nullable=True,
                         para_intro='用户姓名',
                         default='')
        days = getp(request.GET.get('days'),
                    nullable=False,
                    para_intro='最近天数',
                    default='7')

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        params = services.get_practice_list_answer_his(request, user_name,
                                                       days)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, params)
    return render_to_response('html/practice/answer_his.html', params)
Example #3
0
def api_practice_pinyin(request):
    """
    功能说明: 下载拼音练习EXCEL
    """
    log_request(request)
    try:
        has_hanzi = getp(request.GET.get('has_hanzi'),
                         nullable=True,
                         para_intro='仅显示汉字拼音,不要格式')  # 勾上为on,不勾不会传这个参数
        words = getp(request.GET.get('words'),
                     nullable=False,
                     para_intro='中文单词列表')

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        excel_filename = r'temp/%s.xls' % uuid.uuid1()
        result = get_pinyin_excel(words, excel_filename, has_hanzi)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)

    file = open(excel_filename, 'rb')
    response = HttpResponse(file)
    response['Content-Type'] = 'application/octet-stream'  #设置头信息,告诉浏览器这是个文件
    response['Content-Disposition'] = 'attachment;filename="quiz.xls"'
    return response
Example #4
0
def api_mod_user(request):
    log_request(request)
    try:
        user_id = getp(request.POST.get("user_id"), u"用户ID", nullable=False)
        username = getp(request.POST.get("username"), u"用户名", nullable=True, default='')  # 暂不允许修改用户名,修改用户视为删除旧用户,增加新用户,但你非要改我也能支持liukai
        name = getp(request.POST.get("name"), u"名称", nullable=False)
        sex = getp(request.POST.get("sex"), u"性别", nullable=False)
        # area_name = getp(request.POST.get("area_name"), u"地区", nullable=False)
        # current_user_id = getp(request.POST.get("current_user_id"), u'当前用户', nullable=False)
        # manage_direct = getp(request.POST.get("manage_direct"), u"直属标志", nullable=True)

        area_id = getp(request.POST.get("area_id"), u"区域ID", nullable=True)
        direct_area_id = getp(request.POST.get("direct_area_id"), u"哪一个区域直属", nullable=True)
        institution = getp(request.POST.get("institution"), u"组织名称", nullable=True)
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)

    try:
        result = services.mod_user(request.user, user_id, username, name, sex, area_id, direct_area_id, institution)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #5
0
def api_list_expert_user(request):
    log_request(request)
    try:
        # cur_user_id = getp(request.POST.get("cur_user_id"), u"当前用户的id", nullable=False)
        name = getp(request.POST.get("name"), u"姓名", nullable=True)
        area_id = getp(request.POST.get("area_id"), u"地域id", nullable=True)
        manage_direct = getp(request.POST.get("manage_direct"),
                             u"直属标志",
                             nullable=True)
        is_show_store = getp(request.POST.get("is_show_store"),
                             u"是否在专家库显示",
                             nullable=True)
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.list_expert_user(request.user, None, name, area_id,
                                           manage_direct, is_show_store)
        # result = paging_with_request(request, result)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    if result['c'] == SUCCESS[0]:
        result = paging_with_request(request, result)
    log_response(request, result)
    return response200(result)
Example #6
0
def api_delete_expert_user(request):
    log_request(request)
    try:
        cur_user_id = getp(request.POST.get("cur_user_id"), u"当前用户的id")
        expert_id_list = getp(request.POST.get("expert_id_list"),
                              u"专家的id列表",
                              nullable=True)
        name = getp(request.POST.get("name"), u"姓名", nullable=True)
        area_id = getp(request.POST.get("area_id"), u"地域id", nullable=True)
        manage_direct = getp(request.POST.get("manage_direct"),
                             u"直属标志",
                             nullable=True)
        del_all_expert = getp(request.POST.get("del_all_expert"),
                              u"是否删除所有专家",
                              nullable=True)

    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.delete_expert_user(request.user, cur_user_id,
                                             expert_id_list, name, area_id,
                                             manage_direct, del_all_expert)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #7
0
def api_login(request):
    log_request(request)
    try:
        username = getp(request.POST.get("username"), u"用户名", nullable=True)
        password = getp(request.POST.get("password"), u"密码", nullable=True)
        confirm_code = getp(request.GET.get('confirm_code'),
                            nullable=True,
                            para_intro='用户确认码')
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        if confirm_code:
            # 如果传了confirm_code则直接用确认码进行登陆
            if services.api_confirmcode_login(request, confirm_code):
                return response200({"c": SUCCESS[0], "m": SUCCESS[1]})
            else:
                return response200({
                    "c": ERR_LOGIN_FAIL[0],
                    "m": ERR_LOGIN_FAIL[1]
                })

        if services.login(request, username=username, password=password):
            result = {"c": SUCCESS[0], "m": SUCCESS[1]}
            log_response(request, result)
            response = response200(result)
            return response
        else:
            result = {"c": ERR_LOGIN_FAIL[0], "m": ERR_LOGIN_FAIL[1]}
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #8
0
def wx_update_scan_status(request):
    """
    功能说明: 更新用户扫码状态
    """
    log_request(request)
    try:
        confirm_code = getp(request.GET.get('confirm_code'),
                            nullable=False,
                            para_intro='用户确认码')
        confirm_status = getp(request.GET.get('confirm_status'),
                              nullable=False,
                              para_intro='用户确认状态')

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        result = agents.wx_update_scan_status(request, confirm_code,
                                              confirm_status)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Example #9
0
def api_get_area_onhome(request):
    log_request(request)
    try:
        result = services.get_area_onhome()
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #10
0
def api_logout(request):
    log_request(request)
    try:
        logout(request)
        response = response200(dict(c=SUCCESS[0], m=SUCCESS[1]))
        response.delete_cookie('account')
        return response
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex)
Example #11
0
def api_check_username(request):
    log_request(request)
    try:
        username = getp(request.POST.get("username"), u"用户名", nullable=False)
    except InvalidHttpParaException as ex:
        return response_parameter_error(ex)
    try:
        result = services.check_username(request.user, username)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #12
0
def api_get_current_user(request):
    log_request(request)
    try:
        area_id = getp(request.POST.get("area_id"), u"地域的id", nullable=True)
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.get_current_user(request.user, area_id)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #13
0
def api_display_expert(request):
    log_request(request)
    try:
        area_id = getp(request.POST.get("area_id"), u"地域id")
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.display_expert(request.user, area_id)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #14
0
def get_weixin_global_access_token(request):
    log_request(request)
    weixin_define_code = request.GET.get("weixin_define_code", "")
    weixin_app_id = request.GET.get("appid", "")

    try:
        weixindefine = get_weixin_define(weixin_define_code, weixin_app_id)
        cur_access_token = agents.get_weixin_global_access_token(weixindefine)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, cur_access_token)

    return response200(cur_access_token)
Example #15
0
def api_reset_own_password(request):
    log_request(request)
    try:
        old_password = getp(request.POST.get('old_password'), u"原密码")
        new_password = getp(request.POST.get('new_password'), u"新密码")
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.reset_own_password(user=request.user, old_password=old_password, new_password=new_password)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #16
0
def api_get_activity_user(request):
    # 查询某活动中,用户的角色。
    log_request(request)
    try:
        activity_id = getp(request.POST.get("activity_id"), u"活动id", nullable=False)
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.api_get_activity_user(request.user, activity_id)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Example #17
0
def api_config_user(request):
    log_request(request)
    try:
        account_id = getp(request.POST.get("account_id"), u"account_id", nullable=False)
        activity_mask = getp(request.POST.get("activity_mask"), u"可配置的活动掩码", nullable=False)
        area_id = getp(request.POST.get("area_id"), u"创建活动的区域id", nullable=False)
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.config_user(request.user, account_id, activity_mask, area_id)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #18
0
def api_qry_area_dropdowndetail(request):
    log_request(request)
    try:
        area_id = getp(request.POST.get("area_id"), u"地区id", nullable=False)

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        result = services.api_qry_area_dropdowndetail(request.user, area_id)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Example #19
0
def api_del_account_right(request):
    log_request(request)
    try:
        ids = getp(request.POST.get('ids'), nullable=False, para_intro='ids')  # 英文半角逗号分隔

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        result = services.api_del_account_right(request, ids)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Example #20
0
def api_send_smsverifycode(request):
    log_request(request)
    try:
        mobile = getp(request.POST.get('mobile'), nullable=False, para_intro='电话号码')

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        result = services.api_send_smsverifycode(request.user, mobile)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Example #21
0
def api_update_area_fullname(request):
    log_request(request)
    try:
        area_id = getp(request.POST.get('area_id'), nullable=True, para_intro='地区id', default='')

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        result = services.api_update_area_fullname(area_id)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Example #22
0
def api_add_expert_user(request):
    """
    添加专家用户。一般此接口只有其它接口调用,前端不会直接调用。
    当前逻辑为任何用户可以随意添加专家,也可以添加任意地区的专家。
    :param request:
    :return:
    """
    log_request(request)
    try:
        # cur_user_id = getp(request.POST.get("cur_user_id"), u"当前用户id")
        username = getp(request.POST.get("username"), u"用户名")
        name = getp(request.POST.get("name"), u"姓名")
        sex = getp(request.POST.get("sex"), u"性别")
        # area_name = getp(request.POST.get("area_name"), u"地域名称", nullable=True)
        institution = getp(request.POST.get("institution"),
                           u"组织名称",
                           nullable=True)
        # manage_direct = getp(request.POST.get("manage_direct"), u"直属标志", nullable=True)
        area_id = getp(request.POST.get("area_id"), u"区域ID", nullable=True)
        direct_area_id = getp(request.POST.get("direct_area_id"),
                              u"哪一个区域直属",
                              nullable=True)

        image_id = getp(request.POST.get("image_id", ""),
                        u"头像图片",
                        nullable=True)
        position = getp(request.POST.get("position", ""),
                        u"职位信息",
                        nullable=True)
        introduction = getp(request.POST.get("introduction", ""),
                            u"个人介绍",
                            nullable=True)

    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.add_expert_user(request.user, username, name, sex,
                                          institution, image_id, position,
                                          introduction, area_id,
                                          direct_area_id)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #23
0
def api_add_account_right(request):
    log_request(request)
    try:
        account_id = getp(request.POST.get('account_id'), nullable=False, para_intro='帐户ID')
        area_id = getp(request.POST.get('area_id'), nullable=False, para_intro='地区ID')

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        result = services.api_add_account_right(request, account_id, area_id)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Example #24
0
def api_reset_others_password(request):
    log_request(request)
    try:
        account_id = getp(request.POST.get('account_id'), u"用户id", nullable=False)
        admin_password = getp(request.POST.get('admin_password'), u"管理员密码")
        new_password = getp(request.POST.get('new_password'), u"新密码")
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.reset_others_password(user=request.user, account_id=account_id, admin_password=admin_password,
                                                new_password=new_password)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #25
0
def api_detail_account(request):
    log_request(request)
    try:
        result = services.detail_account(request.user)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    un = json.dumps(result, ensure_ascii=False)
    # response.set_cookie("username", un) # UnicodeEncodeError!
    un2 = un.encode('utf8')
    import base64
    un3 = base64.b64encode(un)
    # 向cookie中写入用户资料,避免前端重复查询。
    response = response200(dict(c=SUCCESS[0], m=SUCCESS[1], d=[result]))
    response.set_cookie('account', un3, max_age=SESSION_COOKIE_AGE)
    log_response(request, result)
    return response
Example #26
0
def api_list_sub_area(request):
    log_request(request)
    try:
        cur_user_id = getp(request.POST.get('cur_user_id'), u"当前用户的id", nullable=True)
        area_id = getp(request.POST.get("area_id"), u"地域id", nullable=True)
        manage_direct = getp(request.POST.get("manage_direct"), u"直属标志", nullable=True)  # 1只查直属,0只查非直属,不传或传空则不限制。
        area_name = getp(request.POST.get("area_name"), u"区域名称", nullable=True)  # 过滤条件,模糊匹配
        is_school = getp(request.POST.get("is_school"), u"是否学校", nullable=True)  # 1只查学校,0只查非学校,不传或传空则不限制。
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.list_sub_area(request.user, cur_user_id, area_id, manage_direct, area_name, is_school)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #27
0
def api_reset_forget_password(request):
    log_request(request)
    try:
        mobile = getp(request.POST.get('mobile'), nullable=False, para_intro='电话号码')
        smscode = getp(request.POST.get('smscode'), nullable=False, para_intro='短信验证码')
        new_password = getp(request.POST.get('new_password'), nullable=False, para_intro='新密码')

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        result = services.api_reset_forget_password(request.user, mobile, smscode, new_password)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Example #28
0
def api_add_account(request):
    log_request(request)
    try:
        username = getp(request.POST.get("username"), u"用户名", nullable=False)
        name = getp(request.POST.get("name"), u"姓名", nullable=False)
        sex = getp(request.POST.get("sex"), u"性别", nullable=False)
        activity_mask = getp(request.POST.get("activity_mask"), u"创建活动的掩码", nullable=True)
        area_id = getp(request.POST.get("area_id"), u"区域的id", nullable=True)
    except InvalidHttpParaException as ex:
        logger.exception(ex)
        return response_parameter_error(ex)
    try:
        result = services.add_account(request.user, username, name, sex, activity_mask, area_id)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Example #29
0
def api_qry_institution_reg(request):
    log_request(request)
    try:
        cur_user_id = getp(request.POST.get("cur_user_id"), u"当前用户id", nullable=False)
        rows = getp(request.GET.get('rows'), nullable=True, para_intro='一次返回最大行数')
        page = getp(request.GET.get('page'), nullable=True, para_intro='页码')
        last_id = getp(request.GET.get('last_id'), nullable=True, para_intro='最后id')

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        result = services.api_qry_institution_reg(request.user, cur_user_id, rows, page, last_id)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Example #30
0
def api_list_account(request):
    log_request(request)
    try:
        name_or_mobile = getp(request.GET.get('name_or_mobile'), nullable=False, para_intro='姓名或手机号')
        rows = getp(request.GET.get('rows'), nullable=True, para_intro='一次返回最大行数')
        page = getp(request.GET.get('page'), nullable=True, para_intro='页码')
        last_id = getp(request.GET.get('last_id'), nullable=True, para_intro='最后id')

    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)

    try:
        result = services.api_list_account(request, name_or_mobile, rows, page, last_id)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    log_response(request, result)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})