core: prevent duplicate fixed_username/email
This commit is contained in:
parent
4111ca96a7
commit
564483cab8
|
@ -1,13 +1,29 @@
|
||||||
"""passbook core invitation form"""
|
"""passbook core invitation form"""
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from passbook.core.models import Invitation
|
from passbook.core.models import Invitation, User
|
||||||
|
|
||||||
|
|
||||||
class InvitationForm(forms.ModelForm):
|
class InvitationForm(forms.ModelForm):
|
||||||
"""InvitationForm"""
|
"""InvitationForm"""
|
||||||
|
|
||||||
|
def clean_fixed_username(self):
|
||||||
|
"""Check if username is already used"""
|
||||||
|
username = self.cleaned_data.get('fixed_username')
|
||||||
|
if User.objects.filter(username=username).exists():
|
||||||
|
raise ValidationError(_('Username is already in use.'))
|
||||||
|
return username
|
||||||
|
|
||||||
|
def clean_fixed_email(self):
|
||||||
|
"""Check if email is already used"""
|
||||||
|
email = self.cleaned_data.get('fixed_email')
|
||||||
|
if User.objects.filter(email=email).exists():
|
||||||
|
raise ValidationError(_('E-Mail is already in use.'))
|
||||||
|
return email
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
model = Invitation
|
model = Invitation
|
||||||
|
|
Reference in New Issue