From fd6c7975a02b46d2a8417c6b73b3ce7b6f1ef407 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 14 Nov 2014 22:23:20 +0000 Subject: [PATCH] Fixed errors with systemuser form and serializer --- orchestra/apps/systemusers/models.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/orchestra/apps/systemusers/models.py b/orchestra/apps/systemusers/models.py index 1ce4d7bb..b0f922ae 100644 --- a/orchestra/apps/systemusers/models.py +++ b/orchestra/apps/systemusers/models.py @@ -75,20 +75,18 @@ class SystemUser(models.Model): super(SystemUser, self).save(*args, **kwargs) def clean(self): - # TODO do it right - if self.has_shell and self.directory: - raise ValidationError({ - 'directory': _("Directory with shell users can not be specified.") - }) - if self.pk and self.is_main and self.directory: - raise ValidationError({ - 'directory': _("Directory with main system users can not be specified.") - }) - if self.home == self.get_base_home() and self.directory: - raise ValidationError({ - 'directory': _("Directory on the user's base home is not allowed.") - }) - # TODO valid home exists + if self.directory: + directory_error = None + if self.has_shell: + directory_error = _("Directory with shell users can not be specified.") + elif self.pk and self.is_main: + directory_error = _("Directory with main system users can not be specified.") + elif self.home == self.get_base_home(): + directory_error = _("Directory on the user's base home is not allowed.") + if directory_error: + raise ValidationError({ + 'directory': directory_error, + }) def set_password(self, raw_password): self.password = make_password(raw_password)