def __init__(self, request, *args, **kwargs):
    super(UpdateProjectGroupsAction, self).__init__(request, *args, **kwargs)
    err_msg = _('Unable to retrieve group list. Please try again later.')
    domain_id = self.initial.get('domain_id', None)
    project_id = ''
    if ('project_id' in self.initial):
        project_id = self.initial['project_id']
    try:
        default_role = api.keystone.get_default_role(self.request)
        if (default_role is None):
            default = settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE
            msg = (_('Could not find default role "%s" in Keystone') % default)
            raise exceptions.NotFound(msg)
    except Exception:
        exceptions.handle(self.request, err_msg, redirect=reverse(INDEX_URL))
    default_role_name = self.get_default_role_field_name()
    self.fields[default_role_name] = forms.CharField(required=False)
    self.fields[default_role_name].initial = default_role.id
    all_groups = []
    try:
        all_groups = api.keystone.group_list(request, domain=domain_id)
    except Exception:
        exceptions.handle(request, err_msg)
    groups_list = [(group.id, getattr(group, 'name', group.id)) for group in all_groups]
    role_list = []
    try:
        role_list = api.keystone.role_list(request)
    except Exception:
        exceptions.handle(request, err_msg, redirect=reverse(INDEX_URL))
    for role in role_list:
        field_name = self.get_member_field_name(role.id)
        label = role.name
        self.fields[field_name] = forms.MultipleChoiceField(required=False, label=label)
        self.fields[field_name].choices = groups_list
        self.fields[field_name].initial = []
    if project_id:
        try:
            groups_roles = api.keystone.get_project_groups_roles(request, project_id)
        except Exception:
            exceptions.handle(request, err_msg, redirect=reverse(INDEX_URL))
        for group_id in groups_roles:
            roles_ids = groups_roles[group_id]
            for role_id in roles_ids:
                field_name = self.get_member_field_name(role_id)
                self.fields[field_name].initial.append(group_id)
def __init__(self, request, *args, **kwargs):
    super(UpdateProjectGroupsAction, self).__init__(request, *args, **kwargs)
    err_msg = _('Unable to retrieve group list. Please try again later.')
    domain_id = self.initial.get('domain_id', None)
    project_id = 
    if ('project_id' in self.initial):
        project_id = self.initial['project_id']
    try:
        default_role = api.keystone.get_default_role(self.request)
        if (default_role is None):
            default = settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE
            msg = (_('Could not find default role "%s" in Keystone') % default)
            raise exceptions.NotFound(msg)
    except Exception:
        exceptions.handle(self.request, err_msg, redirect=reverse(INDEX_URL))
    default_role_name = self.get_default_role_field_name()
    self.fields[default_role_name] = forms.CharField(required=False)
    self.fields[default_role_name].initial = default_role.id
    all_groups = []
    try:
        all_groups = api.keystone.group_list(request, domain=domain_id)
    except Exception:
        exceptions.handle(request, err_msg)
    groups_list = [(group.id, getattr(group, 'name', group.id)) for group in all_groups]
    role_list = []
    try:
        role_list = api.keystone.role_list(request)
    except Exception:
        exceptions.handle(request, err_msg, redirect=reverse(INDEX_URL))
    for role in role_list:
        field_name = self.get_member_field_name(role.id)
        label = role.name
        self.fields[field_name] = forms.MultipleChoiceField(required=False, label=label)
        self.fields[field_name].choices = groups_list
        self.fields[field_name].initial = []
    if project_id:
        try:
            groups_roles = api.keystone.get_project_groups_roles(request, project_id)
        except Exception:
            exceptions.handle(request, err_msg, redirect=reverse(INDEX_URL))
        for group_id in groups_roles:
            roles_ids = groups_roles[group_id]
            for role_id in roles_ids:
                field_name = self.get_member_field_name(role_id)
                self.fields[field_name].initial.append(group_id)