def test_get_groups(self): """Test getting groups according to community name""" groups = get_groups("Foo") self.assertSequenceEqual(groups, []) name = "Bar" create_groups(name) community_groups = Group.objects.all() groups = get_groups("Bar") self.assertCountEqual(community_groups, groups) create_groups("New") groups = get_groups("Bar") self.assertCountEqual(community_groups, groups)
def leave_groups(self, community_name): """Leave all groups that are related to a community. :param community: string name of Community """ groups = get_groups(community_name) for group in groups: self.leave_group(group)
def __init__(self, *args, **kwargs): self.user = kwargs.pop('user') community = kwargs.pop('community') super(PermissionGroupsForm, self).__init__(*args, **kwargs) # get all community groups and remove community admin group # from the list of choices self.groups = list(get_groups(community.name)) admin_group = Group.objects.get( name=COMMUNITY_ADMIN.format(community.name)) self.groups.remove(admin_group) choices = [(group.pk, group.name) for group in self.groups] self.fields['groups'] = forms.\ MultipleChoiceField(choices=choices, label="", required=False, widget=forms.CheckboxSelectMultiple) self.member_groups = self.user.get_member_groups(self.groups) self.fields['groups'].initial = [group.pk for group in self.member_groups] self.helper = SubmitCancelFormHelper( self, cancel_href="{% url 'community_users' community.slug %}")
def __init__(self, *args, **kwargs): self.user = kwargs.pop('user') community = kwargs.pop('community') super(PermissionGroupsForm, self).__init__(*args, **kwargs) # get all community groups and remove community admin group # from the list of choices self.groups = list(get_groups(community.name)) admin_group = Group.objects.get( name=COMMUNITY_ADMIN.format(community.name)) self.groups.remove(admin_group) choices = [(group.pk, group.name) for group in self.groups] self.fields['groups'] = forms. \ MultipleChoiceField(choices=choices, label="", required=False, widget=forms.CheckboxSelectMultiple) self.member_groups = self.user.get_member_groups(self.groups) self.fields['groups'].initial = [ group.pk for group in self.member_groups ] self.helper = SubmitCancelFormHelper( self, cancel_href="{% url 'community_users' community.slug %}")