Changeset 83
- Timestamp:
- 03/31/08 14:55:37 (5 months ago)
- Files:
-
- sucrose/trunk/python/api/sucrose.py (modified) (4 diffs)
- sucrose/trunk/python/mysql/db.py (modified) (1 diff)
- sucrose/trunk/python/tests/test_sucrose.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sucrose/trunk/python/api/sucrose.py
r77 r83 35 35 36 36 return self.trays.filter_by(machine_tray_id=int(location)).first() 37 37 38 38 def vend(self, location, uin): 39 39 transaction = self.session.begin() … … 42 42 if not user: 43 43 raise ValueError('no such user') 44 44 45 45 tray = self.tray_from_location(location) 46 46 if not tray: … … 50 50 if tray.quantity <= 0: 51 51 raise ValueError('no product in tray') 52 52 53 53 # comparing Decimal with float will otherwise behave strangely 54 54 if tray.cur_price * 100 > int(user.balance * 100): 55 55 raise ValueError('not enough money') 56 56 57 57 tray.quantity -= 1 58 58 tray.num_consumed += 1 … … 62 62 if hasattr(self, 'pic'): 63 63 self.pic.vendItem(location) 64 # XXX committing the session should commit the transaction?65 transaction.commit()66 64 self.session.commit() 67 self.session.close()68 65 except: 69 self.session. close()66 self.session.rollback() 70 67 raise 71 68 sucrose/trunk/python/mysql/db.py
r82 r83 49 49 mapper(Tray, _trays, properties={'item': relation(Item, uselist=False)}) 50 50 51 _Session = sessionmaker( autoflush=True, twophase=True, transactional=True)51 _Session = sessionmaker(transactional=False, autoflush=False, twophase=True) 52 52 session = _Session() sucrose/trunk/python/tests/test_sucrose.py
r72 r83 21 21 from api.sucrose import Sucrose 22 22 from mysql import db 23 # echo SQL statements as they are executed 24 db._acm.echo = True 25 db._sucrose.echo = True 23 26 self = Sucrose(db, dbonly=True) 24 27 from IPython.Shell import IPShellEmbed
