Check if nickname is set before saving preference

See #157
parent 07d802fd
......@@ -4,6 +4,7 @@ from functools import reduce
from django.conf import settings
from django.core import validators
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Q
from django.urls import reverse
......@@ -345,6 +346,17 @@ class Member(models.Model):
def get_absolute_url(self):
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):
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