[cwprops] add set_property method on CWUser instances, to ease setting of user specific properties

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changeset73b3e0e095d3
branchstable
phasepublic
hiddenno
parent revision#bcdf22734059 Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
child revision#6c8e8747268d [cwprops, migration] fix [set_]property to ensure we don't retrieve a user specific value. Add some docstring along the way
files modified by this revision
entities/authobjs.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1301053437 -3600
# Fri Mar 25 12:43:57 2011 +0100
# Branch stable
# Node ID 73b3e0e095d3556c29a92a2721bd0f388f02c261
# Parent bcdf227340591fb0cad7b3137efdbd0d89ceca91
[cwprops] add set_property method on CWUser instances, to ease setting of user specific properties

diff --git a/entities/authobjs.py b/entities/authobjs.py
@@ -78,10 +78,22 @@
1          except ValueError:
2              self.warning('incorrect value for eproperty %s of user %s',
3                           key, self.login)
4          return self._cw.vreg.property_value(key)
5 
6 +    def set_property(self, pkey, value):
7 +        value = unicode(value)
8 +        try:
9 +            prop = self._cw.execute(
10 +                'CWProperty X WHERE X pkey %(k)s, X for_user U, U eid %(u)s',
11 +                {'k': pkey, 'u': self.eid}).get_entity(0, 0)
12 +        except:
13 +            self._cw.create_entity('CWProperty', pkey=unicode(pkey),
14 +                                   value=value, for_user=self)
15 +        else:
16 +            prop.set_attributes(value=value)
17 +
18      def matching_groups(self, groups):
19          """return the number of the given group(s) in which the user is
20 
21          :type groups: str or iterable(str)
22          :param groups: a group name or an iterable on group names