[cwprops] add set_property method on CWUser instances, to ease setting of user specific properties stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 25 Mar 2011 12:43:57 +0100
branchstable
changeset 7110 73b3e0e095d3
parent 7108 bcdf22734059
child 7111 6c8e8747268d
[cwprops] add set_property method on CWUser instances, to ease setting of user specific properties
entities/authobjs.py
--- a/entities/authobjs.py	Tue Mar 22 15:11:38 2011 +0100
+++ b/entities/authobjs.py	Fri Mar 25 12:43:57 2011 +0100
@@ -80,6 +80,18 @@
                          key, self.login)
         return self._cw.vreg.property_value(key)
 
+    def set_property(self, pkey, value):
+        value = unicode(value)
+        try:
+            prop = self._cw.execute(
+                'CWProperty X WHERE X pkey %(k)s, X for_user U, U eid %(u)s',
+                {'k': pkey, 'u': self.eid}).get_entity(0, 0)
+        except:
+            self._cw.create_entity('CWProperty', pkey=unicode(pkey),
+                                   value=value, for_user=self)
+        else:
+            prop.set_attributes(value=value)
+
     def matching_groups(self, groups):
         """return the number of the given group(s) in which the user is