From 1fbf4ac08c25191b2a28b580343eb155df33980e Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 30 Jan 2018 14:46:02 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E5=88=A0=E9=99=A4=E9=83=A8=E5=88=86?= =?UTF-8?q?=E8=B5=84=E4=BA=A7=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/forms.py | 15 ++------ apps/assets/models/asset.py | 26 ------------- apps/assets/serializers.py | 1 - .../assets/templates/assets/asset_create.html | 2 - .../assets/templates/assets/asset_detail.html | 38 ------------------- .../assets/templates/assets/asset_update.html | 9 ----- 6 files changed, 4 insertions(+), 87 deletions(-) diff --git a/apps/assets/forms.py b/apps/assets/forms.py index 7c069d9ee..96106d89f 100644 --- a/apps/assets/forms.py +++ b/apps/assets/forms.py @@ -12,9 +12,8 @@ class AssetCreateForm(forms.ModelForm): class Meta: model = Asset fields = [ - 'hostname', 'ip', 'public_ip', 'port', 'type', 'comment', - 'cluster', 'groups', 'status', 'env', 'is_active', - 'admin_user', 'labels' + 'hostname', 'ip', 'public_ip', 'port', 'comment', 'cluster', + 'groups', 'is_active', 'admin_user', 'labels' ] widgets = { @@ -61,8 +60,7 @@ class AssetUpdateForm(forms.ModelForm): model = Asset fields = [ 'hostname', 'ip', 'port', 'groups', "cluster", 'is_active', - 'type', 'env', 'status', 'public_ip', 'remote_card_ip', 'cabinet_no', - 'cabinet_pos', 'number', 'comment', 'admin_user', 'labels' + 'public_ip', 'number', 'comment', 'admin_user', 'labels' ] widgets = { 'groups': forms.SelectMultiple(attrs={ @@ -94,10 +92,6 @@ class AssetUpdateForm(forms.ModelForm): raise forms.ValidationError(_("You need set a admin user if cluster not have")) return self.cleaned_data['admin_user'] - def is_valid(self): - print(self.data) - return super().is_valid() - class AssetBulkUpdateForm(forms.ModelForm): assets = forms.ModelMultipleChoiceField( @@ -117,8 +111,7 @@ class AssetBulkUpdateForm(forms.ModelForm): class Meta: model = Asset fields = [ - 'assets', 'port', 'groups', "cluster", - 'type', 'env', + 'assets', 'port', 'groups', "cluster", 'labels' ] widgets = { 'groups': forms.SelectMultiple( diff --git a/apps/assets/models/asset.py b/apps/assets/models/asset.py index 0b1cdf0ec..3677b04b5 100644 --- a/apps/assets/models/asset.py +++ b/apps/assets/models/asset.py @@ -29,25 +29,6 @@ def default_cluster(): class Asset(models.Model): - # Todo: Move them to settings - STATUS_CHOICES = ( - ('In use', _('In use')), - ('Out of use', _('Out of use')), - ) - TYPE_CHOICES = ( - ('Server', _('Server')), - ('VM', _('VM')), - ('Switch', _('Switch')), - ('Router', _('Router')), - ('Firewall', _('Firewall')), - ('Storage', _("Storage")), - ) - ENV_CHOICES = ( - ('Prod', _('Production')), - ('Dev', _('Development')), - ('Test', _('Testing')), - ) - # Important id = models.UUIDField(default=uuid.uuid4, primary_key=True) ip = models.GenericIPAddressField(max_length=32, verbose_name=_('IP'), db_index=True) @@ -56,18 +37,12 @@ class Asset(models.Model): groups = models.ManyToManyField(AssetGroup, blank=True, related_name='assets', verbose_name=_('Asset groups')) cluster = models.ForeignKey(Cluster, related_name='assets', default=default_cluster, on_delete=models.SET_DEFAULT, verbose_name=_('Cluster')) is_active = models.BooleanField(default=True, verbose_name=_('Is active')) - type = models.CharField(choices=TYPE_CHOICES, max_length=16, blank=True, null=True, default='Server', verbose_name=_('Asset type'),) - env = models.CharField(choices=ENV_CHOICES, max_length=8, blank=True, null=True, default='Prod', verbose_name=_('Asset environment'),) - status = models.CharField(choices=STATUS_CHOICES, max_length=12, null=True, blank=True, default='In use', verbose_name=_('Asset status')) # Auth admin_user = models.ForeignKey('assets.AdminUser', null=True, blank=True, on_delete=models.SET_NULL, verbose_name=_("Admin user")) # Some information public_ip = models.GenericIPAddressField(max_length=32, blank=True, null=True, verbose_name=_('Public IP')) - remote_card_ip = models.CharField(max_length=16, null=True, blank=True, verbose_name=_('Remote control card IP')) - 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, verbose_name=_('Asset number')) # Collect @@ -89,7 +64,6 @@ class Asset(models.Model): hostname_raw = models.CharField(max_length=128, blank=True, null=True, verbose_name=_('Hostname raw')) labels = models.ManyToManyField('assets.Label', blank=True, related_name='assets', verbose_name=_("Labels")) - created_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=_('Created by')) date_created = models.DateTimeField(auto_now_add=True, null=True, blank=True, verbose_name=_('Date created')) comment = models.TextField(max_length=128, default='', blank=True, verbose_name=_('Comment')) diff --git a/apps/assets/serializers.py b/apps/assets/serializers.py index 1fd6e1d9a..1b40ef371 100644 --- a/apps/assets/serializers.py +++ b/apps/assets/serializers.py @@ -173,7 +173,6 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer): def get_field_names(self, declared_fields, info): fields = super().get_field_names(declared_fields, info) fields.extend([ - 'get_type_display', 'get_env_display', 'hardware_info', 'is_connective', ]) return fields diff --git a/apps/assets/templates/assets/asset_create.html b/apps/assets/templates/assets/asset_create.html index 0fb2f6002..4c5f12fdd 100644 --- a/apps/assets/templates/assets/asset_create.html +++ b/apps/assets/templates/assets/asset_create.html @@ -19,8 +19,6 @@ {% bootstrap_field form.port layout="horizontal" %} {% bootstrap_field form.cluster layout="horizontal" %} {% bootstrap_field form.public_ip layout="horizontal" %} - {% bootstrap_field form.type layout="horizontal" %} - {% bootstrap_field form.env layout="horizontal" %}

{% trans 'Auth' %}

diff --git a/apps/assets/templates/assets/asset_detail.html b/apps/assets/templates/assets/asset_detail.html index 346a52723..e7b136555 100644 --- a/apps/assets/templates/assets/asset_detail.html +++ b/apps/assets/templates/assets/asset_detail.html @@ -77,22 +77,10 @@ {% endif %} - - {% trans 'Remote card IP' %}: - {{ asset.remote_card_ip|default:"" }} - {% trans 'Cluster' %}: {{ asset.cluster.name }} - - {% trans 'Cabinet number' %}: - {{ asset.cabinet_no|default:"" }} - - - {% trans 'Cabinet position' %}: - {{ asset.cabinet_pos|default:"" }} - {% trans 'Vendor' %}: {{ asset.vendor|default:"" }} @@ -121,22 +109,10 @@ {% trans 'OS' %}: {{ asset.os|default:"" }} {{ asset.os_version|default:"" }} {{ asset.os_arch|default:"" }} - - {% trans 'Asset status' %}: - {{ asset.status }} - {% trans 'Is active' %}: {{ asset.is_active|yesno:"Yes,No" }} - - {% trans 'Asset type' %}: - {{ asset.type }} - - - {% trans 'Asset environment' %}: - {{ asset.env }} - {% trans 'Serial number' %}: {{ asset.sn|default:"" }} @@ -250,20 +226,6 @@ {% trans 'Labels' %}
-{# #} -{# #} -{# {% for label in asset.labels.all %}#} -{# #} -{# #} -{# #} -{# #} -{# {% endfor %}#} -{# #} -{#
{{ label.name }}#} -{# #} -{# {{ label.value }}#} -{# #} -{#
#}