[Bugfix] 资产批量便捷

pull/1007/head
ibuler 2018-01-30 14:54:27 +08:00
parent 1fbf4ac08c
commit b4f833740e
1 changed files with 16 additions and 0 deletions

View File

@ -107,6 +107,15 @@ class AssetBulkUpdateForm(forms.ModelForm):
port = forms.IntegerField(
label=_('Port'), required=False, min_value=1, max_value=65535,
)
cluster = forms.ModelChoiceField(
required=False, label=_("Cluster"), queryset=Cluster.objects.all(),
widget=forms.Select(
attrs={
'class': 'select2',
'data-placeholder': _('Select cluster')
}
)
)
class Meta:
model = Asset
@ -117,6 +126,9 @@ class AssetBulkUpdateForm(forms.ModelForm):
'groups': forms.SelectMultiple(
attrs={'class': 'select2', 'data-placeholder': _('Select asset groups')}
),
'labels': forms.SelectMultiple(
attrs={'class': 'select2', 'data-placeholder': _('Select lables')}
),
}
def save(self, commit=True):
@ -129,11 +141,15 @@ class AssetBulkUpdateForm(forms.ModelForm):
if k in changed_fields}
assets = cleaned_data.pop('assets')
groups = cleaned_data.pop('groups', [])
labels = cleaned_data.pop('labels', [])
assets = Asset.objects.filter(id__in=[asset.id for asset in assets])
assets.update(**cleaned_data)
if groups:
for asset in assets:
asset.groups.set(groups)
if labels:
for asset in assets:
asset.labels.set(labels)
return assets