author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 20 Nov 2009 19:35:54 +0100 | |
changeset 3890 | d7a270f50f54 |
parent 2968 | 0e3460341023 |
parent 3877 | 7ca53fc72a0a |
child 4011 | 394f853bb653 |
permissions | -rw-r--r-- |
0 | 1 |
"""helper functions for application hooks |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
2840
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2647
diff
changeset
|
10 |
from logilab.common.deprecation import deprecated, class_moved |
0 | 11 |
|
12 |
from cubicweb import RepositoryError |
|
13 |
||
3869
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
14 |
def entity_oldnewvalue(entity, attr): |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
15 |
"""returns the couple (old attr value, new attr value) |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
16 |
NOTE: will only work in a before_update_entity hook |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
17 |
""" |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
18 |
# get new value and remove from local dict to force a db query to |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
19 |
# fetch old value |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
20 |
newvalue = entity.pop(attr, None) |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
21 |
oldvalue = getattr(entity, attr) |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
22 |
if newvalue is not None: |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
23 |
entity[attr] = newvalue |
ec6463886ac4
[server] remove not-so-useful entity_name and entity_attr functions, introduce entity_oldnewvalue
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2876
diff
changeset
|
24 |
return oldvalue, newvalue |
0 | 25 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
26 |
@deprecated('[3.6] entity_name is deprecated, use entity.name') |
2840
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2647
diff
changeset
|
27 |
def entity_name(session, eid): |
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2647
diff
changeset
|
28 |
"""return the "name" attribute of the entity with the given eid""" |
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2647
diff
changeset
|
29 |
return session.entity_from_eid(eid).name |
0 | 30 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
31 |
@deprecated('[3.6] rproperty is deprecated, use session.schema_rproperty') |
2840
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2647
diff
changeset
|
32 |
def rproperty(session, rtype, eidfrom, eidto, rprop): |
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2647
diff
changeset
|
33 |
return session.rproperty(rtype, eidfrom, eidto, rprop) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
34 |
|
2840
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2647
diff
changeset
|
35 |
from cubicweb.server.hook import SendMailOp |
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2647
diff
changeset
|
36 |
SendMailOp = class_moved(SendMailOp) |