summaryrefslogtreecommitdiffstats
path: root/accounts/models.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-01-30 04:18:31 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2016-02-02 04:23:19 +0100
commitc6caa836b4fc897b6327fb573cbbcd67764d1cbd (patch)
tree02c161382d31f1bf5f2cea81d0e4399dbc04dccc /accounts/models.py
parentb83ad9d369c21662b0e26dad1e704d3b768b631a (diff)
downloadweb-c6caa836b4fc897b6327fb573cbbcd67764d1cbd.tar.gz
web-c6caa836b4fc897b6327fb573cbbcd67764d1cbd.tar.bz2
web-c6caa836b4fc897b6327fb573cbbcd67764d1cbd.zip
Account: Support direct setting of attributes
Direct access to additional attributes was possible before, but setting the same value, created a new local property: >>> acc = Account(...) >>> acc.mail == acc.attributes['mail'] True >>> acc.mail = "foobar" >>> acc.mail == acc.attributes['mail'] False Not also assignments are possible and all assignments to unknown properties will create new attributes.
Diffstat (limited to 'accounts/models.py')
-rw-r--r--accounts/models.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/accounts/models.py b/accounts/models.py
index 421b392..0c7ffdb 100644
--- a/accounts/models.py
+++ b/accounts/models.py
@@ -10,6 +10,7 @@ class Account(UserMixin):
An Account represents a complex ldap tree entry for spline users.
For each service a spline user can have a different password.
"""
+ _ready = False
def __init__(self, uid, mail, services=[], dn=None, password=None):
self.uid = uid.encode('utf8') if isinstance(uid, unicode) else uid
@@ -21,6 +22,7 @@ class Account(UserMixin):
self.attributes = {}
self._set_attribute('mail', mail)
+ self._ready = True
def __repr__(self):
return "<Account uid=%s>" % self.uid
@@ -66,6 +68,12 @@ class Account(UserMixin):
raise AttributeError("'%s' object has no attribute '%s'" %
(self.__class__.__name__, name))
+ def __setattr__(self, name, value):
+ if self._ready and name not in self.__dict__:
+ self._set_attribute(name, value)
+ else:
+ super(Account, self).__setattr__(name, value)
+
def get_id(self):
"""
This is for flask-login. The returned string is saved inside