Commit f1c38671 authored by ibuler's avatar ibuler

[Update]一些修改

parent f0dd7d54
...@@ -49,7 +49,8 @@ class AssetViewSet(IDInFilterMixin, LabelFilter, BulkModelViewSet): ...@@ -49,7 +49,8 @@ class AssetViewSet(IDInFilterMixin, LabelFilter, BulkModelViewSet):
queryset = queryset.filter(admin_user=admin_user) queryset = queryset.filter(admin_user=admin_user)
if node_id: if node_id:
node = get_object_or_404(Node, id=node_id) node = get_object_or_404(Node, id=node_id)
queryset = queryset.filter(nodes__key__startswith=node.key).distinct() if not node.is_root():
queryset = queryset.filter(nodes__key__startswith=node.key).distinct()
return queryset return queryset
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
from django import forms from django import forms
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from ..models import Asset from ..models import Asset, AdminUser
from common.utils import get_logger from common.utils import get_logger
logger = get_logger(__file__) logger = get_logger(__file__)
...@@ -85,16 +85,23 @@ class AssetBulkUpdateForm(forms.ModelForm): ...@@ -85,16 +85,23 @@ class AssetBulkUpdateForm(forms.ModelForm):
port = forms.IntegerField( port = forms.IntegerField(
label=_('Port'), required=False, min_value=1, max_value=65535, label=_('Port'), required=False, min_value=1, max_value=65535,
) )
admin_user = forms.ModelChoiceField(
required=False, queryset=AdminUser.objects.all(),
label=_("Admin user"),
widget=forms.Select(
attrs={
'class': 'select2',
'data-placeholder': _('Admin user')
}
)
)
class Meta: class Meta:
model = Asset model = Asset
fields = [ fields = [
'assets', 'port', 'admin_user', 'nodes', 'assets', 'port', 'admin_user', 'labels', 'nodes',
] ]
widgets = { widgets = {
'admin_user': forms.SelectMultiple(
attrs={'class': 'select2', 'data-placeholder': _('Admin user')}
),
'labels': forms.SelectMultiple( 'labels': forms.SelectMultiple(
attrs={'class': 'select2', 'data-placeholder': _('Labels')} attrs={'class': 'select2', 'data-placeholder': _('Labels')}
), ),
...@@ -106,17 +113,21 @@ class AssetBulkUpdateForm(forms.ModelForm): ...@@ -106,17 +113,21 @@ class AssetBulkUpdateForm(forms.ModelForm):
def save(self, commit=True): def save(self, commit=True):
changed_fields = [] changed_fields = []
for field in self._meta.fields: for field in self._meta.fields:
if self.data.get(field) is not None: if self.data.get(field) not in [None, '']:
changed_fields.append(field) changed_fields.append(field)
cleaned_data = {k: v for k, v in self.cleaned_data.items() cleaned_data = {k: v for k, v in self.cleaned_data.items()
if k in changed_fields} if k in changed_fields}
assets = cleaned_data.pop('assets') assets = cleaned_data.pop('assets')
labels = cleaned_data.pop('labels', []) labels = cleaned_data.pop('labels', [])
nodes = cleaned_data.pop('nodes')
assets = Asset.objects.filter(id__in=[asset.id for asset in assets]) assets = Asset.objects.filter(id__in=[asset.id for asset in assets])
assets.update(**cleaned_data) assets.update(**cleaned_data)
if labels: if labels:
for asset in assets: for label in labels:
asset.labels.set(labels) label.assets.add(*tuple(assets))
if nodes:
for node in nodes:
node.assets.add(*tuple(assets))
return assets return assets
...@@ -63,10 +63,16 @@ class Node(models.Model): ...@@ -63,10 +63,16 @@ class Node(models.Model):
def get_all_assets(self): def get_all_assets(self):
from .asset import Asset from .asset import Asset
nodes = self.get_family() if self.is_root():
assets = Asset.objects.filter(nodes__in=nodes) assets = Asset.objects.all()
else:
nodes = self.get_family()
assets = Asset.objects.filter(nodes__in=nodes)
return assets return assets
def is_root(self):
return self.key == '0'
@property @property
def parent(self): def parent(self):
if self.key == "0": if self.key == "0":
......
...@@ -38,16 +38,21 @@ class NodeGrantedSerializer(BulkSerializerMixin, serializers.ModelSerializer): ...@@ -38,16 +38,21 @@ class NodeGrantedSerializer(BulkSerializerMixin, serializers.ModelSerializer):
class NodeSerializer(serializers.ModelSerializer): class NodeSerializer(serializers.ModelSerializer):
parent = serializers.SerializerMethodField() parent = serializers.SerializerMethodField()
assets_amount = serializers.SerializerMethodField()
class Meta: class Meta:
model = Node model = Node
fields = ['id', 'key', 'value', 'parent'] fields = ['id', 'key', 'value', 'parent', 'assets_amount']
list_serializer_class = BulkListSerializer list_serializer_class = BulkListSerializer
@staticmethod @staticmethod
def get_parent(obj): def get_parent(obj):
return obj.parent.id return obj.parent.id
@staticmethod
def get_assets_amount(obj):
return obj.get_all_assets().count()
def get_fields(self): def get_fields(self):
fields = super().get_fields() fields = super().get_fields()
field = fields["key"] field = fields["key"]
......
...@@ -74,7 +74,8 @@ $(document).ready(function(){ ...@@ -74,7 +74,8 @@ $(document).ready(function(){
if (val === 100) { if (val === 100) {
innerHtml = "<span class='text-navy'>" + val + "% </span>"; innerHtml = "<span class='text-navy'>" + val + "% </span>";
} else { } else {
innerHtml = "<span class='text-danger'>" + val + "% </span>"; var num = new Number(val);
innerHtml = "<span class='text-danger'>" + num.toFixed(1) + "% </span>";
} }
$(td).html('<span href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</span>'); $(td).html('<span href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</span>');
......
...@@ -329,7 +329,7 @@ function initTree() { ...@@ -329,7 +329,7 @@ function initTree() {
{#if (value["key"] === "0") {#} {#if (value["key"] === "0") {#}
value["open"] = true; value["open"] = true;
{# }#} {# }#}
value["name"] = value["value"] value["name"] = value["value"] + ' (' + value['assets_amount'] + ')'
}); });
zNodes = data; zNodes = data;
$.fn.zTree.init($("#assetTree"), setting, zNodes); $.fn.zTree.init($("#assetTree"), setting, zNodes);
......
...@@ -75,7 +75,8 @@ function initTable() { ...@@ -75,7 +75,8 @@ function initTable() {
if (val === 100) { if (val === 100) {
innerHtml = "<span class='text-navy'>" + val + "% </span>"; innerHtml = "<span class='text-navy'>" + val + "% </span>";
} else { } else {
innerHtml = "<span class='text-danger'>" + val + "% </span>"; var num = new Number(val);
innerHtml = "<span class='text-danger'>" + num.toFixed(1) + "% </span>";
} }
$(td).html('<span href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</span>'); $(td).html('<span href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</span>');
......
...@@ -43,6 +43,7 @@ class AssetListView(AdminUserRequiredMixin, TemplateView): ...@@ -43,6 +43,7 @@ class AssetListView(AdminUserRequiredMixin, TemplateView):
template_name = 'assets/asset_list.html' template_name = 'assets/asset_list.html'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
Node.root()
context = { context = {
'app': _('Assets'), 'app': _('Assets'),
'action': _('Asset list'), 'action': _('Asset list'),
......
...@@ -181,7 +181,7 @@ function initTree() { ...@@ -181,7 +181,7 @@ function initTree() {
{#if (value["key"] === "0") {#} {#if (value["key"] === "0") {#}
value["open"] = true; value["open"] = true;
{# }#} {# }#}
value["name"] = value["value"] value["name"] = value["value"] + ' (' + value['assets_amount'] + ')'
}); });
zNodes = data; zNodes = data;
$.fn.zTree.init($("#assetTree"), setting, zNodes); $.fn.zTree.init($("#assetTree"), setting, zNodes);
......
{% load i18n %} {% load i18n %}
{% block first_login_message %} {% block first_login_message %}
{% if request.user.is_authenticated and request.user.is_first_login %} {% if request.user.is_authenticated and request.user.is_first_login %}
<div class="alert alert-danger help-message"> <div class="alert alert-danger help-message alert-dismissable">
{% url 'users:user-first-login' as first_login_url %} {% url 'users:user-first-login' as first_login_url %}
{% blocktrans %} {% blocktrans %}
Your information was incomplete. Please click <a href="{{ first_login_url }}"> this link </a>to complete your information. Your information was incomplete. Please click <a href="{{ first_login_url }}"> this link </a>to complete your information.
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block update_public_key_message %} {% block update_public_key_message %}
{% if request.user.is_authenticated and not request.user.is_public_key_valid %} {% if request.user.is_authenticated and not request.user.is_public_key_valid and not request.COOKIE.close_public_key_msg != '1' %}
<div class="alert alert-danger help-message"> <div class="alert alert-danger help-message alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button" onclick="closePublicKeyMsg()">×</button>
{% url 'users:user-pubkey-update' as user_pubkey_update %} {% url 'users:user-pubkey-update' as user_pubkey_update %}
{% blocktrans %} {% blocktrans %}
Your ssh public key not set or expired. Please click <a href="{{ user_pubkey_update }}"> this link </a>to update Your ssh public key not set or expired. Please click <a href="{{ user_pubkey_update }}"> this link </a>to update
...@@ -27,3 +28,9 @@ ...@@ -27,3 +28,9 @@
</div> </div>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
<script>
function closePublicKeyMsg() {
setCookie('close_public_key_msg', 1)
}
</script>
\ No newline at end of file
...@@ -174,7 +174,7 @@ class SessionViewSet(viewsets.ModelViewSet): ...@@ -174,7 +174,7 @@ class SessionViewSet(viewsets.ModelViewSet):
terminal_id = self.kwargs.get("terminal", None) terminal_id = self.kwargs.get("terminal", None)
if terminal_id: if terminal_id:
terminal = get_object_or_404(Terminal, id=terminal_id) terminal = get_object_or_404(Terminal, id=terminal_id)
self.queryset = terminal.status_set.all() self.queryset = terminal.session_set.all()
return self.queryset return self.queryset
......
...@@ -15,6 +15,8 @@ router.register(r'v1/terminal/(?P<terminal>[a-zA-Z0-9\-]{36})?/?sessions', api.S ...@@ -15,6 +15,8 @@ router.register(r'v1/terminal/(?P<terminal>[a-zA-Z0-9\-]{36})?/?sessions', api.S
router.register(r'v1/tasks', api.TaskViewSet, 'tasks') router.register(r'v1/tasks', api.TaskViewSet, 'tasks')
router.register(r'v1/terminal', api.TerminalViewSet, 'terminal') router.register(r'v1/terminal', api.TerminalViewSet, 'terminal')
router.register(r'v1/command', api.CommandViewSet, 'command') router.register(r'v1/command', api.CommandViewSet, 'command')
router.register(r'v1/sessions', api.SessionViewSet, 'session')
router.register(r'v1/status', api.StatusViewSet, 'session')
urlpatterns = [ urlpatterns = [
url(r'^v1/sessions/(?P<pk>[0-9a-zA-Z\-]{36})/replay/$', url(r'^v1/sessions/(?P<pk>[0-9a-zA-Z\-]{36})/replay/$',
......
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