def __init__(self, name_check=False, *args, **kwargs): super(GroupForm, self).__init__(*args, **kwargs) self.name_check = name_check try: if kwargs['initial']['owners']: pass self.fields['owners'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], initial=kwargs['initial']['owners'], required=False) except: self.fields['owners'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], required=False) try: if kwargs['initial']['members']: pass self.fields['members'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], initial=kwargs['initial']['members'], required=False) except: self.fields['members'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], required=False) self.fields['permissions'] = forms.ChoiceField( choices=PERMISSION_CHOICES, widget=forms.RadioSelect(), required=True, label="Permissions") self.fields.keyOrder = [ 'name', 'description', 'owners', 'members', 'permissions' ]
def __init__(self, *args, **kwargs): super(GroupOwnerForm, self).__init__(*args, **kwargs) try: if kwargs['initial']['owners']: pass self.fields['owners'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], initial=kwargs['initial']['owners'], required=False) except: self.fields['owners'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], required=False) try: if kwargs['initial']['members']: pass self.fields['members'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], initial=kwargs['initial']['members'], required=False) except: self.fields['members'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], required=False) self.fields.keyOrder = ['owners', 'members', 'permissions']
def __init__(self, name_check=False, group_is_current_or_system=False, *args, **kwargs): super(GroupForm, self).__init__(*args, **kwargs) self.name_check = name_check try: if kwargs['initial']['owners']: pass self.fields['owners'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], initial=kwargs['initial']['owners'], required=False) except: self.fields['owners'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], required=False) try: if kwargs['initial']['members']: pass self.fields['members'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], initial=kwargs['initial']['members'], required=False) except: self.fields['members'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], required=False) self.fields['permissions'] = forms.ChoiceField( choices=PERMISSION_CHOICES, widget=forms.RadioSelect(), required=True, label="Permissions") if group_is_current_or_system: self.fields['name'].widget.attrs['readonly'] = True self.fields['name'].widget.attrs['title'] = \ "Changing of system groupname would be un-doable" self.fields.keyOrder = [ 'name', 'description', 'owners', 'members', 'permissions' ]
def __init__(self, name_check=False, group_is_system=False, can_modify_group=True, can_add_member=True, *args, **kwargs): super(GroupForm, self).__init__(*args, **kwargs) self.name_check = name_check if can_modify_group: self.fields['name'] = forms.CharField( max_length=100, widget=forms.TextInput(attrs={ 'size': 25, 'autocomplete': 'off' })) self.fields['description'] = forms.CharField( max_length=250, required=False, widget=forms.TextInput(attrs={ 'size': 25, 'autocomplete': 'off' })) if can_add_member: try: if kwargs['initial']['owners']: pass self.fields['owners'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], initial=kwargs['initial']['owners'], required=False) except: self.fields['owners'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], required=False) try: if kwargs['initial']['members']: pass self.fields['members'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], initial=kwargs['initial']['members'], required=False) except: self.fields['members'] = ExperimenterModelMultipleChoiceField( queryset=kwargs['initial']['experimenters'], required=False) if can_modify_group: self.fields['permissions'] = forms.ChoiceField( choices=PERMISSION_CHOICES, widget=forms.RadioSelect(), required=True, label="Permissions") if group_is_system: self.fields['name'].widget.attrs['readonly'] = True self.fields['name'].widget.attrs['title'] = \ "Changing of system group name would be un-doable" self.fields.keyOrder = [ 'name', 'description', 'owners', 'members', 'permissions' ] # If we can't modify group, disable fields if not can_modify_group: for name, field in self.fields.items(): if name not in ('owners', 'members'): field.widget.attrs['disabled'] = True