provide __getitem__() method for tracking storage, tolerating track ids in string format
This commit is contained in:
		
							parent
							
								
									dcbf231038
								
							
						
					
					
						commit
						960092b4a8
					
				
					 2 changed files with 9 additions and 2 deletions
				
			
		|  | @ -81,9 +81,15 @@ class Container(object): | ||||||
|         self.table = self.getTable() |         self.table = self.getTable() | ||||||
| 
 | 
 | ||||||
|     def get(self, trackId): |     def get(self, trackId): | ||||||
|         stmt = self.table.select().where(self.table.c.trackid == trackId) |         stmt = self.table.select().where(self.table.c.trackid == int(trackId)) | ||||||
|         return self.makeTrack(self.session.execute(stmt).first()) |         return self.makeTrack(self.session.execute(stmt).first()) | ||||||
| 
 | 
 | ||||||
|  |     def __getitem__(self, trackId): | ||||||
|  |         tr = self.get(trackId) | ||||||
|  |         if tr is None: | ||||||
|  |             raise KeyError(trackId) | ||||||
|  |         return tr | ||||||
|  | 
 | ||||||
|     def query(self, **crit): |     def query(self, **crit): | ||||||
|         stmt = self.table.select().where( |         stmt = self.table.select().where( | ||||||
|                 and_(*self.setupWhere(crit))).order_by(self.table.c.trackid) |                 and_(*self.setupWhere(crit))).order_by(self.table.c.trackid) | ||||||
|  |  | ||||||
|  | @ -19,7 +19,8 @@ def test_tracking(self, storage): | ||||||
|         trid01 = tracks.save(tr01) |         trid01 = tracks.save(tr01) | ||||||
|         self.assertTrue(trid01 > 0) |         self.assertTrue(trid01 > 0) | ||||||
| 
 | 
 | ||||||
|         tr01a = tracks.get(trid01) |         #tr01a = tracks.get(trid01) | ||||||
|  |         tr01a = tracks['%07i' % trid01] | ||||||
|         self.assertEqual(tr01a.head, tr01.head) |         self.assertEqual(tr01a.head, tr01.head) | ||||||
|         self.assertEqual(tr01a.trackId, trid01) |         self.assertEqual(tr01a.trackId, trid01) | ||||||
|         self.assertEqual(tr01a.data.get('activity'), 'testing') |         self.assertEqual(tr01a.data.get('activity'), 'testing') | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue