Пример #1
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)
Пример #2
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)
Пример #3
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)
Пример #4
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})
Пример #5
0
def api_export_activity_expert(request, para):
    try:
        activity = Activity.objects.filter(id=int(para.activity_id)).first()
        if not activity:
            raise BusinessException(ERR_ACTIVITY_NOT_EXIST)
        user, role = get_user(activity, request.user)
        if not user:
            raise BusinessException(ERR_USER_AUTH)
        expert_id_list = [
            int(r) for r in para.expert_id_list.strip().strip(',').split(',')
        ]
        expert_list = Expert.objects.filter(del_flag=FALSE_INT,
                                            id__in=expert_id_list)
        wb = activity_s.export_activity_expert(request.user, activity, user,
                                               role, expert_list)

        fname = u'%s.xlsx' % suuid()
        response = HttpResponse(content_type='application/vnd.ms-excel')
        response[
            'Content-Disposition'] = 'attachment; filename=' + fname.encode(
                'utf-8')
        wb.save(response)
        return response

        # path = os.path.join(settings.BASE_DIR, 'media/%s.xlsx' % suuid())
        # wb.save(path)
        # return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': path})
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
Пример #6
0
def api_export_team(request, para):
    try:
        subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first()
        if not subjudge:
            raise BusinessException(ERR_SUBJUDGE_NOT_EXIST)
        user, role = get_user(subjudge.activity, request.user)
        if not user:
            raise BusinessException(ERR_USER_AUTH)
        # 仅子级评审的维护者可使用
        if not subjudge_services.is_subjudge_manager(subjudge, request.user):
            raise BusinessException(ERR_USER_AUTH)
        subjudge_team_id_list = [
            int(each)
            for each in para.subjudge_team_list.strip().strip(',').split(',')
            if each
        ]
        # team_list = list(Team.objects.filter(id__in=team_id_list))
        wb = subjudge_services.export_team(request.user, subjudge, user, role,
                                           subjudge_team_id_list)

        fname = u'%s.xlsx' % suuid()
        response = HttpResponse(content_type='application/vnd.ms-excel')
        response[
            'Content-Disposition'] = 'attachment; filename=' + fname.encode(
                'utf-8')
        wb.save(response)
        return response

        # path = os.path.join(settings.BASE_DIR, 'media/%s.xlsx' % suuid())
        # wb.save(path)
        # return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': path})
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex)
Пример #7
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})
Пример #8
0
def api_download_activity_role_template(request, para):
    try:
        activity = Activity.objects.filter(id=int(para.activity_id)).first()
        if not activity:
            raise BusinessException(ERR_ACTIVITY_NOT_EXIST)
        user, role = get_user(activity, request.user)
        if not user:
            raise BusinessException(ERR_USER_AUTH)
        wb = activity_s.download_activity_role_template(
            request.user, activity, user, role)

        fname = u'%s.xlsx' % suuid()
        response = HttpResponse(content_type='application/vnd.ms-excel')
        response[
            'Content-Disposition'] = 'attachment; filename=' + fname.encode(
                'utf-8')
        wb.save(response)
        return response

        # path = os.path.join(settings.BASE_DIR, 'media/%s.xlsx' % suuid())
        # wb.save(path)
        # return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': path})
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
Пример #9
0
def api_list_activity_create_area(request):
    try:
        result = activity_s.list_activity_create_area(request.user)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    return response200(result)
