diff --git a/orchestra/contrib/accounts/models.py b/orchestra/contrib/accounts/models.py index f19a2cf9..bf6a8a32 100644 --- a/orchestra/contrib/accounts/models.py +++ b/orchestra/contrib/accounts/models.py @@ -55,10 +55,6 @@ class Account(auth.AbstractBaseUser): def is_staff(self): return self.is_superuser -# @property -# def main_systemuser(self): -# return self.systemusers.get(is_main=True) - @classmethod def get_main(cls): return cls.objects.get(pk=settings.ACCOUNTS_MAIN_PK) @@ -70,8 +66,8 @@ class Account(auth.AbstractBaseUser): super(Account, self).save(*args, **kwargs) if created: self.main_systemuser = self.systemusers.create(account=self, username=self.username, - password=self.password, is_active=active_systemuser) - self.save(update_fields=['main_systemuser']) + password=self.password, is_active=active_systemuser) + self.save(update_fields=('main_systemuser',)) elif was_active != self.is_active: self.notify_related() diff --git a/orchestra/contrib/orchestration/__init__.py b/orchestra/contrib/orchestration/__init__.py index 57b18b26..3e717bdd 100644 --- a/orchestra/contrib/orchestration/__init__.py +++ b/orchestra/contrib/orchestration/__init__.py @@ -17,6 +17,9 @@ class Operation(): def __str__(self): return '%s.%s(%s)' % (self.backend, self.action, self.instance) + def __repr__(self): + return str(self) + def __hash__(self): """ set() """ return hash(self.backend) + hash(self.instance) + hash(self.action) diff --git a/orchestra/contrib/systemusers/models.py b/orchestra/contrib/systemusers/models.py index fb274a78..1b7c640f 100644 --- a/orchestra/contrib/systemusers/models.py +++ b/orchestra/contrib/systemusers/models.py @@ -74,7 +74,10 @@ class SystemUser(models.Model): @cached_property def main(self): - return self.account.main_systemuser + # On account creation main_systemuser_id is still None + if self.account.main_systemuser_id: + return self.account.main_systemuser + return type(self).objects.get(username=self.account.username) @property def has_shell(self):