diff --git a/apps/assets/forms/asset.py b/apps/assets/forms/asset.py index 3500862e5..69e64ceaf 100644 --- a/apps/assets/forms/asset.py +++ b/apps/assets/forms/asset.py @@ -33,11 +33,16 @@ class AssetCreateForm(OrgModelForm): return nodes_field = self.fields['nodes'] if self.instance: - nodes_field.choices = ((n.id, n.full_value) for n in - self.instance.nodes.all()) + nodes_field.choices = [(n.id, n.full_value) for n in + self.instance.nodes.all()] else: nodes_field.choices = [] + def add_nodes_initial(self, node): + nodes_field = self.fields['nodes'] + nodes_field.choices.append((node.id, node.full_value)) + nodes_field.initial = [node] + class Meta: model = Asset fields = [ diff --git a/apps/assets/models/node.py b/apps/assets/models/node.py index 37ebbd6d3..243c352a7 100644 --- a/apps/assets/models/node.py +++ b/apps/assets/models/node.py @@ -37,19 +37,22 @@ class TreeMixin: def tree(cls): from ..utils import TreeService tree_updated_time = cache.get(cls.tree_updated_time_cache_key, 0) + now = time.time() + # 什么时候重新初始化 _tree_service if not cls.tree_created_time or \ tree_updated_time > cls.tree_created_time: logger.debug("Create node tree") tree = TreeService.new() - cls.tree_created_time = time.time() - cls.tree_assets_created_time = time.time() + cls.tree_created_time = now + cls.tree_assets_created_time = now cls._tree_service = tree return tree + # 是否要重新初始化节点资产 node_assets_updated_time = cache.get(cls.tree_assets_cache_key, 0) if not cls.tree_assets_created_time or \ node_assets_updated_time > cls.tree_assets_created_time: - cls._tree_service.init_assets_async() - cls.tree_assets_created_time = time.time() + cls._tree_service.init_assets() + cls.tree_assets_created_time = now logger.debug("Refresh node tree assets") return cls._tree_service diff --git a/apps/assets/views/asset.py b/apps/assets/views/asset.py index 257691fa4..f08c08db8 100644 --- a/apps/assets/views/asset.py +++ b/apps/assets/views/asset.py @@ -86,7 +86,7 @@ class AssetCreateView(PermissionsMixin, FormMixin, TemplateView): node = get_object_or_none(Node, id=node_id) else: node = Node.org_root() - form["nodes"].initial = node + form.add_nodes_initial(node) return form def get_protocol_formset(self): diff --git a/apps/audits/templates/audits/ftp_log_list.html b/apps/audits/templates/audits/ftp_log_list.html index 91ea6c49d..a5e3fceec 100644 --- a/apps/audits/templates/audits/ftp_log_list.html +++ b/apps/audits/templates/audits/ftp_log_list.html @@ -11,6 +11,9 @@ #search_btn { margin-bottom: 0; } + .form-control { + height: 30px; + } {% endblock %} diff --git a/apps/audits/templates/audits/login_log_list.html b/apps/audits/templates/audits/login_log_list.html index c855db1c1..6a3bae989 100644 --- a/apps/audits/templates/audits/login_log_list.html +++ b/apps/audits/templates/audits/login_log_list.html @@ -8,6 +8,12 @@ #search_btn { margin-bottom: 0; } + .form-control { + height: 30px; + } + .select2-selection__rendered span.select2-selection, .select2-container .select2-selection--single { + height: 30px !important; + } {% endblock %} diff --git a/apps/audits/templates/audits/operate_log_list.html b/apps/audits/templates/audits/operate_log_list.html index 736c4f7ac..ae072187d 100644 --- a/apps/audits/templates/audits/operate_log_list.html +++ b/apps/audits/templates/audits/operate_log_list.html @@ -11,6 +11,12 @@ #search_btn { margin-bottom: 0; } + .form-control { + height: 30px; + } + .select2-selection__rendered span.select2-selection, .select2-container .select2-selection--single { + height: 30px !important; + } {% endblock %} diff --git a/apps/audits/templates/audits/password_change_log_list.html b/apps/audits/templates/audits/password_change_log_list.html index a8a2f818d..1440dca2d 100644 --- a/apps/audits/templates/audits/password_change_log_list.html +++ b/apps/audits/templates/audits/password_change_log_list.html @@ -11,6 +11,12 @@ #search_btn { margin-bottom: 0; } + .form-control { + height: 30px; + } + .select2-selection__rendered span.select2-selection, .select2-container .select2-selection--single { + height: 30px !important; + } {% endblock %} diff --git a/apps/common/mixins/api.py b/apps/common/mixins/api.py index ae92e3e97..96c170670 100644 --- a/apps/common/mixins/api.py +++ b/apps/common/mixins/api.py @@ -44,8 +44,9 @@ class IDInCacheFilterMixin(object): return queryset cache_key = KEY_CACHE_RESOURCES_ID.format(spm) resources_id = cache.get(cache_key) - if resources_id and isinstance(resources_id, list): - queryset = queryset.filter(id__in=resources_id) + if not resources_id or not isinstance(resources_id, list): + queryset = queryset.none() + queryset = queryset.filter(id__in=resources_id) return queryset diff --git a/apps/ops/tasks.py b/apps/ops/tasks.py index 64d979c25..d2f55f623 100644 --- a/apps/ops/tasks.py +++ b/apps/ops/tasks.py @@ -40,7 +40,7 @@ def run_ansible_task(tid, callback=None, **kwargs): logger.error("No task found") -@shared_task(soft_time_limit=60) +@shared_task(soft_time_limit=60, queue="ansible") def run_command_execution(cid, **kwargs): execution = get_object_or_none(CommandExecution, id=cid) if execution: diff --git a/apps/ops/templates/ops/command_execution_list.html b/apps/ops/templates/ops/command_execution_list.html index fe8b7122c..3c9f1b54e 100644 --- a/apps/ops/templates/ops/command_execution_list.html +++ b/apps/ops/templates/ops/command_execution_list.html @@ -9,6 +9,9 @@