def permission_edit(request, pk): ''' 编辑权限 :param request: :param pk: :return: ''' permission_obj = models.Permission.objects.filter(pid=pk).first() if not permission_obj: return HttpResponse('菜单不存在!') if request.method == 'GET': form = menu.PermissionModelForm(instance=permission_obj) return render(request, 'rbac/role_change.html', {'form': form}) form = menu.PermissionModelForm(instance=permission_obj, data=request.POST) if form.is_valid(): form.save() return redirect(urls.memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/role_change.html', {'form': form})
def permission_add(request, second_menu_id): ''' 增加权限 :param request: :param second_menu_id: :return: ''' if request.method == 'GET': form = menu.PermissionModelForm() return render(request, 'rbac/role_change.html', {'form': form}) form = menu.PermissionModelForm(request.POST) if form.is_valid(): second_menu_obj = models.Permission.objects.filter( pid=second_menu_id).first() if not second_menu_obj: return HttpResponse('二级菜单不存在!') form.instance.p_id = second_menu_obj # 给新增权限绑定二级菜单 form.save() return redirect(urls.memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/role_change.html', {'form': form})
def permission_edit(request, pk): """ 编辑权限 :param request: :param id: 权限对象id :return: """ obj = models.Permission.objects.filter(id=pk).first() if not obj: return HttpResponse('权限不存在') if request.method == 'GET': form = menu.PermissionModelForm(instance=obj) return render(request, 'rbac/change.html', {'form': form}) form = menu.PermissionModelForm(instance=obj, data=request.POST) if form.is_valid(): form.save() return redirect(memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/change.html', {'form': form})
def permission_add(request, pk): """ 添加权限 :param request: :param sid: :return: """ if request.method == 'GET': form = menu.PermissionModelForm() return render(request, 'rbac/change.html', {'form': form}) form = menu.PermissionModelForm(request.POST) if form.is_valid(): permission_object = models.Permission.objects.filter(id=pk).first() if not permission_object: return HttpResponse('未关联二级菜单,请先关联再操作!') form.instance.pid = permission_object form.save() return redirect(memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/change.html', {'form': form})