Commit d0ba1737 authored by ibuler's avatar ibuler

Finish asset group create

parent 30fd51c2
...@@ -45,6 +45,9 @@ class AssetGroupForm(forms.ModelForm): ...@@ -45,6 +45,9 @@ class AssetGroupForm(forms.ModelForm):
fields = [ fields = [
"name", "comment" "name", "comment"
] ]
help_texts = {
'name': '* required',
}
class IdcForm(forms.ModelForm): class IdcForm(forms.ModelForm):
......
"""
jumpserver.__app__.hands.py
~~~~~~~~~~~~~~~~~
This app depends other apps api, function .. should be import or write mack here.
Other module of this app shouldn't connect with other app.
:copyright: (c) 2014-2016 by Jumpserver Team.
:license: GPL v2, see LICENSE for more details.
"""
...@@ -165,6 +165,25 @@ class Asset(models.Model): ...@@ -165,6 +165,25 @@ class Asset(models.Model):
db_table = 'asset' db_table = 'asset'
index_together = ('ip', 'port') index_together = ('ip', 'port')
@classmethod
def generate_fake(cls, count=100):
from random import seed
import forgery_py
from django.db import IntegrityError
seed()
for i in range(count):
asset = cls(ip='%s.%s.%s.%s' % tuple([forgery_py.forgery.basic.text(length=3, digits=True)
for i in range(0, 4)]),
port=22,
created_by='Fake')
try:
asset.save()
logger.debug('Generate fake asset : %s' % asset.ip)
except IntegrityError:
print('Error continue')
continue
class Label(models.Model): class Label(models.Model):
key = models.CharField(max_length=64, null=True, blank=True, verbose_name=_('KEY')) key = models.CharField(max_length=64, null=True, blank=True, verbose_name=_('KEY'))
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
<div class="ibox float-e-margins"> <div class="ibox float-e-margins">
<div class="ibox-title"> <div class="ibox-title">
<span class="label"><b>{{ asset_group.name }}</b></span> <span>{% trans 'Asset list of ' %} <b>{{ asset_group.name }}</b></span>
<div class="ibox-tools"> <div class="ibox-tools">
<a class="collapse-link"> <a class="collapse-link">
<i class="fa fa-chevron-up"></i> <i class="fa fa-chevron-up"></i>
...@@ -89,26 +89,29 @@ ...@@ -89,26 +89,29 @@
</div> </div>
</div> </div>
<div class="ibox-content"> <div class="ibox-content">
<table class="table"> <table class="table table-hover">
<thead>
<tr>
<th>{% trans 'Hostname' %}</th>
<th>{% trans 'IP' %}</th>
<th>{% trans 'Port' %}</th>
<th>{% trans 'Alive' %}</th>
</tr>
</thead>
<tbody> <tbody>
<tr class="no-borders-tr"> {% for asset in page_obj %}
<td>{% trans 'Name' %}:</td> <tr>
<td><b>{{ asset_group.name }}</b></td> <td>{{ asset.hostname }}</td>
</tr> <td>{{ asset.ip }}</td>
<tr> <td>{{ asset.port }}</td>
<td>{% trans 'Date created' %}:</td> <td>Alive</td>
<td><b>{{ asset_group.date_created }}</b></td> </tr>
</tr> {% endfor %}
<tr>
<td>{% trans 'Created by' %}:</td>
<td><b>{{ asset_group.created_by }}</b></td>
</tr>
<tr>
<td>{% trans 'Comment' %}:</td>
<td><b>{{ asset_group.comment }}</b></td>
</tr>
</tbody> </tbody>
</table> </table>
<div class="row">
{% include '_pagination.html' %}
</div>
</div> </div>
</div> </div>
</div> </div>
...@@ -129,14 +132,42 @@ ...@@ -129,14 +132,42 @@
</td> </td>
</tr> </tr>
<form> <form>
<tr> <tr class="no-borders-tr">
<td colspan="2"> <td colspan="2">
<select class="select2 form-control"> <select data-placeholder="{% trans 'Select system user' %}" class="select2" style="width: 100%" multiple="" tabindex="4">
<option value="1">{% trans 'System user' %}</option> {% for group in groups %}
<option value="2">{% trans 'Admin user' %}</option> <option value="{{ group.id }}">{{ group.name }}</option>
{% endfor %}
</select> </select>
</td> </td>
</tr> </tr>
<tr class="no-borders-tr">
<td colspan="2">
<button type="button" class="btn btn-primary btn-sm">{% trans 'Associate' %}</button>
</td>
</tr>
</form>
{% for group in user.groups.all %}
<tr>
<td ><b>{{ group.name }}</b></td>
<td>
<button class="btn btn-danger btn-xs" type="button" style="float: right;"><i class="fa fa-minus"></i></button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-info-circle"></i> {% trans 'Add asset to this group' %}
</div>
<div class="panel-body">
<table class="table">
<tbody>
<form>
<tr class="no-borders-tr"> <tr class="no-borders-tr">
<td colspan="2"> <td colspan="2">
<select data-placeholder="{% trans 'Select asset user' %}" class="select2" style="width: 100%" multiple="" tabindex="4"> <select data-placeholder="{% trans 'Select asset user' %}" class="select2" style="width: 100%" multiple="" tabindex="4">
...@@ -148,7 +179,7 @@ ...@@ -148,7 +179,7 @@
</tr> </tr>
<tr class="no-borders-tr"> <tr class="no-borders-tr">
<td colspan="2"> <td colspan="2">
<button type="button" class="btn btn-primary btn-sm">{% trans 'Associate' %}</button> <button type="button" class="btn btn-info btn-sm">{% trans 'Add' %}</button>
</td> </td>
</tr> </tr>
</form> </form>
...@@ -164,6 +195,7 @@ ...@@ -164,6 +195,7 @@
</table> </table>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -11,7 +11,7 @@ from django.db.models import Q ...@@ -11,7 +11,7 @@ from django.db.models import Q
from django.views.generic import TemplateView, ListView from django.views.generic import TemplateView, ListView
from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView, SingleObjectMixin
from .models import Asset, AssetGroup, IDC, AssetExtend from .models import Asset, AssetGroup, IDC, AssetExtend
from .forms import AssetForm, AssetGroupForm from .forms import AssetForm, AssetGroupForm
...@@ -56,6 +56,8 @@ class AssetGroupCreateView(CreateView): ...@@ -56,6 +56,8 @@ class AssetGroupCreateView(CreateView):
template_name = 'assets/asset_group_create.html' template_name = 'assets/asset_group_create.html'
success_url = reverse_lazy('assets:asset-group-list') success_url = reverse_lazy('assets:asset-group-list')
# Todo: Asset group create template select assets so hard, need be resolve next
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = { context = {
'app': _('Assets'), 'app': _('Assets'),
...@@ -99,15 +101,22 @@ class AssetGroupListView(ListView): ...@@ -99,15 +101,22 @@ class AssetGroupListView(ListView):
return self.queryset return self.queryset
class AssetGroupDetailView(DetailView): class AssetGroupDetailView(SingleObjectMixin, ListView):
template_name = 'assets/asset_group_detail.html' template_name = 'assets/asset_group_detail.html'
model = AssetGroup paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
context_object_name = 'asset_group'
def get(self, request, *args, **kwargs):
self.object = self.get_object(queryset=AssetGroup.objects.all())
return super(AssetGroupDetailView, self).get(request, *args, **kwargs)
def get_queryset(self):
return self.object.assets.all()
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = { context = {
'app': _('Assets'), 'app': _('Assets'),
'action': _('Asset group detail') 'action': _('Asset group detail'),
'asset_group': self.object,
} }
kwargs.update(context) kwargs.update(context)
return super(AssetGroupDetailView, self).get_context_data(**kwargs) return super(AssetGroupDetailView, self).get_context_data(**kwargs)
......
"""
jumpserver.__app__.hands.py
~~~~~~~~~~~~~~~~~
This app depends other apps api, function .. should be import or write mack here.
Other module of this app shouldn't connect with other app.
:copyright: (c) 2014-2016 by Jumpserver Team.
:license: GPL v2, see LICENSE for more details.
"""
...@@ -16,6 +16,7 @@ urlpatterns = [ ...@@ -16,6 +16,7 @@ urlpatterns = [
name='reset-password-success'), name='reset-password-success'),
url(r'^user$', views.UserListView.as_view(), name='user-list'), url(r'^user$', views.UserListView.as_view(), name='user-list'),
url(r'^user/(?P<pk>[0-9]+)$', views.UserDetailView.as_view(), name='user-detail'), url(r'^user/(?P<pk>[0-9]+)$', views.UserDetailView.as_view(), name='user-detail'),
url(r'^user/(?P<pk>[0-9]+)/assets-perm$', views.UserDetailView.as_view(), name='user-detail'),
url(r'^user/create$', views.UserCreateView.as_view(), name='user-create'), url(r'^user/create$', views.UserCreateView.as_view(), name='user-create'),
url(r'^user/(?P<pk>[0-9]+)/update$', views.UserUpdateView.as_view(), name='user-update'), url(r'^user/(?P<pk>[0-9]+)/update$', views.UserUpdateView.as_view(), name='user-update'),
url(r'^user/(?P<pk>[0-9]+)/delete$', views.UserDeleteView.as_view(), name='user-delete'), url(r'^user/(?P<pk>[0-9]+)/delete$', views.UserDeleteView.as_view(), name='user-delete'),
......
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