def __init__(self, request, *args, **kwargs): super(AddProjectAction, self).__init__(request, *args, **kwargs) default_role_field_name = self.get_default_role_field_name() self.fields[default_role_field_name] = forms.CharField(required=False) self.fields[default_role_field_name].initial = 'member' field_name = self.get_member_field_name('member') self.fields[field_name] = forms.MultipleChoiceField(required=False) share_group_type_id = self.initial['id'] # Get list of existing projects try: projects, __ = keystone.tenant_list(request) except Exception: err_msg = _('Unable to get list of projects.') exceptions.handle(request, err_msg) # Get list of projects with access to this Share Group Type try: share_group_type = manila.share_group_type_get( request, share_group_type_id) self.share_group_type_name = share_group_type.name projects_initial = manila.share_group_type_access_list( request, share_group_type) except Exception: err_msg = _( 'Unable to get information about share group type access.') exceptions.handle(request, err_msg) self.fields[field_name].choices = [ (project.id, project.name or project.id) for project in projects] self.fields[field_name].initial = [ pr.project_id for pr in projects_initial] self.projects_initial = set(self.fields[field_name].initial)
def test_share_group_type_access_list(self): sgt = 'fake_share_group_type' result = api.share_group_type_access_list(self.request, sgt) self.assertIsNotNone(result) self.assertEqual( self.manilaclient.share_group_type_access.list.return_value, result) self.manilaclient.share_group_type_access.list.assert_called_once_with( sgt)
def test_share_group_type_access_list(self): sgt = 'fake_share_group_type' result = api.share_group_type_access_list(self.request, sgt) self.assertIsNotNone(result) self.assertEqual( self.manilaclient.share_group_type_access.list.return_value, result) self.manilaclient.share_group_type_access.list.assert_called_once_with( sgt)
def __init__(self, request, *args, **kwargs): super(AddProjectAction, self).__init__(request, *args, **kwargs) default_role_field_name = self.get_default_role_field_name() self.fields[default_role_field_name] = forms.CharField(required=False) self.fields[default_role_field_name].initial = 'member' field_name = self.get_member_field_name('member') self.fields[field_name] = forms.MultipleChoiceField(required=False) share_group_type_id = self.initial['id'] # Get list of existing projects try: projects, __ = keystone.tenant_list(request) except Exception: err_msg = _('Unable to get list of projects.') exceptions.handle(request, err_msg) # Get list of projects with access to this Share Group Type try: share_group_type = manila.share_group_type_get( request, share_group_type_id) self.share_group_type_name = share_group_type.name projects_initial = manila.share_group_type_access_list( request, share_group_type) except Exception: err_msg = _( 'Unable to get information about share group type access.') exceptions.handle(request, err_msg) self.fields[field_name].choices = [(project.id, project.name or project.id) for project in projects] self.fields[field_name].initial = [ pr.project_id for pr in projects_initial ] self.projects_initial = set(self.fields[field_name].initial)