equal
deleted
inserted
replaced
1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
19 |
19 |
20 |
20 |
21 This module is in the cubicweb package and not in cubicweb.server because those |
21 This module is in the cubicweb package and not in cubicweb.server because those |
22 objects should be accessible to client through pyro, where the cubicweb.server |
22 objects should be accessible to client through pyro, where the cubicweb.server |
23 package may not be installed. |
23 package may not be installed. |
24 |
|
25 """ |
24 """ |
26 __docformat__ = "restructuredtext en" |
25 __docformat__ = "restructuredtext en" |
27 _ = unicode |
26 _ = unicode |
28 |
27 |
29 from cubicweb import RepositoryError |
28 from cubicweb import RepositoryError |
37 'R': _('relation removal'), |
36 'R': _('relation removal'), |
38 } |
37 } |
39 |
38 |
40 |
39 |
41 class NoSuchTransaction(RepositoryError): |
40 class NoSuchTransaction(RepositoryError): |
42 pass |
41 # Used by CubicWebException |
|
42 msg = _("there is no transaction #%s") |
43 |
43 |
|
44 def __init__(self, txuuid): |
|
45 super(RepositoryError, self).__init__(txuuid) |
|
46 self.txuuid = txuuid |
44 |
47 |
45 class Transaction(object): |
48 class Transaction(object): |
46 """an undoable transaction""" |
49 """an undoable transaction""" |
47 |
50 |
48 def __init__(self, uuid, time, ueid): |
51 def __init__(self, uuid, time, ueid): |
80 |
83 |
81 @property |
84 @property |
82 def label(self): |
85 def label(self): |
83 return ACTION_LABELS[self.action] |
86 return ACTION_LABELS[self.action] |
84 |
87 |
|
88 @property |
|
89 def ertype(self): |
|
90 """ Return the entity or relation type this action is related to""" |
|
91 raise NotImplementedError(self) |
|
92 |
85 |
93 |
86 class EntityAction(AbstractAction): |
94 class EntityAction(AbstractAction): |
87 def __init__(self, action, public, order, etype, eid, changes): |
95 def __init__(self, action, public, order, etype, eid, changes): |
88 AbstractAction.__init__(self, action, public, order) |
96 AbstractAction.__init__(self, action, public, order) |
89 self.etype = etype |
97 self.etype = etype |
93 def __repr__(self): |
101 def __repr__(self): |
94 return '<%s: %s %s (%s)>' % ( |
102 return '<%s: %s %s (%s)>' % ( |
95 self.label, self.eid, self.changes, |
103 self.label, self.eid, self.changes, |
96 self.public and 'dbapi' or 'hook') |
104 self.public and 'dbapi' or 'hook') |
97 |
105 |
|
106 @property |
|
107 def ertype(self): |
|
108 """ Return the entity or relation type this action is related to""" |
|
109 return self.etype |
|
110 |
98 |
111 |
99 class RelationAction(AbstractAction): |
112 class RelationAction(AbstractAction): |
100 def __init__(self, action, public, order, rtype, eidfrom, eidto): |
113 def __init__(self, action, public, order, rtype, eidfrom, eidto): |
101 AbstractAction.__init__(self, action, public, order) |
114 AbstractAction.__init__(self, action, public, order) |
102 self.rtype = rtype |
115 self.rtype = rtype |
105 |
118 |
106 def __repr__(self): |
119 def __repr__(self): |
107 return '<%s: %s %s %s (%s)>' % ( |
120 return '<%s: %s %s %s (%s)>' % ( |
108 self.label, self.eid_from, self.rtype, self.eid_to, |
121 self.label, self.eid_from, self.rtype, self.eid_to, |
109 self.public and 'dbapi' or 'hook') |
122 self.public and 'dbapi' or 'hook') |
|
123 |
|
124 @property |
|
125 def ertype(self): |
|
126 """ Return the entity or relation type this action is related to""" |
|
127 return self.rtype |