def get_url(url, method, content, timeout): """ 通过netagent平台做代理,通过POST或GET方法请求某个URL :param url: URL地址 :param method: 请求方式GET/POST :param content: JSON参数字符串 :param timeout: 超时时间,字符串或数字,不传默认60秒 :return: """ payload = { 'pkg_name': 'applications.mail.services', 'function_name': 'api_get_url', 'parameter': json.dumps({ 'url': url, 'method': method, 'content': content, 'timeout': timeout, }, ensure_ascii=False) } try: logger.info('get url to netagent:') logger.info(str(payload).decode("unicode-escape")) remote_response = _mail_remote_call(payload) except Exception as e: logger.exception(e) return response200({'c': FAIL[0], 'm': FAIL[1], 'd': u'调用网络代理平台失败'}) logger.info('netagent return response:') logger.info(str(remote_response).decode("unicode-escape")) return remote_response
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})
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})
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})
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)
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})
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)
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))
def api_list_winner(request, para): try: result = activity_s.list_winner(request.user, para.activity_id, para.rows, para.page, para.last_id) except Exception as ex: logger.exception(ex) return response_exception(ex, ex.message) log_response(request, result) return response200(result)
def api_import_winner(request, para): try: result = activity_s.import_winner(request.user, para.activity_id, para.file) except Exception as ex: logger.exception(ex) return response_exception(ex, ex.message) log_response(request, result) return response200(result)
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})
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})
def api_common_setting_detail(request, para): try: # if para['key'] != SETTING_KEY_REVIEW_YEAR: # raise BusinessException(SETTING_KEY_WRONG) result = setting_detail(para['key'], request.user.school) except Exception as e: log_exception(e) return response_exception(e) return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
def api_schooldisk_getoatarget(request): """ 调用oa,获取oa的组织结构信息。 """ payload = { 'account_id': request.user.id, } try: logger.info('proxy to oa:') logger.info(payload) remote_response = service.api_oa_send_target(payload) except Exception as e: logger.exception(e) return response200({'c': FAIL[0], 'm': FAIL[1], 'd': u'调用OA平台失败'}) logger.info('oa return response:') logger.info(remote_response) return response200(remote_response)
def api_common_student_list(request, para): try: grade_num = para['grade'].grade_num if para['grade'] else None result = student_list(request.user.school, para['keyword'], grade_num, para['clazz']) except Exception as e: log_exception(e) return response_exception(e) return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
def api_persondisk_adddir(request, para): # 新增文件夹 try: result = service.api_persondisk_adddir(request.user, para["dir_name"], para["file_id"]) except Exception as e: log_exception(e) return response_exception(e) return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
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)
def api_detail_subjudge(request, para): try: subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first() if not subjudge: raise BusinessException(ERR_SUBJUDGE_NOT_EXIST) result = subjudge_services.detail_subjudge(subjudge) except Exception as e: logger.exception(e) return response_exception(e) return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
def api_list_expert_area_in_team(request, para): try: team = Team.objects.filter(id=int(para.team_id)).first() if not team: raise BusinessException(ERR_TEAM_NOT_EXIST) result = t_services.list_expert_area_in_team(request.user, team) except Exception as ex: logger.exception(ex) return response_exception(ex, ex.message) return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
def api_schooldisk_getdownloadurl(request, para): # 获取文件列表中的下载地址 try: result = service.api_schooldisk_getdownloadurl(request.user, para["file_id_list"], para["file_id_get_all"]) except Exception as e: log_exception(e) return response_exception(e) return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
def api_tag_alias(request, para): try: activity = Activity.objects.get(pk=int(para.activity_id)) if not activity: raise BusinessException(ERR_ACTIVITY_NOT_EXIST) result = activity_s.tag_alias(request.user, activity, para.tag) except Exception as ex: logger.exception(ex) return response_exception(ex, ex.message) return response200(dict(c=SUCCESS[0], m=SUCCESS[1], d=result))
def api_schooldisk_delfile(request, para): # 查询当前目录下所有文件夹/文件 try: result = service.api_schooldisk_delfile(request.user, para["file_id_list"], para["file_id_del_all"]) except Exception as e: log_exception(e) return response_exception(e) return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
def api_detail_work_attr_schema(request, para): activity = Activity.objects.filter(pk=int(para.activity_id)).first() if not activity: raise BusinessException(ERR_ACTIVITY_NOT_EXIST) try: result = activity_s.detail_work_attr_schema(activity) except Exception as ex: logger.exception(ex) return response_exception(ex, ex.message) return response200(result)
def api_edit_work_attr_schema_bulk(request, para): # 一次性更新三类活动信息 try: result = activity_s.edit_work_attr_schema_bulk(request.user, int(para.activity_id), para.bulk_list) except Exception as ex: logger.exception(ex) return response_exception(ex, ex.message) return response200(result)
def api_detail_ranks(request, para): try: activity = Activity.objects.filter(id=int(para.activity_id)).first() if not activity: raise BusinessException(ERR_ACTIVITY_NOT_EXIST) result = activity_s.detail_ranks(activity, request.user) except Exception as ex: logger.exception(ex) return response_exception(ex, ex.message) return response200(result)
def api_edit_rule(request, para): try: activity = Activity.objects.filter(id=para.activity_id).first() if not activity: raise BusinessException(ERR_ACTIVITY_NOT_EXIST) result = activity_s.edit_rule(request.user, activity, para.rule) except Exception as ex: logger.exception(ex) return response_exception(ex, ex.message) return response200(result)
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)
def api_edit_score(request, para): try: work = Work.objects.filter(id=int(para.work_id)).first() if not work: raise BusinessException(ERR_WORK_ID_ERROR) score_s.score(request.user, work, para.data, para.is_submit) except Exception as ex: logger.exception(ex) return response_exception(ex) return response200({'c': SUCCESS[0], 'm': SUCCESS[1]})
def api_persondisk_submitfile(request, para): # 查询当前目录下所有文件夹/文件 try: result = service.api_persondisk_submitfile(request.user, para["file_id"], para["file_obj_id_list"]) except Exception as e: log_exception(e) return response_exception(e) return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result})
def api_mobile_qrcode_info(request): try: result = get_mobile_qrcode() return net_helper.response200({ 'c': SUCCESS[0], 'm': SUCCESS[1], 'd': result }) except Exception as e: logger.exception(e) return response_exception(e)