def permission_add(request, second_menu_id): """ 添加权限 :param request: :param second_: :return: """ if request.method == 'GET': form = PermissionModelForm() return render(request, "rbac/change.html", {"form": form}) form = PermissionModelForm(data=request.POST) if form.is_valid(): second_menu_object = models.Permission.objects.filter( id=second_menu_id).first() if not second_menu_object: return HttpResponse('二级菜单不存在,请重新选择!') # form.instance中包含用户提交的所有值 # instance = models.Permission(title='', name='', url='', pid=second_menu_object) # instance.pid = second_menu_object # instance.save() form.instance.pid = second_menu_object form.save() return redirect(memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/change.html', {'form': form})
def menu_del(request, pk): """ 删除菜单 :param request: :param pk: :return: """ url = memory_reverse(request, 'rbac:menu_list') if request.method == 'GET': return render(request, 'rbac/delete.html', {'cancel_url': url}) models.Menu.objects.filter(id=pk).delete() return redirect(url)
def multi_permissions_del(request, pk): """ 批量页面的权限删除 :param request: :param pk: :return: """ url = memory_reverse(request, 'rbac:multi_permissions') if request.method == 'GET': return render(request, 'rbac/delete.html', {'cancel_url': url}) models.Permission.objects.filter(id=pk).delete() return redirect(url)
def menu_add(request): """ 添加菜单 :param request: :return: """ if request.method == 'GET': form = MenuModelForm() return render(request, "rbac/menu_change.html", {"form": form}) form = MenuModelForm(data=request.POST) if form.is_valid(): form.save() return redirect(memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/menu_change.html', {'form': form})
def second_menu_add(request, menu_id): """ 添加二级菜单 :param request: :return: """ menu_object = models.Menu.objects.filter(id=menu_id).first() if request.method == 'GET': form = SecondMenuModelForm(initial={'menu': menu_object}) return render(request, "rbac/change.html", {"form": form}) form = SecondMenuModelForm(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_edit(request, pk): """ 编辑权限 :param request: :param pk: :return: """ permission_object = models.Permission.objects.filter(id=pk).first() if request.method == 'GET': form = PermissionModelForm(instance=permission_object) return render(request, "rbac/change.html", {"form": form}) form = PermissionModelForm(data=request.POST, instance=permission_object) if form.is_valid(): form.save() return redirect(memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/change.html', {'form': form})
def menu_edit(request, pk): """ 编辑菜单 :param request: :param pk: :return: """ obj = models.Menu.objects.filter(id=pk).first() if not obj: return HttpResponse("菜单不存在") if request.method == "GET": form = MenuModelForm(instance=obj) # instance 输入框默认值 return render(request, 'rbac/menu_change.html', {'form': form}) form = MenuModelForm(instance=obj, data=request.POST) if form.is_valid(): form.save() return redirect(memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/menu_change.html', {'form': form})