ProductListMenu bruker less (det er blitt for mange produkter til at

alle får plass på skjermen på en gang).

La til ProductSearchMenu.
This commit is contained in:
Øystein Ingmar Skartsæterhagen 2010-09-04 14:30:19 +00:00
parent 467c6af263
commit b4bfaf5e96
1 changed files with 18 additions and 4 deletions

View File

@ -863,12 +863,25 @@ class ProductListMenu(Menu):
def _execute(self): def _execute(self):
self.print_header() self.print_header()
text = ''
product_list = self.session.query(Product).all() product_list = self.session.query(Product).all()
line_format = '%-30s | %6s | %-15s' line_format = '%-30s | %6s | %-15s\n'
print line_format % ('name', 'price', 'bar code') text += line_format % ('name', 'price', 'bar code')
print '---------------------------------------------------------' text += '---------------------------------------------------------\n'
for p in product_list: 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() self.pause()
@ -906,6 +919,7 @@ main = Menu('Dibbler main menu',
Menu('Add/edit', Menu('Add/edit',
items=[AddUserMenu(), EditUserMenu(), items=[AddUserMenu(), EditUserMenu(),
AddProductMenu(), EditProductMenu()]), AddProductMenu(), EditProductMenu()]),
ProductSearchMenu(),
FAQMenu() FAQMenu()
], ],
exit_msg='happy happy joy joy', exit_msg='happy happy joy joy',