Commit 4d1da568 authored by ibuler's avatar ibuler

[Update] 修改asset api

parent 3e17e942
......@@ -30,10 +30,8 @@ from .. import serializers
logger = get_logger(__file__)
__all__ = [
'NodeViewSet', 'NodeChildrenApi',
'NodeAssetsApi',
'NodeAddAssetsApi', 'NodeRemoveAssetsApi',
'NodeReplaceAssetsApi',
'NodeViewSet', 'NodeChildrenApi', 'NodeAssetsApi',
'NodeAddAssetsApi', 'NodeRemoveAssetsApi', 'NodeReplaceAssetsApi',
'NodeAddChildrenApi', 'RefreshNodeHardwareInfoApi',
'TestNodeConnectiveApi'
]
......
......@@ -64,6 +64,9 @@ class Node(OrgModelMixin):
def create_child(self, value):
with transaction.atomic():
child_key = self.get_next_child_key()
print("Create child")
print(self.key)
print(child_key)
child = self.__class__.objects.create(key=child_key, value=value)
return child
......@@ -120,15 +123,16 @@ class Node(OrgModelMixin):
return self.get_all_assets().valid()
def is_root(self):
root = self.__class__.root()
if self == root:
print(type(self.key))
print(self.key)
if self.key.isdigit():
return True
else:
return False
@property
def parent(self):
if self.key == "0" or not self.key.startswith("0"):
if self.is_root():
return self.__class__.root()
parent_key = ":".join(self.key.split(":")[:-1])
try:
......@@ -155,7 +159,7 @@ class Node(OrgModelMixin):
if self.is_root():
root = self.__class__.root()
return [root]
print(self.key)
_key = self.key.split(':')
if not with_self:
_key.pop()
......
......@@ -411,6 +411,8 @@ function initTree() {
zNodes = data;
$.fn.zTree.init($("#assetTree"), setting, zNodes);
zTree = $.fn.zTree.getZTreeObj("assetTree");
var root = zTree.getNodes()[0];
zTree.expandNode(root);
rMenu = $("#rMenu");
selectQueryNode();
});
......
......@@ -44,7 +44,7 @@ class AssetListView(AdminUserRequiredMixin, TemplateView):
template_name = 'assets/asset_list.html'
def get_context_data(self, **kwargs):
Node.root()
print(Node.root().name)
context = {
'app': _('Assets'),
'action': _('Asset list'),
......
......@@ -7,7 +7,7 @@ from django.contrib.auth import get_user_model
from django.forms import ModelForm
from common.utils import get_logger
from .utils import get_current_org, get_model_by_db_table, set_current_org
from .utils import get_current_org, set_current_org
logger = get_logger(__file__)
......@@ -22,23 +22,27 @@ class OrgManager(models.Manager):
current_org = get_current_org()
kwargs = {}
print(">>>>>>>>>> Get query set")
if not current_org:
kwargs['id'] = None
elif current_org.is_real():
kwargs['org'] = current_org
elif current_org.is_default():
kwargs['org'] = None
queryset = super().get_queryset().filter(**kwargs)
queryset = super(OrgManager, self).get_queryset()
queryset = queryset.filter(**kwargs)
# print(kwargs)
print(queryset.query)
return queryset
def all(self):
current_org = get_current_org()
if not current_org:
msg = 'You should `objects.set_current_org(org).all()` then run it'
msg = 'You can `objects.set_current_org(org).all()` then run it'
warnings.warn(msg)
return self
else:
return super().all()
return super(OrgManager, self).all()
def set_current_org(self, org):
set_current_org(org)
......
......@@ -35,10 +35,9 @@ def set_current_org(org):
setattr(_thread_locals, 'current_org', org)
def get_model_by_db_table(db_table):
for model in apps.get_models():
if model._meta.db_table == db_table:
return model
else:
# here you can do fallback logic if no model with db_table found
raise ValueError('No model found with db_table {}!'.format(db_table))
def set_to_default_org():
set_current_org(Organization.default())
def set_to_root_org():
set_current_org(Organization.root())
......@@ -11,7 +11,7 @@ __all__ = ['UserGroup']
class UserGroup(OrgModelMixin):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
name = models.CharField(max_length=128, unique=True, verbose_name=_('Name'))
name = models.CharField(max_length=128, verbose_name=_('Name'))
comment = models.TextField(blank=True, verbose_name=_('Comment'))
date_created = models.DateTimeField(auto_now_add=True, null=True,
verbose_name=_('Date created'))
......@@ -22,6 +22,7 @@ class UserGroup(OrgModelMixin):
class Meta:
ordering = ['name']
unique_together = ['org', 'name']
verbose_name = _("User group")
@classmethod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment