def __init__(self, *args, **kwargs): super(GroupEditForm, self).__init__(*args, **kwargs) if self.instance.id: self.fields['name'].widget.attrs['readonly'] = True initial_members = User.objects.filter( groups=self.instance).order_by( 'email' if ENABLE_ORGANIZATIONS.get() else 'username') initial_perms = HuePermission.objects.filter( grouppermission__group=self.instance).order_by( 'app', 'description') else: initial_members = [] initial_perms = [] self.fields["members"] = _make_model_field( _("members"), initial_members, User.objects.order_by('username')) self.fields["permissions"] = _make_model_field( _("permissions"), initial_perms, HuePermission.objects.order_by('app', 'description')) if 'organization' in self.fields: self.fields['organization'] = forms.ChoiceField( choices=((get_user_request_organization().id, get_user_request_organization()), ), initial=get_user_request_organization())
def __init__(self, *args, **kwargs): super(OrganizationUserChangeForm, self).__init__(*args, **kwargs) if self.instance.id: self.fields['email'].widget.attrs['readonly'] = True self.fields['organization'] = forms.ChoiceField( choices=((get_user_request_organization().id, get_user_request_organization()), ), initial=get_user_request_organization())
def __init__(self, *args, **kwargs): super(UserChangeForm, self).__init__(*args, **kwargs) if self.instance.id and 'username' in self.fields: self.fields['username'].widget.attrs['readonly'] = True if 'desktop.auth.backend.LdapBackend' in desktop_conf.AUTH.BACKEND.get( ): self.fields['password1'].widget.attrs['readonly'] = True self.fields['password2'].widget.attrs['readonly'] = True self.fields['password_old'].widget.attrs['readonly'] = True self.fields['first_name'].widget.attrs['readonly'] = True self.fields['last_name'].widget.attrs['readonly'] = True self.fields['email'].widget.attrs['readonly'] = True if 'is_active' in self.fields: self.fields['is_active'].widget.attrs['readonly'] = True if 'is_superuser' in self.fields: self.fields['is_superuser'].widget.attrs['readonly'] = True if 'unlock_account' in self.fields: self.fields['unlock_account'].widget.attrs['readonly'] = True if 'groups' in self.fields: self.fields['groups'].widget.attrs['readonly'] = True if ENABLE_ORGANIZATIONS.get(): organization = self.instance.organization if self.instance.id else get_user_request_organization( ) self.fields['groups'].choices = [ (group.id, group.name) for group in organization.organizationgroup_set.all() ]
def create_user(self, email=None, password=None, **extra_fields): """Create and save a regular User with the given email and password.""" if extra_fields.get('username'): email = extra_fields.pop('username') if not extra_fields.get('organization'): extra_fields['organization'] = get_user_request_organization() extra_fields.setdefault('is_staff', False) extra_fields.setdefault('is_superuser', False) extra_fields.setdefault('is_admin', False) return self._create_user(email, password, **extra_fields)
def __init__(self, *args, **kwargs): if not kwargs.get('organization'): kwargs['organization'] = get_user_request_organization() super(Connector, self).__init__(*args, **kwargs)