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 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_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 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 })