def post(self,request,*args,**kwargs): if not request.body: return JsonResponse(Message.success(402, None, '请求入参不正确!')) param = json.loads(request.body) cid = param.get('id') if not cid: return JsonResponse(Message.success(402, None, '请求入参不正确!')) try: obj = Role.objects.get(pk=cid) if param.get('name'): obj.name = param.get('name') if param.get('seq'): obj.seq = param.get('seq') if param.get('status'): obj.status = param.get('status') if param.get('alias_name'): obj.alias_name = param.get('alias_name') if param.get('is_all_sql_auth'): obj.is_all_sql_auth = param.get('is_all_sql_auth') if param.get('desc'): obj.desc = param.get('desc') obj.save() if param.get('resources'): rIds = ','.join(str(s) for s in param.get('resources')) obj.resources.set(Resource.objects.extra(where=['id IN ('+ rIds +')'])) else: obj.resources.clear() if param.get('sql_resources'): sIds = ','.join(str(s) for s in param.get('sql_resources')) obj.sql_resources.set(SQLResource.objects.extra(where=['id IN ('+ sIds +')'])) else: obj.sql_resources.clear() obj.save() except: return JsonResponse(Message.success(301, None, '更新失败!')) return JsonResponse(Message.success(200, None, '更新成功!'))
def post(self, request, *args, **kwargs): if not request.body: return JsonResponse(Message.success(402, None, '请求入参不正确!')) param = json.loads(request.body) cid = param.get('id') if not cid: return JsonResponse(Message.success(402, None, '请求入参不正确!')) try: obj = User.objects.get(pk=cid, enabled=1) roleList = obj.roles.filter(enabled=1).values('id') roles = [] for role in roleList: roles.append(role['id']) companyList = obj.companys.filter(enabled=1).values('id') companys = [] for company in companyList: companys.append(company['id']) data = model_to_dict(obj) data['roles'] = roles data['companys'] = companys except Exception as e: print(e) return JsonResponse(Message.success(301, None, '获取失败!')) return JsonResponse(Message.success(200, data, '获取成功!'))
def get(self, request): return JsonResponse(Message.success(200, None, '后台系统欢迎您!'))