Beispiel #1
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)
Beispiel #2
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))
Beispiel #3
0
def api_list_team(request, para):
    try:
        subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first()
        if not subjudge:
            raise BusinessException(ERR_SUBJUDGE_NOT_EXIST)
        # 仅子级评审的维护者可使用
        if not subjudge_services.is_subjudge_manager(subjudge, request.user):
            raise BusinessException(ERR_USER_AUTH)
        result = subjudge_services.list_team(subjudge, para.keyword,
                                             para.judger, para.rows, para.page)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Beispiel #4
0
def api_update_team_expert(request, para):
    try:
        subjudge_team = SubJudgeTeam.objects.filter(
            id=int(para.subjudge_team)).first()
        if not subjudge_team:
            raise BusinessException(ERR_SUBJUDGE_TEAM_NOT_EXIST)

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

        result = subjudge_services.update_team_expert(subjudge_team, para.data)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Beispiel #5
0
def api_remove_expert(request, para):
    try:
        subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first()
        if not subjudge:
            raise BusinessException(ERR_SUBJUDGE_NOT_EXIST)

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

        expert_id_list = [int(each) for each in seq2list(para.expert_id_list)]
        result = subjudge_services.remove_expert(request.user, subjudge,
                                                 expert_id_list)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    return response200(result)
Beispiel #6
0
def api_import_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)
        result = subjudge_services.import_expert(request.user, user, role,
                                                 subjudge, para.file)
    except Exception as ex:
        logger.exception(ex)
        return response_exception(ex, ex.message)
    return response200(dict(c=SUCCESS[0], m=SUCCESS[1], d=result))
Beispiel #7
0
def api_edit_team(request, para):
    try:
        subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first()
        if not subjudge:
            raise BusinessException(ERR_SUBJUDGE_NOT_EXIST)

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

        subjudge_team = SubJudgeTeam.objects.filter(
            id=int(para.subjudge_team)).first() if para.subjudge_team else None
        result = subjudge_services.edit_team(subjudge, subjudge_team,
                                             para.new_name)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Beispiel #8
0
def api_add_team_work(request, para):
    try:
        subjudge_team = SubJudgeTeam.objects.filter(
            id=int(para.subjudge_team)).first()
        if not subjudge_team:
            raise BusinessException(ERR_SUBJUDGE_TEAM_NOT_EXIST)

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

        work_id_list = [
            int(each)
            for each in para.work_id_list.strip().strip(',').split(',') if each
        ]
        result = subjudge_services.add_team_work(subjudge_team, work_id_list)
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
Beispiel #9
0
def api_subjudge_work_availale_add_team(request, para):
    try:
        subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first()
        if not subjudge:
            raise BusinessException(ERR_SUBJUDGE_NOT_EXIST)

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

        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)
        ignore_area_list = para.ignore_area_id.strip().strip(',').split(
            ',') if para.ignore_area_id else []

        result = subjudge_services.work_availale_add_team(
            request.user,
            subjudge,
            subjudge_team,
            para.sub_activity,
            para.phase,
            para.project,
            area,
            direct_area,
            para.subject,
            para.keyword,
            ignore_area_list,
            para.page,
            para.rows,
        )
    except Exception as e:
        logger.exception(e)
        return response_exception(e)
    return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})