Endret makslengde for produktnavn fra 30 til 45 tegn.
Gjorde følgende endring i databasen: ALTER TABLE products ALTER COLUMN name TYPE CHARACTER VARYING(45); Lagret samtidig lengden på produktnavnfeltet i Product.name_length istedenfor å hardkode det rundt omkring i formatstrenger og input-sjekker. (\ /) (O.o) (> <) Bunny approves these changes.
This commit is contained in:
parent
b4bfaf5e96
commit
100cc8eda4
3
db.py
3
db.py
@ -34,11 +34,12 @@ class Product(Base):
|
||||
__tablename__ = 'products'
|
||||
|
||||
bar_code = Column(String(13), primary_key=True)
|
||||
name = Column(String(30))
|
||||
name = Column(String(45))
|
||||
price = Column(Integer)
|
||||
|
||||
bar_code_re = r"[0-9]+"
|
||||
name_re = r".+"
|
||||
name_length = 45
|
||||
|
||||
def __init__(self, bar_code, name, price):
|
||||
self.name = name
|
||||
|
@ -589,7 +589,7 @@ class AddProductMenu(Menu):
|
||||
def _execute(self):
|
||||
self.print_header()
|
||||
bar_code = self.input_str('Bar code> ', Product.bar_code_re, (8,13))
|
||||
name = self.input_str('Name> ', Product.name_re, (1,30))
|
||||
name = self.input_str('Name> ', Product.name_re, (1,Product.name_length))
|
||||
price = self.input_int('Price> ', (1,100000))
|
||||
product = Product(bar_code, name, price)
|
||||
self.session.add(product)
|
||||
@ -616,7 +616,7 @@ class EditProductMenu(Menu):
|
||||
('store', 'Store')])
|
||||
what = selector.execute()
|
||||
if what == 'name':
|
||||
product.name = self.input_str('Name> ', Product.name_re, (1,30))
|
||||
product.name = self.input_str('Name> ', Product.name_re, (1,product.name_length))
|
||||
elif what == 'price':
|
||||
product.price = self.input_int('Price> ', (1,100000))
|
||||
elif what == 'store':
|
||||
@ -713,7 +713,7 @@ class ShowUserMenu(Menu):
|
||||
else:
|
||||
print 'Products purchased:'
|
||||
for product in products:
|
||||
print '%-30s %3i' % (product, products[product])
|
||||
print ('%-'+str(Product.name_length)+'s %3i') % (product, products[product])
|
||||
|
||||
|
||||
class UserListMenu(Menu):
|
||||
@ -865,11 +865,11 @@ class ProductListMenu(Menu):
|
||||
self.print_header()
|
||||
text = ''
|
||||
product_list = self.session.query(Product).all()
|
||||
line_format = '%-30s | %6s | %-15s\n'
|
||||
text += line_format % ('name', 'price', 'bar code')
|
||||
text += '---------------------------------------------------------\n'
|
||||
line_format = '%-15s | %5s | %-'+str(Product.name_length)+'s\n'
|
||||
text += line_format % ('bar code', 'price', 'name')
|
||||
text += '-----------------------------------------------------------------------\n'
|
||||
for p in product_list:
|
||||
text += line_format % (p.name, p.price, p.bar_code)
|
||||
text += line_format % (p.bar_code, p.price, p.name)
|
||||
less(text)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user