Beispiel #1
0
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user', None)
        super(CommunityForm, self).__init__(*args, **kwargs)

        # get the valid parents for a user if we have a user
        if user:
            group = kwargs.get('instance', None)
            valid_parents = get_valid_parents(
                user, group=group,
                model=Network)  # only networks may be parent to a community
            self.fields['parent'].queryset = valid_parents
            self.fields['parent'].label = "Chapter"
            self.fields[
                'parent'].help_text = "If a chapter set, this community will show up on the chapter's info page and chapter execs will also have access to it."

        # set the initial visibility state (since it's not a direct mapping to
        # a model field, it isn't done automatically)
        if self.instance.pk:
            # not sure why "if self.instance" doesn't work; that's set even for a new form

            if not self.instance.invite_only:
                self.fields['group_permissions'].initial = 'P'
            elif self.instance.visibility == 'E':
                self.fields['group_permissions'].initial = 'I'
            elif self.instance.visibility == 'M':
                self.fields['group_permissions'].initial = 'R'

            # hack way to see if this is actually a NationalRepList or ExecList instance
            # (self.instance.__class__ doesn't work, since the object is instantiated as a community)
            try:
                if getattr(self.instance, "nationalreplist"):
                    del self.fields['group_permissions']
            except:
                pass
            try:
                if getattr(self.instance, "execlist"):
                    del self.fields['group_permissions']
            except:
                pass

            # and don't let people change chapters after a community is created
            del self.fields['parent']
Beispiel #2
0
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user', None)
        super(CommunityForm, self).__init__(*args, **kwargs)

        # get the valid parents for a user if we have a user
        if user:
            group = kwargs.get('instance', None)
            valid_parents = get_valid_parents(user, group=group, model=Network)     # only networks may be parent to a community
            self.fields['parent'].queryset = valid_parents
            
        # set the initial visibility state (since it's not a direct mapping to 
        # a model field, it isn't done automatically)        
        if self.instance.pk:
            # not sure why "if self.instance" doesn't work; that's set even for a new form
            if not self.instance.invite_only:
                self.fields['group_permissions'].initial='P'
            elif self.instance.visibility == 'E':
                self.fields['group_permissions'].initial='I'
            elif self.instance.visibility == 'M':
                self.fields['group_permissions'].initial='R'
Beispiel #3
0
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user', None)
        super(CommunityForm, self).__init__(*args, **kwargs)

        # get the valid parents for a user if we have a user
        if user:
            group = kwargs.get('instance', None)
            valid_parents = get_valid_parents(user, group=group, model=Network)     # only networks may be parent to a community
            self.fields['parent'].queryset = valid_parents
            self.fields['parent'].label = "Chapter"
            self.fields['parent'].help_text = "If a chapter set, this community will show up on the chapter's info page and chapter execs will also have access to it."
            
        # set the initial visibility state (since it's not a direct mapping to 
        # a model field, it isn't done automatically)        
        if self.instance.pk:
            # not sure why "if self.instance" doesn't work; that's set even for a new form

            if not self.instance.invite_only:
                self.fields['group_permissions'].initial='P'
            elif self.instance.visibility == 'E':
                self.fields['group_permissions'].initial='I'
            elif self.instance.visibility == 'M':
                self.fields['group_permissions'].initial='R'

            # hack way to see if this is actually a NationalRepList or ExecList instance
            # (self.instance.__class__ doesn't work, since the object is instantiated as a community)
            try:
                if getattr(self.instance, "nationalreplist"):
                    del self.fields['group_permissions']
            except: 
                pass
            try:
                if getattr(self.instance, "execlist"):
                    del self.fields['group_permissions']
            except:
                pass
            
            # and don't let people change chapters after a community is created
            del self.fields['parent']