[Bugfix] 解决上次引入的bug

pull/1268/head
ibuler 2018-04-26 20:48:32 +08:00
parent 16aa42a861
commit 5103dab72e
2 changed files with 5 additions and 6 deletions

View File

@ -108,18 +108,18 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
return node return node
def get_queryset(self): def get_queryset(self):
queryset = set() queryset = []
query_all = self.request.query_params.get("all") query_all = self.request.query_params.get("all")
query_assets = self.request.query_params.get('assets') query_assets = self.request.query_params.get('assets')
node = self.get_object() node = self.get_object()
if node == Node.root(): if node == Node.root():
queryset.add(node) queryset.append(node)
if query_all: if query_all:
children = node.get_all_children() children = node.get_all_children()
else: else:
children = node.get_children() children = node.get_children()
queryset.update(set(children)) queryset.extend(list(children))
if query_assets: if query_assets:
assets = node.get_assets() assets = node.get_assets()
for asset in assets: for asset in assets:
@ -128,7 +128,7 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
node_fake.parent = node node_fake.parent = node
node_fake.value = asset.hostname node_fake.value = asset.hostname
node_fake.is_node = False node_fake.is_node = False
queryset.add(node_fake) queryset.append(node_fake)
queryset = sorted(queryset, key=lambda x: x.is_node, reverse=True) queryset = sorted(queryset, key=lambda x: x.is_node, reverse=True)
return queryset return queryset

View File

@ -18,8 +18,7 @@ class NodeTMPSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Node model = Node
fields = ['id', 'key', 'value', 'parent', 'assets_amount', fields = ['id', 'key', 'value', 'parent', 'assets_amount', 'is_node']
'is_asset']
list_serializer_class = BulkListSerializer list_serializer_class = BulkListSerializer
@staticmethod @staticmethod