class Meta: model = UserEmail fields = ('email', 'primary', 'confirmed') widgets = { 'email': bootstrap.EmailInput(), 'primary': bootstrap.CheckboxInput(), 'confirmed': bootstrap.CheckboxInput() }
class Meta: model = Application fields = ('title', 'url', 'notes', 'is_active', 'is_internal') widgets = { 'title': bootstrap.TextInput(attrs={'size': 50}), 'notes': bootstrap.Textarea(attrs={'rows': '5'}), 'url': bootstrap.TextInput(attrs={'size': 50}), 'is_active': bootstrap.CheckboxInput(), 'is_internal': bootstrap.CheckboxInput(), }
class Meta: model = Organisation fields = ('name_native', 'homepage', 'source_urls', 'google_plus_page', 'facebook_page', 'twitter_page', 'founded', 'coordinates_type', 'is_private', 'is_live', 'location', 'neighbour_distance', 'transregional_distance', 'timezone') years_to_display = range(datetime.datetime.now().year - 100, datetime.datetime.now().year + 1) widgets = { 'homepage': bootstrap.URLInput(attrs={'size': 50}), 'source_urls': bootstrap.Textarea(attrs={'rows': '3'}), 'google_plus_page': bootstrap.URLInput(attrs={'size': 50}), 'facebook_page': bootstrap.URLInput(attrs={'size': 50}), 'twitter_page': bootstrap.URLInput(attrs={'size': 50}), 'association': bootstrap.Select(), 'name': bootstrap.TextInput(attrs={'size': 50}), 'name_native': bootstrap.TextInput(attrs={'size': 50}), 'founded': bootstrap.SelectDateWidget(years=years_to_display), 'coordinates_type': bootstrap.Select(), 'center_type': bootstrap.Select(), 'is_private': bootstrap.CheckboxInput(), 'is_active': bootstrap.CheckboxInput(), 'is_live': bootstrap.CheckboxInput(), 'timezone': bootstrap.Select2(), 'location': bootstrap.OSMWidget(), 'neighbour_distance': bootstrap.TextInput(attrs={ 'type': 'number', 'step': '0.001' }), 'transregional_distance': bootstrap.TextInput(attrs={ 'type': 'number', 'step': '0.001' }), }
class Meta: model = ApplicationRole fields = ( 'role', 'is_inheritable_by_org_admin', 'is_inheritable_by_global_admin', 'is_organisation_related', ) widgets = { 'is_inheritable_by_org_admin': bootstrap.CheckboxInput(), 'is_inheritable_by_global_admin': bootstrap.CheckboxInput(), 'is_organisation_related': bootstrap.CheckboxInput(), }
class Meta: model = UserPhoneNumber fields = ('phone_type', 'phone', 'primary') widgets = { 'phone_type': bootstrap.Select(), 'phone': bootstrap.TextInput(attrs={'size': 50}), 'primary': bootstrap.CheckboxInput() }
class EmailAuthenticationForm(AuthenticationForm): labels = { 'username': capfirst(_("Email address or Username")), 'password': capfirst(_("Password")) } username = forms.CharField( max_length=75, error_messages={ 'required': _('Please enter your Email address or Username.') }, label=labels.get('username'), widget=bootstrap.TextInput( attrs={ 'placeholder': labels.get('username'), 'autofocus': True, 'autocapitalize': 'none', 'class': 'form-control-lg', 'autocomplete': 'username' })) password = forms.CharField( label=labels.get('password'), error_messages={'required': _('Please enter your Password.')}, widget=bootstrap.PasswordInput( attrs={ 'placeholder': labels.get('password'), 'class': 'form-control-lg', 'autocomplete': 'current-password' })) remember_me = forms.BooleanField( label=_('Remember me'), help_text=string_format( _('Stay logged in for %(days)d days'), {'days': timedelta(seconds=settings.SESSION_COOKIE_AGE).days}), required=False, widget=bootstrap.CheckboxInput()) error_messages = { 'invalid_login': _("Please enter a correct %(username)s and password. Note that both fields may be case-sensitive." ), 'inactive': _("This account is inactive."), 'expired': _("This account has expired. Please contact the user administrator in your organisation %s." ), 'whitespaces': _("Please enter your Email address or Username without whitespaces at the beginning or end." ), } def clean_username(self): # check if there are whitespaces at the beginning or end of the username data = self.cleaned_data['username'] if data and data != data.strip(): raise forms.ValidationError(self.error_messages['whitespaces'], code='whitespaces') return data
class Meta: model = Client fields = ('application', 'uuid', 'client_secret', 'name', 'type', 'redirect_uris', 'post_logout_redirect_uris', 'notes', 'is_active', 'scopes') widgets = { 'application': bootstrap.HiddenInput(), 'name': bootstrap.TextInput(attrs={'size': 50}), 'client_secret': bootstrap.TextInput(attrs={'readonly': True}), 'notes': bootstrap.Textarea(attrs={'rows': '3'}), 'redirect_uris': bootstrap.Textarea(attrs={'rows': '3'}), 'post_logout_redirect_uris': bootstrap.Textarea(attrs={'rows': '3'}), 'is_active': bootstrap.CheckboxInput(), }
class Meta: model = UserAddress fields = ('primary', 'address_type', 'addressee', 'street_address', 'city', 'city_native', 'postal_code', 'country', 'region') widgets = { 'primary': bootstrap.CheckboxInput(), 'address_type': bootstrap.Select(), 'addressee': bootstrap.TextInput(attrs={'size': 50}), 'street_address': bootstrap.Textarea(attrs={ 'cols': 50, 'rows': 2 }), 'city': bootstrap.TextInput(attrs={'size': 50}), 'city_native': bootstrap.TextInput(attrs={'size': 50}), 'postal_code': bootstrap.TextInput(attrs={'size': 50}), 'country': bootstrap.Select2(), 'region': bootstrap.TextInput(attrs={'size': 50}), }
class ClientForm(BaseForm): can_access_all_users = forms.BooleanField(label=_('Can access all users'), required=False, widget=bootstrap.CheckboxInput()) type = forms.ChoiceField( label=_('Type'), help_text=mark_safe_lazy( _("Confidential client (can store a secret) or public client for <a href='https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowSteps'>authorisation code flow</a> " "or service account client with <a href='https://datatracker.ietf.org/doc/html/rfc6749#section-4.4'>client credentials grant</a>." )), required=True, choices=ALLOWED_CLIENT_TYPES, widget=bootstrap.Select()) uuid = forms.UUIDField( label=_('Client ID'), required=True, initial=uuid.uuid4, widget=bootstrap.TextInput(attrs={'readonly': True})) scopes = forms.MultipleChoiceField(label=_('Scopes'), required=False, initial=['openid'], choices=ALLOWED_SCOPES, widget=bootstrap.Select2Multiple()) class Meta: model = Client fields = ('application', 'uuid', 'client_secret', 'name', 'type', 'redirect_uris', 'post_logout_redirect_uris', 'notes', 'is_active', 'scopes') widgets = { 'application': bootstrap.HiddenInput(), 'name': bootstrap.TextInput(attrs={'size': 50}), 'client_secret': bootstrap.TextInput(attrs={'readonly': True}), 'notes': bootstrap.Textarea(attrs={'rows': '3'}), 'redirect_uris': bootstrap.Textarea(attrs={'rows': '3'}), 'post_logout_redirect_uris': bootstrap.Textarea(attrs={'rows': '3'}), 'is_active': bootstrap.CheckboxInput(), } def __init__(self, *args, **kwargs): self.user = kwargs.pop('user') # remove custom user keyword # initialize scopes if kwargs.get('instance'): instance = kwargs['instance'] if instance.scopes: kwargs['initial']['scopes'] = instance.scopes.split() kwargs['initial'][ 'can_access_all_users'] = instance.has_access_to_all_users super().__init__(*args, **kwargs) def clean_scopes(self): scopes = self.cleaned_data['scopes'] return ' '.join(scopes) def clean(self): cleaned_data = super().clean() client_type = cleaned_data.get("type") client_secret = cleaned_data.get("client_secret") redirect_uris = cleaned_data.get("redirect_uris") if client_type in ['web', 'service']: if not client_secret: self.add_error( 'client_secret', ValidationError( "A client secret is required for this client type.")) if client_type == "native": cleaned_data['client_secret'] = '' if client_type in ['web', 'native']: if not redirect_uris: self.add_error( 'redirect_uris', ValidationError( "A redirect uri is required for this client type.")) else: cleaned_data['redirect_uris'] = '' cleaned_data['post_logout_redirect_uris'] = '' return self.cleaned_data def save(self, commit=True): instance = super().save(commit) # service clients need a user associated with if self.instance.type == 'service': instance.ensure_service_user_exists() can_access_all_users = self.cleaned_data['can_access_all_users'] if can_access_all_users is not None: instance.set_access_to_all_users(can_access_all_users, self.user) else: self.instance.remove_service_user() return instance
class Meta: model = EmailForward fields = ('forward', 'primary') widgets = {'primary': bootstrap.CheckboxInput()}
class GroupEmailForm(BaseForm): email_value = EmailFieldLower(required=True, label=_("Email address"), widget=bootstrap.EmailInput()) permission = forms.ChoiceField(label=_('Permission'), choices=Email.PERMISSION_CHOICES, widget=bootstrap.Select()) is_active = forms.BooleanField(required=False, label=_("Active"), widget=bootstrap.CheckboxInput()) class Meta: model = GroupEmail fields = ['homepage', 'name', 'is_guide_email'] widgets = { 'homepage': bootstrap.TextInput(attrs={'size': 50}), 'name': bootstrap.TextInput(attrs={'size': 50}), } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) try: email = self.instance.email self.fields['is_active'].initial = email.is_active self.fields['email_value'].initial = force_str(email) self.fields['permission'].initial = email.permission except ObjectDoesNotExist: self.fields['is_active'].initial = True def clean_email_value(self): """ the new email address must .. """ email_value = self.cleaned_data['email_value'] if Email.objects.filter(email=email_value).exclude( groupemail=self.instance).exists(): msg = _('The email address already exists') raise ValidationError(msg) return email_value def save(self, commit=True): cd = self.changed_data if 'email_value' in cd or 'permission' in cd or 'is_active' in cd: created = False try: email = self.instance.email except ObjectDoesNotExist: email = Email(email_type=GROUP_EMAIL_TYPE) created = True email.is_active = self.cleaned_data['is_active'] email.email = self.cleaned_data['email_value'] email.permission = self.cleaned_data['permission'] email.save() if created: self.instance.email = email instance = super().save(commit) return instance