From f1ef355fd6f034f42aab1f3e465520d43a30a804 Mon Sep 17 00:00:00 2001 From: oysteini Date: Thu, 10 Mar 2011 15:03:19 +0000 Subject: [PATCH] =?UTF-8?q?Superhurtigkj=C3=B8p=20(fikser=20#8).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text_based.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/text_based.py b/text_based.py index 81151c3..273bd91 100755 --- a/text_based.py +++ b/text_based.py @@ -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: