Revision history [back]

click to hide/show revision 1
initial version
 project = forms.ChoiceField(label=_("Project"),
                                required=True)

    def __init__(self, request, *args, **kwargs):
        super(CreateAlarmInfoAction, self).__init__(request,
                                                    *args, **kwargs)
        self.fields['project'].choices = (
            self.get_project_list_choices(request))

    def get_project_list_choices(self, request):
        project_choices = [('', _("Select a Project"))]
        list_of_projects = self._get_projects(request)
        for obj in list_of_projects:
            project_choices.append((obj.id, obj.name))
        return project_choices

    def _get_projects(self, request):
        projects = []
        try:
            projects, has_more = api.keystone.tenant_list(request)
        except Exception:
            msg = _('Project list cannot be retrieved.')
            exceptions.handle(request, msg)
        return projects

I am able to display the list of projects as a dropdown menu

 project = forms.ChoiceField(label=_("Project"),
                                required=True)

    def __init__(self, request, *args, **kwargs):
        super(CreateAlarmInfoAction, super(CreateAction, self).__init__(request,
                                                    *args, **kwargs)
        self.fields['project'].choices = (
            self.get_project_list_choices(request))

    def get_project_list_choices(self, request):
        project_choices = [('', _("Select a Project"))]
        list_of_projects = self._get_projects(request)
        for obj in list_of_projects:
            project_choices.append((obj.id, obj.name))
        return project_choices

    def _get_projects(self, request):
        projects = []
        try:
            projects, has_more = api.keystone.tenant_list(request)
        except Exception:
            msg = _('Project list cannot be retrieved.')
            exceptions.handle(request, msg)
        return projects

I am able to display the list of projects as a dropdown menu