Prevent creating custom kaehmy role with existing name

This commit is contained in:
henu
2017-10-14 21:33:51 +03:00
parent 54c9ef8dce
commit b2bc3ad43e
2 changed files with 11 additions and 2 deletions
+9 -1
View File
@@ -38,7 +38,15 @@ class KaehmyForm_Form(forms.ModelForm):
if number.isdigit():
return number
else:
raise ValidationError(_('Invalid value'))
raise ValidationError(_('Invalid phone number'))
def clean_custom_role_name(self):
"""Check that no other custom role with same name exists."""
custom_name = self.cleaned_data.get('custom_role_name')
if CustomKaehmyRole.objects.get(name=custom_name) is None:
return custom_name
else:
raise ValidationError(_('Custom role with the same name already exists.'))
class KaehmyCommentForm(forms.ModelForm):
+2 -1
View File
@@ -235,7 +235,8 @@ def kaehmy_comment(request, *args, **kwargs):
'Käy lukemassa viesti osoitteessa http://sika.sahkoinsinoorikilta.fi/kaehmy').format(name.capitalize())
send_email(email, subject, body)
logging.debug('Sent kaehmy comment email to recipient <{}>'.format(email))
logging.debug(
'Sent kaehmy comment email to recipient <{}>'.format(email))
return redirect('/kaehmy')
else: