Fixes on systemuser backend

This commit is contained in:
Marc Aymerich 2015-06-15 11:21:33 +00:00
parent 482de3157e
commit 2160f79ce4
3 changed files with 9 additions and 7 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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):