From b4bfaf5e96ca1b75f7928002abbd24a88b2a8525 Mon Sep 17 00:00:00 2001 From: oysteini Date: Sat, 4 Sep 2010 14:30:19 +0000 Subject: [PATCH] =?UTF-8?q?ProductListMenu=20bruker=20less=20(det=20er=20b?= =?UTF-8?q?litt=20for=20mange=20produkter=20til=20at=20alle=20f=C3=A5r=20p?= =?UTF-8?q?lass=20p=C3=A5=20skjermen=20p=C3=A5=20en=20gang).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La til ProductSearchMenu. --- text_based.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/text_based.py b/text_based.py index 4a0bd56..b9a3a86 100755 --- a/text_based.py +++ b/text_based.py @@ -863,12 +863,25 @@ class ProductListMenu(Menu): def _execute(self): self.print_header() + text = '' product_list = self.session.query(Product).all() - line_format = '%-30s | %6s | %-15s' - print line_format % ('name', 'price', 'bar code') - print '---------------------------------------------------------' + line_format = '%-30s | %6s | %-15s\n' + text += line_format % ('name', 'price', 'bar code') + text += '---------------------------------------------------------\n' for p in product_list: - print line_format % (p.name, p.price, p.bar_code) + text += line_format % (p.name, p.price, p.bar_code) + less(text) + + +class ProductSearchMenu(Menu): + def __init__(self): + Menu.__init__(self, 'Product search', uses_db=True) + + def _execute(self): + self.print_header() + self.set_context('Enter (part of) product name or bar code') + product = self.input_product() + print 'Result: %s, price: %d kr, bar code: %s' % (product.name, product.price, product.bar_code) self.pause() @@ -906,6 +919,7 @@ main = Menu('Dibbler main menu', Menu('Add/edit', items=[AddUserMenu(), EditUserMenu(), AddProductMenu(), EditProductMenu()]), + ProductSearchMenu(), FAQMenu() ], exit_msg='happy happy joy joy',