Пример #10
0
def api_common_title_list(request):
    try:
        result = title_list(request.user.school)
    except Exception as e:
        log_exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Пример #11
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)
Пример #12
0
def api_export_activity_user(request):
    try:
        cur_user_id = getp(request.POST.get("cur_user_id"), u"当前用户id", nullable=True)
        activity_id = getp(request.POST.get("activity_id"), u"活动的id", nullable=False)
        user_id_list = getp(request.POST.get("user_id_list"), u"用户ID列表", nullable=True, default=[])
        user_flag = getp(request.POST.get("user_flag"), u"被导入用户的标识(0:用户,1:专家)", nullable=True, default=0)
        name = getp(request.POST.get("name"), u"用户名", nullable=True)
        area_id = getp(request.POST.get("area_id"), u"区域ID", nullable=True)
        direct_level = getp(request.POST.get("direct_level"), u"直属等级(4:省直属,2市直属)", nullable=True)
        item_id_list = getp(request.POST.get("item_id_list"), u"查询的id列表,JSON", nullable=True)
        qry_all_user = getp(request.POST.get("qry_all_user"), u"是否查询全部用户", nullable=True)

        if user_id_list:
            account_id_list = json.loads(user_id_list)
        else:
            account_id_list = []

        result = services.export_activity_user(user=request.user, activity_id=activity_id, account_id_list=account_id_list,
                                               name=name, user_flag=user_flag, area_id=area_id, cur_user_id=cur_user_id, direct_level=direct_level,
                                               item_id_list=item_id_list, qry_all_user=qry_all_user)
        if result["c"] != ERR_SUCCESS[0]:
            return response200(result)
        file_path = result["d"]
        response = gen_file_reponse(file_path)
        return response

    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
Пример #13
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)
Пример #14
0
def api_subjudge_export_work_for_leader(request, para):
    try:
        subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first()
        if not subjudge:
            raise BusinessException(ERR_SUBJUDGE_NOT_EXIST)
        subj_expert = SubJudgeExpert.objects.filter(
            subjudge=subjudge,
            expert__del_flag=FALSE_INT,
            expert__account=request.user).first()
        if not subj_expert:
            raise BusinessException(ERR_USER_AUTH)
        # TODO 验证必须是组长
        #

        work_id_list = [
            int(each)
            for each in para.work_id_list.strip().strip(',').split(',') if each
        ]
        work_list = list(Work.objects.filter(id__in=work_id_list))

        # TODO check auth for these work
        #

        resp = WorkExcelExport(subjudge.activity, work_list,
                (EXCEL.BASIC, EXCEL.AUTHOR, EXCEL.TUTOR, EXCEL.SUBJG_MY_SCORE, EXCEL.SUBJG_SCORE), expert=subj_expert.expert, subjudge=subjudge)\
                .write().dump_stream()
        return resp
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
Пример #15
0
def api_subjudge_list_work_for_expert(request, para):
    try:
        subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first()
        if not subjudge:
            raise BusinessException(ERR_SUBJUDGE_NOT_EXIST)
        subjg_team = SubJudgeTeam.objects.filter(
            id=int(para.subjudge_team)).first() if para.subjudge_team else None
        subjg_expert = SubJudgeExpert.objects.filter(
            subjudge=subjudge, expert__account=request.user).first()
        if not subjg_expert:
            raise BusinessException(ERR_USER_AUTH)
        result = subjudge_services.list_work_for_expert(
            request.user,
            subjudge,
            subjg_expert,
            para.sub_activity,
            para.phase,
            para.project,
            para.subject,
            para.keyword,
            subjg_team,
            para.is_unfinish,
            para.page,
            para.rows,
        )
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Пример #16
0
def api_group_create(request):
    if getattr(request, 'limited', False):
        return net_helper.response_ratelimit()
    try:
        group_name = get_parameter(request.POST.get('group_name'),
                                   para_intro=u'群组名称')
        invite_users = get_parameter(request.POST.get('invite_users'),
                                     allow_null=True,
                                     default='')
    except InvalidHttpParaException as ihpe:
        logger.exception(ihpe)
        return response_parameter_error(ihpe)
    try:
        # 仅支持教师操作群组
        if request.user.type != USER_TYPE_TEACHER:
            raise BusinessException(ONLY_TEACHER_CAN_HANDLE_GRP)
        new_grp = create_grp(group_name, request.user)
        invite_who = tools.cut_last_char(invite_users).split(';')
        invite_user(request.user, new_grp, invite_who)
        return net_helper.response200({
            'c': SUCCESS[0],
            'm': SUCCESS[1],
            'd': {
                'group_id': str(new_grp.id)
            }
        })
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
Пример #17
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
Пример #18
0
def api_new_expert(request, para):
    try:
        subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first()
        if not subjudge:
            raise BusinessException(ERR_SUBJUDGE_NOT_EXIST)
        user, role = get_user(subjudge.activity, request.user)
        if not user:
            raise BusinessException(ERR_USER_AUTH)

        # 仅子级评审的维护者可使用
        if not subjudge_services.is_subjudge_manager(subjudge, request.user):
            raise BusinessException(ERR_USER_AUTH)

        area = Area.objects.filter(del_flag=FLAG_NO, id=int(
            para.area_id)).first() if para.area_id else None
        direct_area = Area.objects.filter(
            del_flag=FLAG_NO, id=int(
                para.direct_area_id)).first() if para.direct_area_id else None
        result = subjudge_services.new_expert(request.user, subjudge, user,
                                              para.mobile, para.name, para.sex,
                                              area, direct_area,
                                              para.institution, para.position)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex)
    return response200(dict(c=SUCCESS[0], m=SUCCESS[1], d=result))
