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 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 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 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 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('/')
def dept_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, "非管理员用户", '') restful_result_dept, msg = AccountBaseService.get_dept_detail(dept_id=pk) if not restful_result_dept: return api_response(0, msg, '') else: return api_response(1, '', restful_result_dept) else: return redirect('/')
def user_list(request): """ 返回用户列表 :param request: :return: """ if request.method == "GET": user = request.user.username permission, msg = admin_permission_check(user) if not permission: return api_response(0, "非管理员用户", '') request_data = request.GET username = request_data.get('username', '') email = request_data.get('email', '') alias = request_data.get('alias', '') per_page = int(request_data.get('per_page', 10)) page = int(request_data.get('page', 1)) category = request_data.get('category', 'all') account_restful_list, msg = AccountBaseService.get_user_list(username=username, email=email, alias=alias, per_page=per_page, page=page, category=category) if account_restful_list is False: return api_response(0, msg, '') else: data = dict(value=account_restful_list, per_page=msg['per_page'], page=msg['page'], total=msg['total']) return api_response(1, '', data) else: return redirect('/')