2021-09-28 10:25:07 -04:00
|
|
|
from django import forms
|
2022-11-03 11:58:26 -07:00
|
|
|
from django.utils.translation import gettext as _
|
2021-09-28 10:25:07 -04:00
|
|
|
|
|
|
|
from utilities.forms import BootstrapMixin, ExpandableNameField, form_from_model
|
|
|
|
from virtualization.models import VMInterface, VirtualMachine
|
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
'VMInterfaceBulkCreateForm',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class VirtualMachineBulkAddComponentForm(BootstrapMixin, forms.Form):
|
|
|
|
pk = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=VirtualMachine.objects.all(),
|
|
|
|
widget=forms.MultipleHiddenInput()
|
|
|
|
)
|
2022-09-15 10:10:32 -04:00
|
|
|
name = ExpandableNameField(
|
2022-11-03 11:58:26 -07:00
|
|
|
label=_('Name')
|
2021-09-28 10:25:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
def clean_tags(self):
|
|
|
|
# Because we're feeding TagField data (on the bulk edit form) to another TagField (on the model form), we
|
|
|
|
# must first convert the list of tags to a string.
|
|
|
|
return ','.join(self.cleaned_data.get('tags'))
|
|
|
|
|
|
|
|
|
|
|
|
class VMInterfaceBulkCreateForm(
|
|
|
|
form_from_model(VMInterface, ['enabled', 'mtu', 'description', 'tags']),
|
|
|
|
VirtualMachineBulkAddComponentForm
|
|
|
|
):
|
2022-09-15 10:10:32 -04:00
|
|
|
replication_fields = ('name',)
|