Ticket #161: rwall_livequery.patch
| File rwall_livequery.patch, 3.0 kB (added by rwall, 3 years ago) |
|---|
-
/home/richard/lib/Divmod/trunk/Axiom/axiom/test/test_livequery.py
old new 1 from louie import dispatcher 2 3 from twisted.trial.unittest import TestCase 4 5 from axiom.item import Item 6 from axiom.store import Store 7 from axiom.attributes import text 8 9 class MyItem(Item): 10 name = text(allowNone = True) 11 12 class TabularDataModel: 13 results = [] 14 def __init__(self, store, queryItem): 15 self.store = store 16 self.queryItem = queryItem 17 18 def updateResults(self): 19 self.results = list(self.store.query(self.queryItem)) 20 21 def onStoreItemAdd(self): 22 self.updateResults() 23 24 class LiveQuery(TestCase): 25 def testLiveQueryItemAddObserver(self): 26 27 s = Store() 28 tdm = TabularDataModel(s, MyItem) 29 dispatcher.connect(tdm.onStoreItemAdd, "itemadd", MyItem) 30 def transaction(): 31 MyItem(store=s, name=u"a") 32 33 count1 = len(tdm.results) 34 s.transact(transaction) 35 count2 = len(tdm.results) 36 37 self.assertEquals(count1, 0) 38 self.assertEquals(count2, 1) 39 s.close() 40 -
/home/richard/lib/Divmod/trunk/Axiom/axiom/item.py
old new 1 1 # -*- test-case-name: axiom.test -*- 2 2 __metaclass__ = type 3 from louie import dispatcher 3 4 4 5 from twisted.python.reflect import qual 5 6 from twisted.application.service import IService, IServiceCollection, MultiService … … 438 439 # TODO: need to measure the performance impact of this, then do 439 440 # it to make sure things are in fact deleted: 440 441 # self.store.executeSQL(_schema.APP_VACUUM) 442 dispatcher.send("itemdelete", self.__class__) 441 443 else: 442 444 assert self.__legacy__ 443 445 … … 449 451 # transaction; just don't do anything. 450 452 return 451 453 self.store.executeSQL(*self._updateSQL()) 454 dispatcher.send("itemupdate", self.__class__) 452 455 else: 453 456 # case 2: we are in the middle of creating the object, we've never 454 457 # been inserted into the db before … … 459 462 [self.storeID] + 460 463 [self.__dirty__.get(a[1].attrname, (None, a[1].default,))[1] for a in attrs]) 461 464 self.__everInserted = True 465 dispatcher.send("itemadd", self.__class__) 462 466 # In case 1, we're dirty but we did an update, synchronizing the 463 467 # database, in case 2, we haven't been created but we issue an insert. 464 468 # In either case, the code in attributes.py sets the attribute *as well
