在我的自定义工作流中,我有一个动作,除其他外,它应该向用户显示可用 OpenStack 图像和风格的列表。我的假设是,填充这两个列表的最佳位置在__init__
方法内。目前,我的看起来像这样:
class SetWorkflowInfoAction(workflows.Action):
name = forms.CharField(max_length="255", label=_("Workload Name"))
description = forms.CharField(widget=forms.Textarea,
label=_("Description"), required=False)
image_choices = []
images = forms.ChoiceField(label=_("Images"), choices=image_choices)
flavor_choices = []
flavors = forms.ChoiceField(label=_("Flavors"), choices=flavor_choices)
def __init__(self, request, image_choices=image_choices, flavor_choices=flavor_choices,
*args, **kwargs):
super(SetWorkflowInfoAction, self).__init__(request, *args, **kwargs)
image_choices = []
flavor_choices = []
images, self._more, self._prev = api.glance.image_list_detailed(
self.request)
flavors = api.nova.flavor_list(request, True)
for image in images:
image_choices.append((image.id, image.name))
if len(image_choices) > 1:
image_choices.insert(0, ('', _("Select an Image")))
self.fields['images'].choices = image_choices
for flavor in flavors:
flavor_choices.append((flavor.id, flavor.name))
if len(flavor_choices) > 1:
flavor_choices.insert(0, ('', _("Select an Flavor")))
self.fields['flavors'].choices = flavor_choices
class Meta:
name = _("Basic Workload Information")
help_text = _("")
slug = "set_workflow_info"
问题是 - 当我到达打电话的地步时,__init__
我收到了这个错误:
File "/home/eugene/dev/horizon/openstack_dashboard/dashboards/mydashboard/workloads_panel/workflows.py", line 20, in __init__
super(SetWorkflowInfoAction, self).__init__(request, *args, **kwargs)
TypeError: __init__() takes at least 3 arguments (2 given)
以这种方式调用的正确方法是什么__init__
,以便我可以填充我的图像和口味列表?