Пример #19
0
def api_subjudge_work_in_team(request, para):
    try:
        subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first()
        if not subjudge:
            raise BusinessException(ERR_SUBJUDGE_NOT_EXIST)
        area = Area.objects.filter(
            id=int(para.area_id)).first() if para.area_id else None
        direct_area = Area.objects.filter(id=int(
            para.direct_area_id)).first() if para.direct_area_id else None
        subjudge_team = SubJudgeTeam.objects.filter(
            id=int(para.subjudge_team)).first()
        if not subjudge_team:
            raise BusinessException(ERR_TEAM_EMPTY)
        result = subjudge_services.work_in_team(
            request.user,
            subjudge,
            subjudge_team,
            para.sub_activity,
            para.phase,
            para.project,
            area,
            direct_area,
            para.subject,
            para.keyword,
            para.page,
            para.rows,
        )
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Пример #20
0
def api_schooldisk_refreshspace(request):
    # 刷新当前用户的使用空间
    try:
        result = service.refresh_school_space(request.user.school)
    except Exception as e:
        log_exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Пример #21
0
def api_schooldisk_qrydir(request, para):
    # 查询文件夹名称
    try:
        result = service.api_schooldisk_qrydir(request.user, para["file_id"])
    except Exception as e:
        log_exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Пример #22
0
def api_list_activity(request, para):
    try:
        result = activity_s.all_activity(para.stages, para.is_home, para.level,
                                         para.rows, para.page)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    return response200(result)
Пример #23
0
def api_schooldisk_alldirsummary(request):
    # 获取所有文件夹摘要信息,
    try:
        result = service.api_schooldisk_alldirsummary(request.user)
    except Exception as e:
        log_exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Пример #24
0
def api_schooldisk_summary(request):
    # 查询用户网盘空间占用户情况
    try:
        result = service.api_schooldisk_summary(request.user)
    except Exception as e:
        log_exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Пример #25
0
def api_add_template(request, para):
    try:
        result = activity_s.add_template(request.user, para.from_activity_id,
                                         para.name)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    return response200(result)
Пример #26
0
def api_list_activity_category(request, para):
    try:
        result = activity_s.list_activity_category(request.user,
                                                   para.category_list)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    return response200(dict(c=SUCCESS[0], m=SUCCESS[1], d=result))
Пример #27
0
def api_get_area_byid(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_area_byid(area_id)
    except BusinessException as be:
        logger.exception(be)
        return response_exception(be)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    log_response(request, result)
    return response200(result)
Пример #28
0
def api_schooldisk_getuserfilerole(request, para):
    # 获取当前用户当前文件的权限,
    try:
        result = service.api_schooldisk_getuserfilerole(
            request.user, para["file_id"])
    except Exception as e:
        log_exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Пример #29
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)
Пример #30
0
def api_schooldisk_dirstatistics(request, para):
    # 获取文件夹统计信息,
    try:
        result = service.api_schooldisk_dirstatistics(request.user,
                                                      para["dir_file_id"])
    except Exception as e:
        log_exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})