Ny meny: UserListMenu.

This commit is contained in:
Øystein Ingmar Skartsæterhagen 2010-05-13 18:25:19 +00:00
parent 9199da6c13
commit e162f415be
1 changed files with 27 additions and 3 deletions

View File

@ -578,6 +578,29 @@ class ShowUserMenu(Menu):
print string print string
class UserListMenu(Menu):
def __init__(self):
Menu.__init__(self, 'User list')
def _execute(self):
self.print_header()
self.session = Session()
user_list = self.session.query(User).all()
total_credit = self.session.query(sqlalchemy.func.sum(User.credit)).first()[0]
line_format = '%-12s | %6s'
hline = '---------------------'
print line_format % ('username', 'credit')
print hline
for user in user_list:
print line_format % (user.name, user.credit)
print hline
print line_format % ('total credit', total_credit)
self.session.close()
self.pause()
class BuyMenu(Menu): class BuyMenu(Menu):
def __init__(self): def __init__(self):
Menu.__init__(self, 'Buy') Menu.__init__(self, 'Buy')
@ -703,13 +726,14 @@ class ProductListMenu(Menu):
def _execute(self): def _execute(self):
self.print_header() self.print_header()
session = Session() self.session = Session()
product_list = session.query(Product).all() product_list = self.session.query(Product).all()
line_format = '%-30s | %6s | %-15s' line_format = '%-30s | %6s | %-15s'
print line_format % ('name', 'price', 'bar code') print line_format % ('name', 'price', 'bar code')
print '---------------------------------------------------------' print '---------------------------------------------------------'
for p in product_list: for p in product_list:
print line_format % (p.name, p.price, p.bar_code) print line_format % (p.name, p.price, p.bar_code)
self.session.close()
self.pause() self.pause()
@ -742,7 +766,7 @@ def restart():
if not conf.stop_allowed: if not conf.stop_allowed:
signal.signal(signal.SIGTSTP, signal.SIG_IGN) signal.signal(signal.SIGTSTP, signal.SIG_IGN)
main = Menu('Dibbler main menu', main = Menu('Dibbler main menu',
items=[BuyMenu(), ProductListMenu(), ShowUserMenu(), items=[BuyMenu(), ProductListMenu(), ShowUserMenu(), UserListMenu(),
AdjustCreditMenu(), TransferMenu(), AdjustCreditMenu(), TransferMenu(),
Menu('Add/edit', Menu('Add/edit',
items=[AddUserMenu(), EditUserMenu(), items=[AddUserMenu(), EditUserMenu(),