server/hookhelper.py
changeset 3890 d7a270f50f54
parent 2968 0e3460341023
parent 3877 7ca53fc72a0a
child 4011 394f853bb653
equal deleted inserted replaced
3810:5b75fd66c80e 3890:d7a270f50f54
     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 
    13 
       
    14 def entity_oldnewvalue(entity, attr):
       
    15     """returns the couple (old attr value, new attr value)
       
    16     NOTE: will only work in a before_update_entity hook
       
    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
    14 
    25 
    15 @deprecated('[3.6] entity_name is deprecated, use entity.name')
    26 @deprecated('[3.6] entity_name is deprecated, use entity.name')
    16 def entity_name(session, eid):
    27 def entity_name(session, eid):
    17     """return the "name" attribute of the entity with the given eid"""
    28     """return the "name" attribute of the entity with the given eid"""
    18     return session.entity_from_eid(eid).name
    29     return session.entity_from_eid(eid).name