Browse Source

[Update] 修改资产树和资产列表数量显示(游离资产)

pull/1370/head
BaiJiangJie 7 years ago
parent
commit
3a2973023c
  1. 16
      apps/assets/api/asset.py
  2. 2
      apps/assets/templates/assets/_asset_list_modal.html
  3. 4
      apps/users/views/login.py

16
apps/assets/api/asset.py

@ -50,16 +50,18 @@ class AssetViewSet(IDInFilterMixin, LabelFilter, BulkModelViewSet):
queryset = queryset.filter(admin_user=admin_user) queryset = queryset.filter(admin_user=admin_user)
if node_id and show_current_asset: if node_id and show_current_asset:
queryset = queryset.filter(
Q(nodes=node_id) | Q(nodes__isnull=True)
).distinct()
if node_id and not show_current_asset:
node = get_object_or_404(Node, id=node_id) node = get_object_or_404(Node, id=node_id)
if not node.is_root(): if node.is_root():
queryset = queryset.filter( queryset = queryset.filter(
Q(nodes__key__regex='^{}(:[0-9]+)*$'.format(node.key)) | Q(nodes=node_id) | Q(nodes__isnull=True)
Q(nodes__isnull=True),
).distinct() ).distinct()
else:
queryset = queryset.filter(nodes=node).distinct()
if node_id and not show_current_asset:
node = get_object_or_404(Node, id=node_id)
if node.is_root():
queryset = Asset.objects.all()
else: else:
queryset = queryset.filter( queryset = queryset.filter(
nodes__key__regex='^{}(:[0-9]+)*$'.format(node.key), nodes__key__regex='^{}(:[0-9]+)*$'.format(node.key),

2
apps/assets/templates/assets/_asset_list_modal.html

@ -95,7 +95,7 @@ function initTree2() {
}; };
var zNodes = []; var zNodes = [];
$.get("{% url 'api-assets:node-list' %}", function(data, status){ $.get("{% url 'api-assets:node-list' %}?show_current_asset=1", function(data, status){
$.each(data, function (index, value) { $.each(data, function (index, value) {
value["pId"] = value["parent"]; value["pId"] = value["parent"];
{#value["open"] = true;#} {#value["open"] = true;#}

4
apps/users/views/login.py

@ -50,7 +50,9 @@ class UserLoginView(FormView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if request.user.is_staff: if request.user.is_staff:
return redirect(self.get_success_url()) return redirect(redirect_user_first_login_or_index(
request, self.redirect_field_name)
)
request.session.set_test_cookie() request.session.set_test_cookie()
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)

Loading…
Cancel
Save