From 8504c3d2fd0ecb491e007d2dce912f665d5b0ad7 Mon Sep 17 00:00:00 2001 From: BaiJiangjie Date: Wed, 4 Apr 2018 19:38:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B5=84=E4=BA=A7=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=AF=BC=E5=87=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/templates/assets/asset_list.html | 9 ++++++--- apps/assets/views/asset.py | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/assets/templates/assets/asset_list.html b/apps/assets/templates/assets/asset_list.html index 25e206c0c..d849d0748 100644 --- a/apps/assets/templates/assets/asset_list.html +++ b/apps/assets/templates/assets/asset_list.html @@ -182,7 +182,6 @@ function initTable() { return asset_table } - function addTreeNode() { hideRMenu(); var parentNode = zTree.getSelectedNodes()[0]; @@ -238,7 +237,6 @@ function editTreeNode() { zTree.editName(current_node); } - function OnRightClick(event, treeId, treeNode) { if (!treeNode && event.target.tagName.toLowerCase() !== "button" && $(event.target).parents("a").length === 0) { zTree.cancelSelectedNode(); @@ -432,6 +430,11 @@ $(document).ready(function(){ .on('click', '.btn_export', function () { var $data_table = $('#asset_list_table').DataTable(); var rows = $data_table.rows('.selected').data(); + var nodes = zTree.getSelectedNodes(); + var current_node; + if (nodes && nodes.length === 1) { + current_node = nodes[0]; + } var assets = []; $.each(rows, function (index, obj) { assets.push(obj.id) @@ -439,7 +442,7 @@ $(document).ready(function(){ $.ajax({ url: "{% url "assets:asset-export" %}", method: 'POST', - data: JSON.stringify({assets_id: assets}), + data: JSON.stringify({assets_id: assets, node_id: current_node.id}), dataType: "json", success: function (data, textStatus) { window.open(data.redirect) diff --git a/apps/assets/views/asset.py b/apps/assets/views/asset.py index 45254c3a4..953f3c8ac 100644 --- a/apps/assets/views/asset.py +++ b/apps/assets/views/asset.py @@ -233,8 +233,16 @@ class AssetExportView(View): def post(self, request, *args, **kwargs): try: assets_id = json.loads(request.body).get('assets_id', []) + assets_node_id = json.loads(request.body).get('node_id', None) except ValueError: return HttpResponse('Json object not valid', status=400) + + if not assets_id and assets_node_id: + assets_node = get_object_or_none(Node, id=assets_node_id) + assets = assets_node.get_all_assets() + for asset in assets: + assets_id.append(asset.id) + spm = uuid.uuid4().hex cache.set(spm, assets_id, 300) url = reverse_lazy('assets:asset-export') + '?spm=%s' % spm