Enhanced call validation for log and registration
This commit is contained in:
parent
c4b3b68c9c
commit
d9e12e362d
|
@ -6,7 +6,7 @@ from crispy_forms.layout import Submit
|
|||
from django.urls import reverse
|
||||
|
||||
from .models import User, Reference, QSO
|
||||
from .validators import CallUsernameValidator
|
||||
from .validators import CallUsernameValidator, CallLogValidator
|
||||
|
||||
class CustomUserCreationForm(UserCreationForm):
|
||||
class Meta:
|
||||
|
@ -62,7 +62,7 @@ class QSOForm(forms.ModelForm):
|
|||
raise forms.ValidationError("Reference already exists")
|
||||
|
||||
try:
|
||||
CallUsernameValidator()(data)
|
||||
CallLogValidator()(data)
|
||||
except forms.ValidationError:
|
||||
raise forms.ValidationError("Enter a valid callsign (1-2 chars, a number, 1-4 chars, maybe a /[A-Z])")
|
||||
|
||||
|
|
|
@ -9,10 +9,20 @@ import re
|
|||
@deconstructible
|
||||
class CallUsernameValidator(validators.RegexValidator):
|
||||
#regex = r'^[\w.@+-]+$'
|
||||
regex = r'^(?:[A-Z]+/)?[A-Z]{1,2}[0-9][A-Z]{1,4}(?:-[0-9])?(?:/p)?$'
|
||||
regex = r'^(?:[A-Z]+/)?[A-Z]{1,2}[0-9][A-Z]{1,4}(?:-[0-9])??$'
|
||||
message = _(
|
||||
'Enter a valid Callsign as Username, ALL UPPERCASE, if needed with /A /B,'
|
||||
'e.g. DL7BST, DN1BER/A, DL/OE1FOO'
|
||||
'Enter a valid Callsign as Username, ALL UPPERCASE, if needed with -1 / -2,'
|
||||
'e.g. DL7BST, DN1BER-1, DL/OE1FOO.'
|
||||
)
|
||||
flags = re.ASCII if six.PY3 else 0
|
||||
|
||||
@deconstructible
|
||||
class CallLogValidator(validators.RegexValidator):
|
||||
#regex = r'^[\w.@+-]+$'
|
||||
regex = r'^(?:[A-Z]+/)?[A-Z]{1,2}[0-9][A-Z]{1,4}(?:-[0-9])?(?:/[A-Z]{1,3})?$'
|
||||
message = _(
|
||||
'Enter a valid callsign, ALL UPPERCASE, if needed with -1 / -2,'
|
||||
'e.g. DL7BST, DN1BER-1, DL/OE1FOO, DN1FTW-1/p'
|
||||
)
|
||||
flags = re.ASCII if six.PY3 else 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue