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): def is_staff(self):
return self.is_superuser return self.is_superuser
# @property
# def main_systemuser(self):
# return self.systemusers.get(is_main=True)
@classmethod @classmethod
def get_main(cls): def get_main(cls):
return cls.objects.get(pk=settings.ACCOUNTS_MAIN_PK) return cls.objects.get(pk=settings.ACCOUNTS_MAIN_PK)
@ -71,7 +67,7 @@ class Account(auth.AbstractBaseUser):
if created: if created:
self.main_systemuser = self.systemusers.create(account=self, username=self.username, self.main_systemuser = self.systemusers.create(account=self, username=self.username,
password=self.password, is_active=active_systemuser) password=self.password, is_active=active_systemuser)
self.save(update_fields=['main_systemuser']) self.save(update_fields=('main_systemuser',))
elif was_active != self.is_active: elif was_active != self.is_active:
self.notify_related() self.notify_related()

View File

@ -17,6 +17,9 @@ class Operation():
def __str__(self): def __str__(self):
return '%s.%s(%s)' % (self.backend, self.action, self.instance) return '%s.%s(%s)' % (self.backend, self.action, self.instance)
def __repr__(self):
return str(self)
def __hash__(self): def __hash__(self):
""" set() """ """ set() """
return hash(self.backend) + hash(self.instance) + hash(self.action) return hash(self.backend) + hash(self.instance) + hash(self.action)

View File

@ -74,7 +74,10 @@ class SystemUser(models.Model):
@cached_property @cached_property
def main(self): def main(self):
# On account creation main_systemuser_id is still None
if self.account.main_systemuser_id:
return self.account.main_systemuser return self.account.main_systemuser
return type(self).objects.get(username=self.account.username)
@property @property
def has_shell(self): def has_shell(self):