8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 |
9 |
10 from logilab.common.deprecation import deprecated, class_moved |
10 from logilab.common.deprecation import deprecated, class_moved |
11 |
11 |
12 from cubicweb import RepositoryError |
12 from cubicweb import RepositoryError |
|
13 from cubicweb.server import hook |
13 |
14 |
|
15 @deprecated('[3.6] entity_oldnewvalue should be imported from cw.server.hook') |
14 def entity_oldnewvalue(entity, attr): |
16 def entity_oldnewvalue(entity, attr): |
15 """returns the couple (old attr value, new attr value) |
17 """return the "name" attribute of the entity with the given eid""" |
16 NOTE: will only work in a before_update_entity hook |
18 return hook.entity_oldnewvalue(entity, attr) |
17 """ |
|
18 # get new value and remove from local dict to force a db query to |
|
19 # fetch old value |
|
20 newvalue = entity.pop(attr, None) |
|
21 oldvalue = getattr(entity, attr) |
|
22 if newvalue is not None: |
|
23 entity[attr] = newvalue |
|
24 return oldvalue, newvalue |
|
25 |
19 |
26 @deprecated('[3.6] entity_name is deprecated, use entity.name') |
20 @deprecated('[3.6] entity_name is deprecated, use entity.name') |
27 def entity_name(session, eid): |
21 def entity_name(session, eid): |
28 """return the "name" attribute of the entity with the given eid""" |
22 """return the "name" attribute of the entity with the given eid""" |
29 return session.entity_from_eid(eid).name |
23 return session.entity_from_eid(eid).name |
30 |
24 |
31 @deprecated('[3.6] rproperty is deprecated, use session.schema_rproperty') |
25 @deprecated('[3.6] rproperty is deprecated, use session.schema_rproperty') |
32 def rproperty(session, rtype, eidfrom, eidto, rprop): |
26 def rproperty(session, rtype, eidfrom, eidto, rprop): |
33 return session.rproperty(rtype, eidfrom, eidto, rprop) |
27 return session.rproperty(rtype, eidfrom, eidto, rprop) |
34 |
28 |
35 from cubicweb.server.hook import SendMailOp |
29 SendMailOp = class_moved(hook.SendMailOp) |
36 SendMailOp = class_moved(SendMailOp) |
|