2016-08-09 09:27:37 +00:00
|
|
|
# ~*~ coding: utf-8 ~*~
|
|
|
|
#
|
2019-08-21 12:27:21 +00:00
|
|
|
from treelib import Tree
|
2019-09-26 07:09:10 +00:00
|
|
|
from treelib.exceptions import NodeIDAbsentError
|
2019-08-21 12:27:21 +00:00
|
|
|
from collections import defaultdict
|
|
|
|
from copy import deepcopy
|
2018-01-26 06:47:10 +00:00
|
|
|
|
2020-08-16 15:08:58 +00:00
|
|
|
from django.db.models import Q
|
|
|
|
|
2020-03-12 08:24:38 +00:00
|
|
|
from common.utils import get_logger, timeit, lazyproperty
|
|
|
|
from .models import Asset, Node
|
2016-09-04 09:43:03 +00:00
|
|
|
|
2017-12-06 10:31:51 +00:00
|
|
|
|
2019-06-27 13:43:10 +00:00
|
|
|
logger = get_logger(__file__)
|
2017-12-07 05:01:33 +00:00
|
|
|
|
|
|
|
|
2020-08-16 15:08:58 +00:00
|
|
|
def check_node_assets_amount():
|
|
|
|
for node in Node.objects.all():
|
|
|
|
assets_amount = Asset.objects.filter(
|
|
|
|
Q(nodes__key__istartswith=f'{node.key}:') | Q(nodes=node)
|
|
|
|
).distinct().count()
|
2019-08-21 12:27:21 +00:00
|
|
|
|
2020-08-16 15:08:58 +00:00
|
|
|
if node.assets_amount != assets_amount:
|
|
|
|
print(f'<Node:{node.key}> wrong assets amount '
|
|
|
|
f'{node.assets_amount} right is {assets_amount}')
|
|
|
|
node.assets_amount = assets_amount
|
|
|
|
node.save()
|
2019-09-26 07:09:10 +00:00
|
|
|
|
|
|
|
|
2020-08-16 15:08:58 +00:00
|
|
|
def is_asset_exists_in_node(asset_pk, node_key):
|
|
|
|
return Asset.objects.filter(
|
|
|
|
id=asset_pk
|
|
|
|
).filter(
|
|
|
|
Q(nodes__key__istartswith=f'{node_key}:') | Q(nodes__key=node_key)
|
|
|
|
).exists()
|