|
|
@@ -9,9 +9,8 @@ from accounts.models import InvitationCode
|
|
|
class ReyMotaUserCreationForm(UserCreationForm):
|
|
|
invitation_code = forms.CharField(
|
|
|
max_length=32,
|
|
|
- required=False,
|
|
|
label="Código de Invitación",
|
|
|
- help_text="Introduce el código que has recibido (opcional)"
|
|
|
+ help_text="Introduce el código que has recibido"
|
|
|
)
|
|
|
|
|
|
class Meta:
|
|
|
@@ -28,7 +27,7 @@ class ReyMotaUserCreationForm(UserCreationForm):
|
|
|
def clean_invitation_code(self):
|
|
|
code = self.cleaned_data.get('invitation_code')
|
|
|
if not code:
|
|
|
- return code
|
|
|
+ raise ValidationError("El código de invitación es obligatorio.")
|
|
|
|
|
|
try:
|
|
|
invitation = InvitationCode.objects.get(code=code)
|
|
|
@@ -47,9 +46,8 @@ class ReyMotaUserCreationForm(UserCreationForm):
|
|
|
if commit:
|
|
|
user.save()
|
|
|
code = self.cleaned_data.get('invitation_code')
|
|
|
- if code:
|
|
|
- invitation = InvitationCode.objects.get(code=code)
|
|
|
- invitation.mark_as_used(user)
|
|
|
+ invitation = InvitationCode.objects.get(code=code)
|
|
|
+ invitation.mark_as_used(user)
|
|
|
return user
|
|
|
|
|
|
|