From 38f8c5bb72b46249c3901b3b5d68601f152b816f Mon Sep 17 00:00:00 2001 From: BaiJiangjie Date: Mon, 14 May 2018 14:21:32 +0800 Subject: [PATCH] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E5=A4=8D=E8=B5=84=E4=BA=A7?= =?UTF-8?q?=E6=A0=91=E8=8A=82=E7=82=B9=E7=A7=BB=E5=8A=A8=EF=BC=8C=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E6=8E=88=E6=9D=83=E6=A0=91=E8=8A=82=E7=82=B9=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E8=B5=84=E4=BA=A7=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/node.py | 5 +++-- apps/assets/models/node.py | 12 +++++++++++- .../perms/templates/perms/asset_permission_list.html | 7 ++++--- apps/perms/views.py | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/apps/assets/api/node.py b/apps/assets/api/node.py index b8b2707e6..30d661a29 100644 --- a/apps/assets/api/node.py +++ b/apps/assets/api/node.py @@ -184,8 +184,9 @@ class NodeAddChildrenApi(generics.UpdateAPIView): for node in children: if not node: continue - node.parent = instance - node.save() + # node.parent = instance + # node.save() + node.move(instance) return Response("OK") diff --git a/apps/assets/models/node.py b/apps/assets/models/node.py index 14ac775fc..bb83035c0 100644 --- a/apps/assets/models/node.py +++ b/apps/assets/models/node.py @@ -2,7 +2,7 @@ # import uuid -from django.db import models +from django.db import models, transaction from django.utils.translation import ugettext_lazy as _ @@ -39,6 +39,16 @@ class Node(models.Model): def level(self): return len(self.key.split(':')) + def move(self, instance): + children = self.get_all_children() + old_key = self.key + with transaction.atomic(): + self.parent = instance + for child in children: + child.key = child.key.replace(old_key, self.key, 1) + child.save() + self.save() + def get_next_child_key(self): mark = self.child_mark self.child_mark += 1 diff --git a/apps/perms/templates/perms/asset_permission_list.html b/apps/perms/templates/perms/asset_permission_list.html index fa1154716..c18f12224 100644 --- a/apps/perms/templates/perms/asset_permission_list.html +++ b/apps/perms/templates/perms/asset_permission_list.html @@ -226,7 +226,7 @@ function initTree() { }, async: { enable: true, - url: "{% url 'api-assets:node-children-2' %}?assets=1&all=1", + url: "{% url 'api-assets:node-children-2' %}?assets=1&all=", autoParam:["id", "name=n", "level=lv"], dataFilter: filter, type: 'get' @@ -238,7 +238,7 @@ function initTree() { }; var zNodes = []; - $.get("{% url 'api-assets:node-children-2' %}?assets=1&all=1", function(data, status){ + $.get("{% url 'api-assets:node-children-2' %}?assets=1&all=", function(data, status){ $.each(data, function (index, value) { value["pId"] = value["parent"]; value["name"] = value["value"]; @@ -304,6 +304,7 @@ $(document).ready(function(){ if (row.child.isShown()) { tr.removeClass('details'); + $(this).children('i:first-child').removeClass('fa-angle-down').addClass('fa-angle-right'); row.child.hide(); // Remove from the 'open' array @@ -311,7 +312,7 @@ $(document).ready(function(){ } else { tr.addClass('details'); - $('.toggle i').removeClass('fa-angle-right').addClass('fa-angle-down'); + $(this).children('i:first-child').removeClass('fa-angle-right').addClass('fa-angle-down'); row.child(format(row.data())).show(); // Add to the 'open' array if ( idx === -1 ) { diff --git a/apps/perms/views.py b/apps/perms/views.py index 17b8637cc..9afbc6ffe 100644 --- a/apps/perms/views.py +++ b/apps/perms/views.py @@ -42,7 +42,7 @@ class AssetPermissionCreateView(AdminUserRequiredMixin, CreateView): if nodes_id: nodes_id = nodes_id.split(",") - nodes = Node.objects.filter(id__in=nodes_id) + nodes = Node.objects.filter(id__in=nodes_id).exclude(id=Node.root().id) form['nodes'].initial = nodes if assets_id: assets_id = assets_id.split(",")