Commit ce78087e authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch '157-constraints-nickname' into 'master'

Check if nickname is set before saving preference

See #157

See merge request !183
parents 5420e848 c7f5ba58
...@@ -4,6 +4,7 @@ from functools import reduce ...@@ -4,6 +4,7 @@ from functools import reduce
from django.conf import settings from django.conf import settings
from django.core import validators from django.core import validators
from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.db.models import Q from django.db.models import Q
from django.urls import reverse from django.urls import reverse
...@@ -345,6 +346,17 @@ class Member(models.Model): ...@@ -345,6 +346,17 @@ class Member(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('members:profile', args=[str(self.pk)]) return reverse('members:profile', args=[str(self.pk)])
def clean(self):
super().clean()
errors = {}
if self.display_name_preference in ('nickname', 'fullnick',
'nicklast'):
if not self.nickname:
errors.update(
{'nickname': _('You need to enter a nickname to use it as '
'display name')})
raise ValidationError(errors)
def __str__(self): def __str__(self):
return '{} ({})'.format(self.get_full_name(), self.user.username) return '{} ({})'.format(self.get_full_name(), self.user.username)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment