transaction.py
changeset 9052 4cba5f2cd57b
parent 8266 704dda5c07f7
child 10235 684215aca046
equal deleted inserted replaced
9051:944d66870c6a 9052:4cba5f2cd57b
    51     def __init__(self, uuid, time, ueid):
    51     def __init__(self, uuid, time, ueid):
    52         self.uuid = uuid
    52         self.uuid = uuid
    53         self.datetime = time
    53         self.datetime = time
    54         self.user_eid = ueid
    54         self.user_eid = ueid
    55         # should be set by the dbapi connection
    55         # should be set by the dbapi connection
    56         self.req = None
    56         self.req = None  # old style
       
    57         self.cnx = None  # new style
       
    58 
       
    59     def _execute(self, *args, **kwargs):
       
    60         """execute a query using either the req or the cnx"""
       
    61         if self.req is None:
       
    62             execute = self.cnx.execute
       
    63         else:
       
    64             execute = self.req
       
    65         return execute(*args, **kwargs)
       
    66 
    57 
    67 
    58     def __repr__(self):
    68     def __repr__(self):
    59         return '<Transaction %s by %s on %s>' % (
    69         return '<Transaction %s by %s on %s>' % (
    60             self.uuid, self.user_eid, self.datetime)
    70             self.uuid, self.user_eid, self.datetime)
    61 
    71 
    62     def user(self):
    72     def user(self):
    63         """return the user entity which has done the transaction,
    73         """return the user entity which has done the transaction,
    64         none if not found.
    74         none if not found.
    65         """
    75         """
    66         return self.req.execute('Any X WHERE X eid %(x)s',
    76         return self._execute('Any X WHERE X eid %(x)s',
    67                                 {'x': self.user_eid}).get_entity(0, 0)
    77                              {'x': self.user_eid}).get_entity(0, 0)
    68 
    78 
    69     def actions_list(self, public=True):
    79     def actions_list(self, public=True):
    70         """return an ordered list of action effectued during that transaction
    80         """return an ordered list of action effectued during that transaction
    71 
    81 
    72         if public is true, return only 'public' action, eg not ones triggered
    82         if public is true, return only 'public' action, eg not ones triggered
    73         under the cover by hooks.
    83         under the cover by hooks.
    74         """
    84         """
    75         return self.req.cnx.transaction_actions(self.uuid, public)
    85         if self.req is not None:
       
    86             cnx = self.req.cnx
       
    87         else:
       
    88             cnx = self.cnx
       
    89         return cnx.transaction_actions(self.uuid, public)
    76 
    90 
    77 
    91 
    78 class AbstractAction(object):
    92 class AbstractAction(object):
    79     def __init__(self, action, public, order):
    93     def __init__(self, action, public, order):
    80         self.action = action
    94         self.action = action