2
0
Fork 0

add support for ocuntry code allowlist, add dach to it

This commit is contained in:
Andreas (@xAndy) Zimmermann 2022-04-27 17:18:58 +02:00
parent e13d05a3df
commit 11854ab1ce
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,17 @@
from dynamic_preferences.registries import global_preferences_registry
from dynamic_preferences.types import MultipleChoicePreference
from dynamic_preferences.types import Section
import phonenumbers
registration = Section("registation")
@global_preferences_registry.register
class AllowedPhoneCountries(MultipleChoicePreference):
section = registration
name = "allowed_countries"
choices = [
(f"{phonenumbers.country_code_for_region(cc)}", cc)
for cc in phonenumbers.SUPPORTED_REGIONS
]
default = [49, 41, 43]

View File

@ -1,6 +1,11 @@
from django import forms from django import forms
from .models import Helper from .models import Helper
from phonenumber_field.formfields import PhoneNumberField from phonenumber_field.formfields import PhoneNumberField
from phonenumber_field.validators import validate_international_phonenumber
from django.core.exceptions import ValidationError
from dynamic_preferences.registries import global_preferences_registry
global_preferences = global_preferences_registry.manager()
def text_input(type=None): def text_input(type=None):
@ -11,6 +16,17 @@ def text_input(type=None):
return forms.TextInput(attrs=attrs) return forms.TextInput(attrs=attrs)
def validate_allowed_countries(value):
if (
not f"{value.country_code}"
in global_preferences["registation__allowed_countries"]
):
raise ValidationError(
"Vorwahl nicht Erlaubt, bitte wende dich an den Infodesk oder schicke uns eine Mail"
)
return value
class RegisterForm(forms.Form): class RegisterForm(forms.Form):
name = forms.CharField( name = forms.CharField(
max_length=Helper.name.field.max_length, label="Name", widget=text_input() max_length=Helper.name.field.max_length, label="Name", widget=text_input()
@ -21,6 +37,10 @@ class RegisterForm(forms.Form):
label="Handynummer für Benachrichtigungen", label="Handynummer für Benachrichtigungen",
help_text="Wir nutzen deine Handynummer, um dir Benachrichtigungen zu deinen Schichten zu schicken. Wir löschen alle Daten 7 Tage nach dem Festival.", help_text="Wir nutzen deine Handynummer, um dir Benachrichtigungen zu deinen Schichten zu schicken. Wir löschen alle Daten 7 Tage nach dem Festival.",
widget=text_input("tel"), widget=text_input("tel"),
validators=[
validate_international_phonenumber,
validate_allowed_countries,
],
) )
okf = forms.BooleanField(label="Ich bin damit einverstanden, SMS zu erhalten.") okf = forms.BooleanField(label="Ich bin damit einverstanden, SMS zu erhalten.")