295 else: |
295 else: |
296 value = super(Entity, self).pop(attr, default) |
296 value = super(Entity, self).pop(attr, default) |
297 if hasattr(self, 'edited_attributes') and attr in self.edited_attributes: |
297 if hasattr(self, 'edited_attributes') and attr in self.edited_attributes: |
298 self.edited_attributes.remove(attr) |
298 self.edited_attributes.remove(attr) |
299 return value |
299 return value |
|
300 |
|
301 def update(self, values): |
|
302 """override update to update self.edited_attributes. See `__setitem__` |
|
303 """ |
|
304 for attr, value in values.items(): |
|
305 self[attr] = value # use self.__setitem__ implementation |
300 |
306 |
301 def rql_set_value(self, attr, value): |
307 def rql_set_value(self, attr, value): |
302 """call by rql execution plan when some attribute is modified |
308 """call by rql execution plan when some attribute is modified |
303 |
309 |
304 don't use dict api in such case since we don't want attribute to be |
310 don't use dict api in such case since we don't want attribute to be |
872 pass |
878 pass |
873 |
879 |
874 # raw edition utilities ################################################### |
880 # raw edition utilities ################################################### |
875 |
881 |
876 def set_attributes(self, **kwargs): |
882 def set_attributes(self, **kwargs): |
|
883 _check_cw_unsafe(kwargs) |
877 assert kwargs |
884 assert kwargs |
878 _check_cw_unsafe(kwargs) |
885 assert self._is_saved |
879 relations = [] |
886 relations = [] |
880 for key in kwargs: |
887 for key in kwargs: |
881 relations.append('X %s %%(%s)s' % (key, key)) |
888 relations.append('X %s %%(%s)s' % (key, key)) |
882 # update current local object |
|
883 self.update(kwargs) |
|
884 # and now update the database |
889 # and now update the database |
885 kwargs['x'] = self.eid |
890 kwargs['x'] = self.eid |
886 self._cw.execute('SET %s WHERE X eid %%(x)s' % ','.join(relations), |
891 self._cw.execute('SET %s WHERE X eid %%(x)s' % ','.join(relations), |
887 kwargs, 'x') |
892 kwargs, 'x') |
|
893 kwargs.pop('x') |
|
894 # update current local object _after_ the rql query to avoid |
|
895 # interferences between the query execution itself and the |
|
896 # edited_attributes / skip_security_attributes machinery |
|
897 self.update(kwargs) |
888 |
898 |
889 def set_relations(self, **kwargs): |
899 def set_relations(self, **kwargs): |
890 """add relations to the given object. To set a relation where this entity |
900 """add relations to the given object. To set a relation where this entity |
891 is the object of the relation, use 'reverse_'<relation> as argument name. |
901 is the object of the relation, use 'reverse_'<relation> as argument name. |
892 |
902 |