forked from ungleich-public/dynamicweb
fix virtual machine serializer e.t.c
This commit is contained in:
parent
afb096b7a3
commit
6b21b86ffe
5 changed files with 62 additions and 23 deletions
|
|
@ -307,30 +307,35 @@ class DCLSectionPromoPluginModel(CMSPlugin):
|
|||
class MultipleChoiceArrayField(ArrayField):
|
||||
"""
|
||||
A field that allows us to store an array of choices.
|
||||
|
||||
Uses Django's Postgres ArrayField
|
||||
and a MultipleChoiceField for its formfield.
|
||||
"""
|
||||
VMTemplateChoices = []
|
||||
if settings.OPENNEBULA_DOMAIN != 'test_domain':
|
||||
VMTemplateChoices = list(
|
||||
(
|
||||
str(obj.opennebula_vm_template_id),
|
||||
(obj.name + ' - ' + VMTemplate.IPV6.title()
|
||||
if obj.vm_type == VMTemplate.IPV6 else obj.name
|
||||
)
|
||||
)
|
||||
for obj in VMTemplate.objects.all()
|
||||
)
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
vm_template_choices = []
|
||||
|
||||
if settings.OPENNEBULA_DOMAIN != 'test_domain':
|
||||
vm_template_choices = [
|
||||
(
|
||||
str(obj.opennebula_vm_template_id),
|
||||
(
|
||||
obj.name + ' - ' + VMTemplate.IPV6.title()
|
||||
if obj.vm_type == VMTemplate.IPV6
|
||||
else obj.name
|
||||
),
|
||||
)
|
||||
for obj in VMTemplate.objects.all()
|
||||
]
|
||||
|
||||
defaults = {
|
||||
'form_class': forms.MultipleChoiceField,
|
||||
'choices': self.VMTemplateChoices,
|
||||
'choices': vm_template_choices,
|
||||
}
|
||||
|
||||
defaults.update(kwargs)
|
||||
# Skip our parent's formfield implementation completely as we don't
|
||||
# care for it.
|
||||
# pylint:disable=bad-super-call
|
||||
|
||||
# Skip ArrayField.formfield() because we don't need its implementation.
|
||||
return super(ArrayField, self).formfield(**defaults)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue