diff --git a/apps/assets/api.py b/apps/assets/api.py
index bfd4d7200..02b94b214 100644
--- a/apps/assets/api.py
+++ b/apps/assets/api.py
@@ -1,8 +1,7 @@
# ~*~ coding: utf-8 ~*~
from rest_framework import serializers
-from rest_framework import viewsets, serializers
-
+from rest_framework import viewsets, serializers,generics
from .models import AssetGroup, Asset, IDC, AssetExtend
@@ -45,9 +44,11 @@ class AssetViewSet(viewsets.ModelViewSet):
serializer_class = AssetSerializer
-class IDCViewSet(viewsets.ModelViewSet):
+class IDCViewSet(viewsets.ReadOnlyModelViewSet):
"""
API endpoint that allows IDC to be viewed or edited.
"""
queryset = IDC.objects.all()
- serializer_class = IDCSerializer
\ No newline at end of file
+ serializer_class = IDCSerializer
+
+
diff --git a/apps/assets/forms.py b/apps/assets/forms.py
index f08d4fb75..b8de07e73 100644
--- a/apps/assets/forms.py
+++ b/apps/assets/forms.py
@@ -91,7 +91,7 @@ class AssetGroupForm(forms.ModelForm):
class Meta:
model = AssetGroup
fields = [
- "name", "comment","system_users"
+ "name", "comment","system_users",
]
widgets = {
'name' : forms.TextInput(attrs={}),
diff --git a/apps/assets/templates/assets/asset_group_create.html b/apps/assets/templates/assets/asset_group_create.html
index e4ef34d14..0f346b53d 100644
--- a/apps/assets/templates/assets/asset_group_create.html
+++ b/apps/assets/templates/assets/asset_group_create.html
@@ -37,18 +37,16 @@
{{ form.name|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
-
-
-
+
+
{{ form.system_users|bootstrap_horizontal }}
@@ -56,6 +54,7 @@
@@ -68,13 +67,64 @@
+
+
+
+
{% endblock %}
{% block custom_foot_js %}
-
+
+
+
{% endblock %}
\ No newline at end of file
diff --git a/apps/assets/templates/assets/asset_modal_list.html b/apps/assets/templates/assets/asset_modal_list.html
new file mode 100644
index 000000000..7ef1152e9
--- /dev/null
+++ b/apps/assets/templates/assets/asset_modal_list.html
@@ -0,0 +1,66 @@
+
+
+
+
+
diff --git a/apps/assets/templates/assets/idc_list.html b/apps/assets/templates/assets/idc_list.html
index 0b53b7c82..810b2a102 100644
--- a/apps/assets/templates/assets/idc_list.html
+++ b/apps/assets/templates/assets/idc_list.html
@@ -9,13 +9,10 @@
|
-{# {% trans 'ID' %} | #}
{% trans 'Name' %} |
{% trans 'Asset num' %} |
-{# {% trans 'Bandwidth' %} | #}
{% trans 'Contact' %} |
{% trans 'Phone' %} |
-{# {% trans 'Address' %} | #}
{% trans 'operation' %} |
{% endblock %}
diff --git a/apps/assets/urls.py b/apps/assets/urls.py
index f5260f33a..d07fd78df 100644
--- a/apps/assets/urls.py
+++ b/apps/assets/urls.py
@@ -1,6 +1,7 @@
# coding:utf-8
from django.conf.urls import url, include
import views
+import api
# from .api import (
# AssetGroupViewSet, AssetViewSet, IDCViewSet
# )
@@ -19,6 +20,7 @@ urlpatterns = [
url(r'^asset/(?P[0-9]+)$', views.AssetDetailView.as_view(), name='asset-detail'),
url(r'^asset/(?P[0-9]+)/update', views.AssetUpdateView.as_view(), name='asset-update'),
url(r'^asset/(?P[0-9]+)/delete$', views.AssetDeleteView.as_view(), name='asset-delete'),
+ url(r'^asset-modal$', views.AssetModalListView.as_view(), name='asset-modal-list'),
# Resource asset group url
url(r'^asset-group$', views.AssetGroupListView.as_view(), name='asset-group-list'),
@@ -50,5 +52,13 @@ urlpatterns = [
url(r'^system-user/(?P[0-9]+)/asset$', views.SystemUserAssetView.as_view(), name='system-user-asset'),
# url(r'^system-user/(?P[0-9]+)/asset-group$', views.SystemUserAssetGroupView.as_view(),
# name='system-user-asset-group'),
- # url(r'^api/v1.0/', include(router.urls)),
+
]
+
+urlpatterns += [
+ #json
+ url(r'^v1/assets/$', api.AssetViewSet.as_view({'get':'list'}), name='assets-list-api'),
+ url(r'^v1/idc/$', api.IDCViewSet.as_view({'get':'list'}), name='idc-list-json'),
+]
+
+
diff --git a/apps/assets/utils.py b/apps/assets/utils.py
index 9a42d3031..593249287 100644
--- a/apps/assets/utils.py
+++ b/apps/assets/utils.py
@@ -1,4 +1,5 @@
# ~*~ coding: utf-8 ~*~
#
-
+from rest_framework import serializers
+from models import Asset
diff --git a/apps/assets/views.py b/apps/assets/views.py
index cab3c6df9..859c9b808 100644
--- a/apps/assets/views.py
+++ b/apps/assets/views.py
@@ -100,6 +100,11 @@ class AssetDetailView(DetailView):
kwargs.update(context)
return super(AssetDetailView, self).get_context_data(**kwargs)
+class AssetModalListView(AdminUserRequiredMixin, ListView):
+ paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
+ model = Asset
+ context_object_name = 'asset_modal_list'
+ template_name = 'assets/asset_modal_list.html'
class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
model = AssetGroup
@@ -119,11 +124,22 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
kwargs.update(context)
return super(AssetGroupCreateView, self).get_context_data(**kwargs)
+ # def form_valid(self, form):
+ # asset_group = form.save()
+ # assets_id_list = self.request.POST.getlist('assets', [])
+ # assets = [get_object_or_404(Asset, id=asset_id) for asset_id in assets_id_list]
+ # asset_group.created_by = self.request.user.username or 'Admin'
+ # asset_group.assets.add(*tuple(assets))
+ # asset_group.save()
+ # return super(AssetGroupCreateView, self).form_valid(form)
+
+
def form_valid(self, form):
asset_group = form.save()
assets_id_list = self.request.POST.getlist('assets', [])
- assets = [get_object_or_404(Asset, id=asset_id) for asset_id in assets_id_list]
+ assets = [get_object_or_404(Asset, id=int(asset_id)) for asset_id in assets_id_list]
+ print assets
asset_group.created_by = self.request.user.username or 'Admin'
asset_group.assets.add(*tuple(assets))
asset_group.save()
@@ -283,6 +299,7 @@ class IDCDeleteView(AdminUserRequiredMixin, DeleteView):
success_url = reverse_lazy('assets:idc-list')
+
class AdminUserListView(AdminUserRequiredMixin, ListView):
model = AdminUser
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
@@ -527,3 +544,5 @@ class SystemUserAssetView(AdminUserRequiredMixin, SingleObjectMixin, ListView):
# kwargs.update(context)
# return super(SystemUserAssetGroupView, self).get_context_data(**kwargs)
+
+
diff --git a/jumpserver0921.rar b/jumpserver0921.rar
new file mode 100644
index 000000000..2b645dd70
Binary files /dev/null and b/jumpserver0921.rar differ