def role_detail(request, pk): """ 角色列表细节 :param pk: :param request: :return: """ if request.method == "GET": username = request.user.username request_data = request.GET permission, msg = admin_permission_check(username) if not permission: return api_response(0, "非管理员用户", '') per_page = request_data.get('per_page', 10) page = request_data.get('page', 1) restful_result_role, msg = AccountBaseService.get_role_detail(role_id=pk, per_page=per_page, page=page) if not restful_result_role: return api_response(0, msg, '') else: return api_response(1, '', restful_result_role) else: return redirect('/')
def account_change(request): username = request.user.username user_obj = get_object_or_404(User, username=username) if request.method == 'POST': user_data_dict = json.loads(request.body.decode('utf-8')) form = AccountChangeForm(user_data_dict) if form.is_valid(): user_obj.alias = form.cleaned_data['alias'] user_obj.email = form.cleaned_data['email'] user_obj.phone = form.cleaned_data['phone'] user_obj.job_number = form.cleaned_data['job_number'] user_obj.dept_id = form.cleaned_data['dept_id'] user_obj.save() form_dict = {'username': username, 'alias': user_obj.alias, 'email': user_obj.email, 'phone': user_obj.phone, 'job_number': user_obj.job_number, 'dept_id': user_obj.dept_id} return api_response(1, "", form_dict) else: error = form.errors return api_response(0, "用户信息填写有误, 请修改后重新填写", error) else: user_restful_detail, msg = AccountBaseService.get_user_detail(user_id=user_obj.id) return api_response(1, '', user_restful_detail)
def dept_list(request): """ 部门列表 :param request: :return: """ if request.method == "GET": username = request.user.username request_data = request.GET permission, msg = admin_permission_check(username) if not permission: return api_response(0, "非管理员用户", '') dept_name = request_data.get('dept', '') per_page = request_data.get('per_page', 10) page = request_data.get('page', 1) dept_restful_list, msg = AccountBaseService.get_dept_list(dept_name, per_page, page) if dept_restful_list is False: return api_response(0, msg, '') else: data = dict(value=dept_restful_list, per_page=msg['per_page'], page=msg['page'], total=msg['total']) return api_response(1, '', data) else: return redirect('/')
def post(self, request, *args, **kwargs): """ 修改工单状态 :param request: :param args: :param kwargs: :return: """ # json_str = request.body.decode('utf-8') # request_data_dict = request.POST.dict() request_data_dict = json.loads(request.body.decode('utf-8')) if not request_data_dict: return api_response(0, "post 参数为空", {}) # request_data_dict = json.loads(json_str) ticket_id = kwargs.get('pk', '') username = request.user.username state_id = request_data_dict.get('state_id', '') if not username: return api_response(0, "参数不全, 请提供username", '') if not state_id: code, msg = 0, "请提供新的状态id" data = '' else: result, msg = TicketBaseService.update_ticket_state(ticket_id, state_id, username) if result: code, msg, data = 1, msg, '' else: code, msg, data = 0, msg, '' return api_response(code, msg, data)
def post(self, request, *args, **kwargs): """ 转单操作, 直接修改工单处理人, 且工单状态不变, :param request: :param args: :param kwargs: :return: """ # json_str = request.body.decode('utf-8') # request_data_dict = request.POST.dict() request_data_dict = json.loads(request.body.decode('utf-8')) if not request_data_dict: return api_response(0, "post 参数为空", {}) # request_data_dict = json.loads(json_str) ticket_id = kwargs.get('pk', '') # username = request_data_dict.get('username', '') username = request.user.username target_username = request_data_dict.get('target_username', '') suggestion = request_data_dict.get('suggestion', '') result, msg = TicketBaseService.deliver_ticket(ticket_id, username, target_username, suggestion) if result: code, msg, data = 1, msg, result else: code, msg, data = 0, msg, '' return api_response(code, msg, data)
def post(self, request, *args, **kwargs): """ 处理工单 :param request: :param args: :param kwargs: :return: """ # json_str = request.body.decode('utf-8') # request_data_dict = request.POST.dict() request_data_dict = json.loads(request.body.decode('utf-8')) request_data_dict['username'] = request.user.username request_data_dict['modifier'] = request.user.username if not request_data_dict: return api_response(0, "patch参数为空", {}) # request_data_dict = json.loads(json_str) ticket_id = kwargs.get('pk', '') if not ticket_id: return api_response(0, "请提供工单id", {}) result, msg = TicketBaseService.handle_ticket(ticket_id, request_data_dict) if result is False: code, data = 0, '' else: code, data = 1, dict(value=result) return api_response(code, msg, data)
def user_detail(request, pk): """ 管理员查看用户信息 :param request: :param pk: :return: """ if request.method == "GET": user = request.user.username permission, msg = admin_permission_check(user) if not permission: return api_response(0, "非管理员用户", '') user_restful_detail, msg = AccountBaseService.get_user_detail(user_id=pk) return api_response(1, '', user_restful_detail) elif request.method == "POST": user = request.user.username permission, msg = admin_permission_check(user) if not permission: return api_response(0, "非管理员用户", '') user_obj = get_object_or_404(User, username=user) user_data_dict = json.loads(request.body.decode('utf-8')) form = AccountChangeForm(user_data_dict) if form.is_valid(): user_obj.alias = form.cleaned_data['alias'] user_obj.email = form.cleaned_data['email'] user_obj.phone = form.cleaned_data['phone'] user_obj.job_number = form.cleaned_data['job_number'] user_obj.dept_id = form.cleaned_data['dept_id'] user_obj.is_active = form.cleaned_data['is_active'] user_obj.is_admin = form.cleaned_data['is_admin'] user_obj.is_viewer = form.cleaned_data['is_viewer'] user_obj.save() form_dict = {'username': user, 'alias': user_obj.alias, 'email': user_obj.email, 'phone': user_obj.phone, 'job_number': user_obj.job_number, 'dept_id': user_obj.dept_id, 'is_active': user_obj.is_active, 'is_viewer': user_obj.is_viewer, 'is_admin': user_obj.is_admin} return api_response(1, "用户信息修改成功", form_dict) else: error = form.errors return api_response(0, "用户信息填写有误, 请修改后重新填写", error) else: return redirect('/')
def get(self, request, *args, **kwargs): request_data = request.GET ticket_id = kwargs.get('pk', '') username = request.user.username if not username: return api_response(0, "参数补全, 请提供 username", '') result, msg = TicketBaseService.get_ticket_transition(ticket_id, username) if result is False: code, data = 0, '' else: code, data = 1, dict(value=result) return api_response(code, msg, data)
def get(self, request, *args, **kwargs): request_data = request.GET ticket_id = kwargs.get('pk', '') username = request.user.username if not username: return api_response(0, "参数不全, 请提供username", '') result, msg = TicketBaseService.get_ticket_flow_step(ticket_id, username) if result: data = dict(value=result) code = 1 else: code, data = 0, '' return api_response(code, msg, data)
def post(self, request, *args, **kwargs): request_data_dict = json.loads(request.body.decode('utf-8')) if not request_data_dict: return api_response(0, "post 参数为空", "") pk = kwargs.get('pk', 0) username = request.user.username request_data_dict['username'] = username ocable_result, msg = OcableSectionBaseService.change_ocable_section( pk, request_data_dict) if ocable_result is False: code, data = 0, '' else: code, data = 1, ocable_result return api_response(code, msg, data)
def get(self, request, *args, **kwargs): """ 获取在用电路列表 :param request: :param args: :param kwargs: :return: """ request_data = request.GET request_params = dict( project_name=request_data.get('project_name', ''), name_az=request_data.get('name_az', ''), # name_Z=request_data.get('name_Z', ''), circuit_num=request_data.get('circuit_num', ''), state=request_data.get('state', ''), sn=request_data.get('sn', ''), reverse=int(request_data.get('reverse', 1)), per_page=int(request_data.get('per_page', 10)), page=int(request_data.get('page', 1))) using_circuit_result_restful_list, msg = UsingCircuitBaseService.get_using_circuit_list( **request_params) if using_circuit_result_restful_list is False: code, data = 0, '' else: data = dict(value=using_circuit_result_restful_list, per_page=msg['per_page'], page=msg['page'], total=msg['total']) code, msg = 1, '' return api_response(code, msg, data)
def get(self, request, *args, **kwargs): """ 获取工作流列表 :param request: :param args: :param kwargs: :return: """ request_data = request.GET workflow_name = request_data.get('name', '') username = request.user.username per_page = int(request_data.get('per_page', 10)) page = int(request_data.get('page', 1)) workflow_result_restful_list, msg = WorkflowBaseService.get_workflow_list( workflow_name, page, per_page) if workflow_result_restful_list is not False: data = dict(value=workflow_result_restful_list, per_page=msg['per_page'], page=msg['page'], total=msg['total']) code, msg = 1, '' else: code, data = 0, '' return api_response(code, msg, data)
def get(self, request, *args, **kwargs): """ 获取状态详情 :param request: :param args: :param kwargs: :return: """ workflow_id = kwargs.get('pk', '') request_data = request.GET per_page = request_data.get('per_page', 10) page = request_data.get('page', 1) result, msg = WorkflowStateService.get_restful_state_list_by_id( workflow_id, per_page, page) if result is False: code, data = 0, '' else: code, data = 1, dict(value=result, per_page=msg['per_page'], page=msg['page'], total=msg['total']) msg = '' return api_response(code, msg, data)
def get(self, request, *args, **kwargs): """ 获取楼栋机房信息列表 :param request: :param args: :param kwargs: :return: """ request_data = request.GET building = request_data.get('building', '') room = request_data.get('room', '') description = request_data.get('description', '') room_id = int(request_data.get('room_id', 0)) reverse = int(request_data.get('reverse', 0)) per_page = int(request_data.get('per_page', 10)) page = int(request_data.get('page', 1)) building_room_result_restful_list, msg = BuildingRoomBaseService.get_building_room_list( building=building, room=room, room_id=room_id, description=description, reverse=reverse, per_page=per_page, page=page) data = {} if building_room_result_restful_list is False: code, msg = 0, msg else: data = dict(value=building_room_result_restful_list, per_page=msg['per_page'], page=msg['page'], total=msg['total']) code, msg = 1, '' return api_response(code, msg, data)
def password_change(request): """ :param request: :return: """ if request.method == 'POST': user_data_dict = json.loads(request.body.decode('utf-8')) form = PasswordChangeForm(user=request.user, data=user_data_dict) if form.is_valid(): form.save() update_session_auth_hash(request, form.user) return api_response(1, "密码修改成功, 请重新登陆", '') else: error = form.errors return api_response(0, error, '') else: return redirect('/')
def logout(request): """ :param request: :return: """ _logout(request) return api_response(1, "用户已注销", '')
def get_token(request): """ 获取 csrf token :param request: :return: """ token = csrf.get_token(request) return api_response(1, 'get_token', token)
def login(request): if request.user.is_authenticated: return redirect('/') if request.method == 'POST': user_data_dict = json.loads(request.body.decode('utf-8')) username = user_data_dict.get('username', '') password = user_data_dict.get('password', '') user = authenticate(request, username=username, password=password) if user is not None: _login(request, user) return api_response(1, "用户已经登陆", username) else: return api_response(0, "用户名与密码不匹配, 请修改后再尝试连接", '') else: return api_response(0, "请输入用户名与密码, 然后登陆", '')
def get(self, request, *args, **kwargs): request_data = request.GET ticket_id = kwargs.get('pk', '') username = request.user.username per_page = int(request_data.get('per_page', 10)) page = int(request_data.get('page', 1)) if not username: return api_response(0, "参数补全, 请提供 username", '') result, msg = TicketBaseService.get_ticket_flow_log(ticket_id, per_page, page) if result: data = dict(value=result, per_page=msg['per_page'], page=msg['page'], total=msg['total']) code, msg = 1, '' else: code, data = 0, '' return api_response(1, msg, data)
def post(self, request, *args, **kwargs): """ 新建光缆段 :param request: :param args: :param kwargs: :return: """ request_data_dict = json.loads(request.body.decode('utf-8')) if not request_data_dict: return api_response(0, "post 参数为空", "") request_data_dict['username'] = request.user.username create_result, msg = OcableSectionBaseService.new_ocable_section( request_data_dict) if create_result is False: code, data = 0, '' else: code, data = 1, create_result return api_response(code, msg, data)
def role_members(request, pk): if request.method == "POST": username = request.user.username request_data_dict = json.loads(request.body.decode('utf-8')) permission, msg = admin_permission_check(username) if not permission: return api_response(0, "非管理员用户", '') user_info = request_data_dict.get('user', '') command = request_data_dict.get('command', '') deal_result, msg = AccountBaseService.deal_role_members(role_id=pk, user_info=user_info, command=command) if deal_result is False: return api_response(0, msg, '') else: return api_response(1, '', deal_result) else: return redirect('/')
def post(self, request, *args, **kwargs): """ 删除工单,因为不想彻底清除工单记录,只是将删除字段置为0 :param request: :param args: :param kwargs: :return: """ request_data_dict = request.POST.dict() if not request_data_dict: return api_response(0, "post 参数为空", "") username = request.user.username delete_str = request_data_dict.get('delete_str', '') result, msg = TicketBaseService.ticket_delete(username, delete_str) if result: code, msg, data = 1, msg, result else: code, msg, data = 0, msg, '' return api_response(code, msg, data)
def get(self, request, *args, **kwargs): request_data = request.GET username = request.user.username pk = kwargs.get('pk', 0) ocable_detail, msg = OcableSectionBaseService.get_ocable_section_detail( username, pk) if ocable_detail is False: code, data = 0, '' else: code, data = 1, ocable_detail return api_response(code, msg, data)
def get(self, request, *args, **kwargs): """ 获取工单详情, 根据用户返回不同的内容 :param request: :param args: :param kwargs: :return: """ request_data = request.GET ticket_id = kwargs.get('pk') username = request.user.username if not username: return api_response(-1, "参数补全, 请提供username", '') result, msg = TicketBaseService.get_ticket_detail(ticket_id, username) if result is False: code, data = 0, '' else: code, data = 1, result return api_response(code, msg, data)
def post(self, request, *args, **kwargs): """ 接单操作 :param request: :param args: :param kwargs: :return: """ # json_str = request.body.decode('utf-8') request_data_dict = request.POST.dict() if not request_data_dict: return api_response(0, "post参数为空", {}) # request_data_dict = json.loads(json_str) ticket_id = kwargs.get('pk', '') username = request.user.username result, msg = TicketBaseService.accept_ticket(ticket_id, username) if result: code, msg, data = 1, msg, result else: code, msg, data = 0, msg, '' return api_response(code, msg, data)
def register(request): # get 请求中,next 通过 url 传递,即 /?next=value # post 请求中,next 通过表单传递,即 <input type="hidden" name="next" value="{{ next }}"/> # redirect_to = request.POST.get('next', request.GET.get('next', '')) if request.method == 'POST': user_data_dict = json.loads(request.body.decode('utf-8')) form = RegisterForm(user_data_dict) if form.is_valid(): form.save() return api_response(1, "用户注册成功", {"username": form.cleaned_data['username']}) # if redirect_to: # return redirect(redirect_to) # else: # return redirect('/') else: error = form.errors return api_response(0, "用户信息填写有误, 请修改后重新填写", error) else: return api_response(0, "用户信息填写有误, 请修改后重新填写", '')
def get(self, request, *args, **kwargs): """ 获取工作流初始状态, 包括状态详情以及允许的transition :param request: :param args: :param kwargs: :return: """ workflow_id = kwargs.get('pk', '') request_data = request.GET username = request.user.username if not workflow_id: return api_response(0, "请提供工作流id", '') state_result, msg = WorkflowStateService.get_workflow_init_state( workflow_id) if state_result is False: code, msg, data = 0, msg, '' else: code, msg, data = 1, msg, state_result return api_response(code, msg, data)
def get(self, request, *args, **kwargs): """ 获取纤芯(视图)列表 :param request: :param args: :param kwargs: :return: """ request_data = request.GET ocable_section_id = request_data.get('ocable_section_id', '') # ocable_odf_A = request_data.get('ocable_odf_A', '') # switch_dport_A = request_data.get('switch_dport_A', '') # ocable_odf_Z = request_data.get('ocable_odf_Z', '') # switch_dport_Z = request_data.get('switch_dport_Z', '') ocable_odf = request_data.get('ocable_odf', '') switch_dport = request_data.get('switch_dport', '') ocable_cor = request_data.get('ocable_cor', '') core_quality = request_data.get('core_quality', '') circuit_num = request_data.get('circuit_num', '') occ_business = request_data.get('occ_business', '') sn = request_data.get('sn', '') building = request_data.get('building', 0) room = request_data.get('room', 0) reverse = int(request_data.get('reverse', 0)) per_page = int(request_data.get('per_page', 10)) page = int(request_data.get('page', 1)) ofiber_core_result_restful_list, msg = OfiberCoreBaseService.get_ofiber_core_list( ocable_section_id=ocable_section_id, ocable_odf=ocable_odf, switch_dport=switch_dport, ocable_cor=ocable_cor, core_quality=core_quality, circuit_num=circuit_num, occ_business=occ_business, sn=sn, building=building, room=room, reverse=reverse, per_page=per_page, page=page) data = {} if ofiber_core_result_restful_list is False: code, msg = 0, msg else: data = dict(value=ofiber_core_result_restful_list, per_page=msg['per_page'], page=msg['page'], total=msg['total']) code, msg = 1, '' return api_response(code, msg, data)
def post(self, request, *args, **kwargs): """ 加签处理完成,加签完成操作后工单处理人回回到之前加签发起人 :param request: :param args: :param kwargs: :return: """ # json_str = request.body.decode('utf-8') # request_data_dict = request.POST.dict() request_data_dict = json.loads(request.body.decode('utf-8')) if not request_data_dict: return api_response(0, "post参数为空", {}) # request_data_dict = json.loads(json_str) ticket_id = kwargs.get('pk') username = request.user.username suggestion = request_data_dict.get('suggestion', '') result, msg = TicketBaseService.add_node_ticket_end(ticket_id, username, suggestion) if result: code, msg, data = 1, msg, result else: code, msg, data = 0, msg, '' return api_response(code, msg, data)
def role_delete(request): """ 删除角色 :param request: :return: """ if request.method == "POST": user = request.user.username request_data_dict = json.loads(request.body.decode('utf-8')) permission, msg = admin_permission_check(user) if not permission: return api_response(0, "非管理员用户", '') role_id = request_data_dict.get('role_id', '') if not role_id: return api_response(0, "请提供角色id", '') delete_result, msg = AccountBaseService.role_delete(role_id=role_id) if not delete_result: return api_response(0, msg, '') else: return api_response(1, msg, delete_result) else: return redirect('/')