[undo, transactions] Adds a property in the transaction API. (closes #2202953)
authorAnthony Truchet <anthony.truchet@logilab.fr>
Mon, 27 Feb 2012 09:45:48 +0100
changeset 8266 704dda5c07f7
parent 8265 9747ab9230ad
child 8267 486386d9f836
[undo, transactions] Adds a property in the transaction API. (closes #2202953) Required by forthcoming changes in undo_web.diff
server/test/unittest_undo.py
transaction.py
--- a/server/test/unittest_undo.py	Mon Feb 27 09:43:15 2012 +0100
+++ b/server/test/unittest_undo.py	Mon Feb 27 09:45:48 2012 +0100
@@ -80,12 +80,14 @@
         self.assertEqual(a1.action, 'C')
         self.assertEqual(a1.eid, self.toto.eid)
         self.assertEqual(a1.etype,'CWUser')
+        self.assertEqual(a1.ertype, 'CWUser')
         self.assertEqual(a1.changes, None)
         self.assertEqual(a1.public, True)
         self.assertEqual(a1.order, 1)
         a4 = actions[3]
         self.assertEqual(a4.action, 'A')
         self.assertEqual(a4.rtype, 'in_group')
+        self.assertEqual(a4.ertype, 'in_group')
         self.assertEqual(a4.eid_from, self.toto.eid)
         self.assertEqual(a4.eid_to, self.toto.in_group[0].eid)
         self.assertEqual(a4.order, 4)
--- a/transaction.py	Mon Feb 27 09:43:15 2012 +0100
+++ b/transaction.py	Mon Feb 27 09:45:48 2012 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -21,7 +21,6 @@
 This module is in the cubicweb package and not in cubicweb.server because those
 objects should be accessible to client through pyro, where the cubicweb.server
 package may not be installed.
-
 """
 __docformat__ = "restructuredtext en"
 _ = unicode
@@ -86,6 +85,11 @@
     def label(self):
         return ACTION_LABELS[self.action]
 
+    @property
+    def ertype(self):
+        """ Return the entity or relation type this action is related to"""
+        raise NotImplementedError(self)
+
 
 class EntityAction(AbstractAction):
     def __init__(self, action, public, order, etype, eid, changes):
@@ -99,6 +103,11 @@
             self.label, self.eid, self.changes,
             self.public and 'dbapi' or 'hook')
 
+    @property
+    def ertype(self):
+        """ Return the entity or relation type this action is related to"""
+        return self.etype
+
 
 class RelationAction(AbstractAction):
     def __init__(self, action, public, order, rtype, eidfrom, eidto):
@@ -111,3 +120,8 @@
         return '<%s: %s %s %s (%s)>' % (
             self.label, self.eid_from, self.rtype, self.eid_to,
             self.public and 'dbapi' or 'hook')
+
+    @property
+    def ertype(self):
+        """ Return the entity or relation type this action is related to"""
+        return self.rtype