diff --git a/apps/assets/models.py b/apps/assets/models.py index 91a506a5e..740c2445e 100644 --- a/apps/assets/models.py +++ b/apps/assets/models.py @@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _ class AssetGroup(models.Model): name = models.CharField(max_length=64, unique=True, null=True, blank=True, verbose_name=_('Name')) created_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=_('Created by')) - comment = models.CharField(max_length=128, null=True, blank=True, verbose_name=_('Comment')) + comment = models.TextField(blank=True, verbose_name=_('Comment')) def __unicode__(self): return self.name @@ -27,7 +27,7 @@ class IDC(models.Model): date_added = models.DateField(auto_now=True, null=True, verbose_name=_('Date added')) operator = models.CharField(max_length=32, blank=True, verbose_name=_('Operator')) created_by = models.CharField(max_length=32, blank=True, verbose_name=_('Created by')) - comment = models.CharField(max_length=128, blank=True, verbose_name=_('Comment')) + comment = models.TextField(blank=True, verbose_name=_('Comment')) def __unicode__(self): return self.name @@ -37,11 +37,11 @@ class IDC(models.Model): class AssetExtend(models.Model): - key = models.CharField(max_length=64, null=True, blank=True, verbose_name=u'key') - value = models.CharField(max_length=64, null=True, blank=True, verbose_name=u'value') - created_by = models.CharField(max_length=32, blank=True, verbose_name=u"Created by") + key = models.CharField(max_length=64, null=True, blank=True, verbose_name=_('KEY')) + value = models.CharField(max_length=64, null=True, blank=True, verbose_name=_('VALUE')) + created_by = models.CharField(max_length=32, blank=True, verbose_name=_("Created by")) date_added = models.DateTimeField(auto_now=True, null=True, blank=True) - comment = models.CharField(max_length=128, blank=True, verbose_name=u"Comment") + comment = models.TextField(blank=True, verbose_name=_('Comment')) def __unicode__(self): return self.name @@ -51,15 +51,15 @@ class AssetExtend(models.Model): class AdminUser(models.Model): - name = models.CharField(max_length=128, unique=True, null=True, blank=True, verbose_name=u"用户名称") - username = models.CharField(max_length=16, null=True, blank=True, verbose_name=u"用户名") - password = models.CharField(max_length=256, null=True, blank=True, verbose_name=u"密码") - private_key = models.CharField(max_length=4096, null=True, blank=True, verbose_name=u"私钥") - is_default = models.BooleanField(default=True, verbose_name=u"是否默认") - auto_update = models.BooleanField(default=True, verbose_name=u"自动更新") + name = models.CharField(max_length=128, unique=True, null=True, blank=True, verbose_name=_('Name')) + username = models.CharField(max_length=16, null=True, blank=True, verbose_name=_('Username')) + password = models.CharField(max_length=256, null=True, blank=True, verbose_name=_('Password')) + private_key = models.CharField(max_length=4096, null=True, blank=True, verbose_name=_('SSH private key')) + is_default = models.BooleanField(default=True, verbose_name=_('As default')) + auto_update = models.BooleanField(default=True, verbose_name=_('Auto update pass/key')) date_added = models.DateTimeField(auto_now=True, null=True, blank=True) - create_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=u"创建者") - comment = models.CharField(max_length=128, blank=True, verbose_name=u"备注") + create_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=_('Created by')) + comment = models.TextField(blank=True, verbose_name=_('Comment')) def __unicode__(self): return self.name @@ -69,22 +69,26 @@ class AdminUser(models.Model): class SysUser(models.Model): - name = models.CharField(max_length=128, unique=True, null=True, blank=True, verbose_name=u"用户名称") - username = models.CharField(max_length=16, null=True, blank=True, verbose_name=u"用户名") - password = models.CharField(max_length=256, null=True, blank=True, verbose_name=u"密码") - protocol = models.CharField(max_length=16, null=True, blank=True, verbose_name=u"协议") - private_key = models.CharField(max_length=4096, null=True, blank=True, verbose_name=u"私钥") - public_key = models.CharField(max_length=4096, null=True, blank=True, verbose_name=u"公钥") - is_default = models.BooleanField(default=True, verbose_name=u"是否显示") - auto_push = models.BooleanField(default=True, verbose_name=u"自动推送") - auto_update = models.BooleanField(default=True, verbose_name=u"自动更新") - sudo = models.CharField(max_length=4096, null=True, blank=True, verbose_name=u"私钥") - shell = models.CharField(max_length=64, null=True, blank=True, verbose_name=u"shell环境") - home = models.CharField(max_length=64, null=True, blank=True, verbose_name=u"home目录") - uid = models.IntegerField(null=True, blank=True, verbose_name=u"uid") - date_added = models.DateTimeField(auto_now=True, null=True, blank=True) - create_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=u"创建者") - comment = models.CharField(max_length=128, blank=True, verbose_name=u"备注") + PROTOCOL_CHOICES = ( + ('ssh', 'ssh'), + ('telnet', 'telnet'), + ) + name = models.CharField(max_length=128, unique=True, verbose_name=_('Name')) + username = models.CharField(max_length=16, blank=True, verbose_name=_('Username')) + password = models.CharField(max_length=256, blank=True, verbose_name=_('Password')) + protocol = models.CharField(max_length=16, default='ssh', verbose_name=_('Protocol')) + private_key = models.CharField(max_length=4096, blank=True, verbose_name=_('SSH private key')) + public_key = models.CharField(max_length=4096, blank=True, verbose_name=_('SSH public key')) + is_default = models.BooleanField(default=True, verbose_name=_('As default')) + auto_push = models.BooleanField(default=True, verbose_name=_('Auto push')) + auto_update = models.BooleanField(default=True, verbose_name=_('Auto update pass/key')) + sudo = models.TextField(max_length=4096, blank=True, verbose_name=_('Sudo')) + shell = models.CharField(max_length=64, blank=True, verbose_name=_('Shell')) + home = models.CharField(max_length=64, blank=True, verbose_name=_('Home')) + uid = models.IntegerField(blank=True, verbose_name=_('Uid')) + date_added = models.DateTimeField(auto_now=True, null=True) + create_by = models.CharField(max_length=32, blank=True, verbose_name=_('Created by')) + comment = models.CharField(max_length=128, blank=True, verbose_name=_('Comment')) def __unicode__(self): return self.name @@ -114,12 +118,9 @@ class Asset(models.Model): cabinet_no = models.CharField(max_length=32, null=True, blank=True, verbose_name=_('Cabinet number')) cabinet_pos = models.IntegerField(null=True, blank=True, verbose_name=_('Cabinet position')) number = models.CharField(max_length=32, null=True, blank=True, unique=True, verbose_name=_('Asset number')) - status = models.ManyToManyField(AssetExtend, null=True, blank=True, - related_name="asset_status_extend", verbose_name=_('Asset status')) - type = models.ManyToManyField(AssetExtend, null=True, blank=True, - related_name="asset_type_extend", verbose_name=_('Asset type')) - env = models.ManyToManyField(AssetExtend, null=True, blank=True, - related_name="asset_env_extend", verbose_name=_('Asset environment')) + status = models.ManyToManyField(AssetExtend, related_name="asset_status_extend", verbose_name=_('Asset status')) + type = models.ManyToManyField(AssetExtend, related_name="asset_type_extend", verbose_name=_('Asset type')) + env = models.ManyToManyField(AssetExtend, related_name="asset_env_extend", verbose_name=_('Asset environment')) sn = models.CharField(max_length=128, null=True, blank=True, unique=True, verbose_name=_('Serial number')) created_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=_('Created by')) is_active = models.BooleanField(default=True, verbose_name=_('Is active')) @@ -134,11 +135,11 @@ class Asset(models.Model): class Label(models.Model): - key = models.CharField(max_length=64, null=True, blank=True, verbose_name=u'key') - value = models.CharField(max_length=64, null=True, blank=True, verbose_name=u'value') - asset = models.ForeignKey(Asset, null=True, blank=True, on_delete=models.SET_NULL, verbose_name=u'label') + key = models.CharField(max_length=64, null=True, blank=True, verbose_name=_('KEY')) + value = models.CharField(max_length=64, null=True, blank=True, verbose_name=_('VALUE')) + asset = models.ForeignKey(Asset, null=True, blank=True, on_delete=models.SET_NULL, verbose_name=_('Asset')) created_by = models.CharField(max_length=32, blank=True, verbose_name=_("Created by")) - date_added = models.DateTimeField(auto_now=True, null=True, blank=True) + date_added = models.DateTimeField(auto_now=True, null=True) comment = models.CharField(max_length=128, blank=True, verbose_name=_('Comment')) def __unicode__(self): @@ -147,4 +148,3 @@ class Label(models.Model): class Meta: db_table = 'label' - diff --git a/apps/assets/templates/assets/assetgroup_add.html b/apps/assets/templates/assets/assetgroup_add.html index e203341da..112eb0484 100644 --- a/apps/assets/templates/assets/assetgroup_add.html +++ b/apps/assets/templates/assets/assetgroup_add.html @@ -32,11 +32,11 @@ {{ form.name|bootstrap_horizontal }}
- +
- + {% for asset in assets %} + {% endfor %}
diff --git a/apps/assets/templates/assets/assetgroup_list.html b/apps/assets/templates/assets/assetgroup_list.html new file mode 100644 index 000000000..51605a549 --- /dev/null +++ b/apps/assets/templates/assets/assetgroup_list.html @@ -0,0 +1,59 @@ +{% extends '_list_base.html' %} +{% load i18n %} +{% load common_tags %} +{% block content_left_head %} + {% trans "Create asset group" %} +{% endblock %} + +{% block table_head %} + + + + {% trans 'Name' %} + {% trans 'Asset num' %} + {% trans 'Comment' %} + +{% endblock %} + +{% block table_body %} + {% for assetgroup in assetgroups %} + + + + + + + {{ assetgroup.name }} + + + {{ assetgroup.comment }} + {{ assetgroup.comment }} + + {% trans 'Edit' %} + {% trans 'Delete' %} + + + {% endfor %} +{% endblock %} + +{% block content_bottom_left %} + +{% endblock %} + + diff --git a/apps/assets/urls.py b/apps/assets/urls.py index 409bc6dca..8b92accb4 100644 --- a/apps/assets/urls.py +++ b/apps/assets/urls.py @@ -1,10 +1,9 @@ # coding:utf-8 from django.conf.urls import url, include -from .views import * +import views # from .api import ( # AssetGroupViewSet, AssetViewSet, IDCViewSet # ) -from django.conf.urls import url,include import views # from rest_framework import routers # router = routers.DefaultRouter() @@ -14,18 +13,16 @@ import views app_name = 'assets' urlpatterns = [ - url(r'^$', AssetListView.as_view(), name='asset-list'), - url(r'^(?P[0-9]+)/delete/$', AssetDeleteView.as_view(), name='asset-delete'), - url(r'^(?P[0-9]+)/detail/$', AssetDetailView.as_view(), name='asset-detail'), - url(r'^asset', views.AssetListView.as_view(), name='asset-list'), + url(r'^$', views.AssetListView.as_view(), name='asset-index'), + url(r'^asset$', views.AssetListView.as_view(), name='asset-list'), url(r'^asset/add$', views.AssetAddView.as_view(), name='asset-add'), url(r'^asset/(?P[0-9]+)$', views.AssetDetailView.as_view(), name='asset-detail'), url(r'^asset/(?P[0-9]+)$/edit', views.AssetEditView.as_view(), name='asset-edit'), url(r'^asset/(?P[0-9]+)/delete$', views.AssetDeleteView.as_view(), name='asset-delete'), - url(r'^asset-group', views.AssetGroupListView.as_view(), name='assetgroup-list'), - url(r'^asset-group/add$', views.AssetAddView.as_view(), name='asset-add'), - url(r'^asset-group/(?P[0-9]+)$', views.AssetDetailView.as_view(), name='asset-detail'), - url(r'^asset-group/(?P[0-9]+)$/edit', views.AssetEditView.as_view(), name='asset-edit'), - url(r'^asset-group/(?P[0-9]+)/delete$', views.AssetDeleteView.as_view(), name='asset-delete'), + url(r'^assetgroup$', views.AssetGroupListView.as_view(), name='assetgroup-list'), + url(r'^assetgroup/add$', views.AssetGroupAddView.as_view(), name='assetgroup-add'), + url(r'^assetgroup/(?P[0-9]+)$', views.AssetGroupDetailView.as_view(), name='assetgroup-detail'), + url(r'^assetgroup/(?P[0-9]+)$/edit', views.AssetGroupEditView.as_view(), name='assetgroup-edit'), + url(r'^assetgroup/(?P[0-9]+)/delete$', views.AssetGroupDeleteView.as_view(), name='assetgroup-delete'), # url(r'^api/v1.0/', include(router.urls)), ] diff --git a/apps/assets/views.py b/apps/assets/views.py index 96cb12441..246aeddf0 100644 --- a/apps/assets/views.py +++ b/apps/assets/views.py @@ -1,6 +1,7 @@ # coding:utf-8 from __future__ import absolute_import, unicode_literals +from django.utils.translation import ugettext as _ from django.views.generic import TemplateView, ListView from django.urls import reverse_lazy from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView @@ -10,7 +11,7 @@ from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateVi from django.urls import reverse_lazy from django.views.generic.detail import DetailView from .models import Asset, AssetGroup, IDC, AssetExtend -from .forms import AssetForm +from .forms import AssetForm, AssetGroupForm from .utils import AdminUserRequiredMixin @@ -49,11 +50,31 @@ class AssetDetailView(DetailView): class AssetGroupAddView(CreateView): model = AssetGroup + form_class = AssetGroupForm template_name = 'assets/assetgroup_add.html' + def get_context_data(self, **kwargs): + context = { + 'app': _('Assets'), + 'action': _('Create asset group'), + 'assets': Asset.objects.all(), + } + kwargs.update(context) + return super(AssetGroupAddView, self).get_context_data(**kwargs) + class AssetGroupListView(ListView): - pass + model = AssetGroup + context_object_name = 'assetgroups' + template_name = 'assets/assetgroup_list.html' + + def get_context_data(self, **kwargs): + context = { + 'app': _('Assets'), + 'action': _('Asset group list') + } + kwargs.update(context) + return super(AssetGroupListView, self).get_context_data(**kwargs) class AssetGroupDetailView(DetailView): diff --git a/apps/jumpserver/settings.py b/apps/jumpserver/settings.py index 25ce61a46..69f4b6486 100644 --- a/apps/jumpserver/settings.py +++ b/apps/jumpserver/settings.py @@ -215,7 +215,7 @@ LOGGING = { # Internationalization # https://docs.djangoproject.com/en/1.10/topics/i18n/ -LANGUAGE_CODE = 'zh_CN' +LANGUAGE_CODE = 'en_US' TIME_ZONE = 'Asia/Shanghai' diff --git a/apps/templates/_nav.html b/apps/templates/_nav.html index 99059d057..25313a891 100644 --- a/apps/templates/_nav.html +++ b/apps/templates/_nav.html @@ -18,8 +18,8 @@ {% trans 'Assets' %}