Superhurtigkjøp (fikser #8).

This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-03-10 15:03:19 +00:00
parent 6493173339
commit f1ef355fd6

View File

@ -801,6 +801,7 @@ class BuyMenu(Menu):
Menu.__init__(self, 'Buy', uses_db=True)
if session:
self.session = session
self.superfast_mode = False
self.help_text = '''
Each purchase may contain one or more products and one or more buyers.
@ -827,10 +828,20 @@ When finished, write an empty line to confirm the purchase.
self.print_header()
self.purchase = Purchase()
self.exit_confirm_msg=None
self.superfast_mode = False
for thing in initialContents:
self.add_thing_to_purchase(thing)
isproduct = lambda t: isinstance(t, Product)
if len(initialContents) > 0 and all(map(isproduct, initialContents)):
self.superfast_mode = True
print '***********************************************'
print '****** Buy menu is in SUPERFASTmode[tm]! ******'
print '*** The purchase will be stored immediately ***'
print '*** when you enter a user. ***'
print '***********************************************'
while True:
self.print_purchase()
self.printc({(False,False): 'Enter user or product identification',
@ -861,6 +872,10 @@ When finished, write an empty line to confirm the purchase.
# Add the thing to our purchase object:
self.add_thing_to_purchase(thing)
# In superfast mode, we complete the purchase once we get a user:
if self.superfast_mode and isinstance(thing, User):
break
self.purchase.perform_purchase()
self.session.add(self.purchase)
try: