def edit_role(request, edit_id=0): role_obj = models.Role.objects.filter(id=edit_id).first() form_obj = RoleForm(instance=role_obj) if request.method == 'POST': form_obj = RoleForm(request.POST, instance=role_obj) if form_obj.is_valid(): form_obj.save() return redirect(reverse('rbac:role_list')) return render(request, 'add_role.html', {'form_obj': form_obj})
def role(request, role_id=None): obj = models.Role.objects.filter(pk=role_id).first() form_obj = RoleForm(instance=obj) if request.method == 'POST': form_obj = RoleForm(request.POST, instance=obj) if form_obj.is_valid(): form_obj.save() return redirect(reverse('rbac:role_list')) return render(request, 'rbac/form.html', {'form_obj': form_obj})
def role_edit(request, edit_id=None): obj = models.Role.objects.filter(id=edit_id).first() form_obj = RoleForm(instance=obj) if request.method == "POST": form_obj = RoleForm(request.POST, instance=obj) if form_obj.is_valid(): form_obj.save() return redirect(reverse('rbac:role_list')) return render(request, 'rbac/role_edit.html', {"form_obj": form_obj})
def role_change(request, edit_id=None): obj = models.Role.objects.filter(id=edit_id).first() if edit_id: form_obj = RoleForm(instance=obj) title = '编辑角色' else: form_obj = RoleForm() title = '添加角色' if request.method == 'POST': form_obj = RoleForm(request.POST, instance=obj) if form_obj.is_valid(): form_obj.save() return redirect(reverse('rbac:rbac/role_list')) return render(request, 'rbac/role_change.html', { 'form_obj': form_obj, 'title': title })
def role_list(request): all_roles = models.Role.objects.all() roles = models.Menu.objects.all().values("id", "title", "permission__title") for i in roles: print(i) form_obj = RoleForm() return render(request, "rbac/role_list.html", context={ "all_roles": all_roles, "form_obj": form_obj })
def role_change(request, pk=None, *args, **kwargs): obj = models.Role.objects.filter(pk=pk).first() form_obj = RoleForm(instance=obj) if request.method == 'POST': form_obj = RoleForm(request.POST, instance=obj) if form_obj.is_valid(): form_obj.save() return redirect('rbac:role_list') return render(request, 'rbac/form.html', {'form_obj': form_obj})
def permission(request): if request.method == "GET": permission_list = Permission.objects.all() role_list = Role.objects.all() role_form = RoleForm() user = UserInfo.objects.filter(user_id=request.user.id) print(user) context = { "permission_list": permission_list, "user": user, 'role_list': role_list, "role_form": role_form, } return render(request, 'system/permission.html', context=context) if request.method == "POST": role_title = request.POST['role'] roles = Role.objects.filter(title=role_title) if roles: return HttpResponse('2') else: Role.objects.create(title=role_title) return HttpResponse('1')