Use new defaults properly in edit product menu

This commit is contained in:
Robert Maikher 2018-08-30 15:11:17 +02:00
parent ca19cc14da
commit ac3ab8099b
1 changed files with 6 additions and 12 deletions

View File

@ -39,20 +39,14 @@ user, then rfid (write an empty line to remove the card number or rfid).
self.print_header() self.print_header()
user = self.input_user('User') user = self.input_user('User')
self.printc(f'Editing user {user.name}') self.printc(f'Editing user {user.name}')
card_str = f'"{user.card}"' card_str = f'"{user.card}"' if user.card is not None else 'empty'
if user.card is None:
card_str = 'empty'
# TODO: Inconsistent with other defaulted strings. Redo.
user.card = self.input_str(f'Card number (currently {card_str})', user.card = self.input_str(f'Card number (currently {card_str})',
regex=User.card_re, length_range=(0, 10), regex=User.card_re, length_range=(0, 10),
empty_string_is_none=True) empty_string_is_none=True)
if user.card: if user.card:
user.card = user.card.lower() user.card = user.card.lower()
rfid_str = f'"{user.rfid}"' rfid_str = f'"{user.rfid}"' if user.rfid is not None else 'empty'
if user.rfid is None:
rfid_str = 'empty'
# TODO: Inconsistent with other defaulted strings. Redo.
user.rfid = self.input_str(f'RFID (currently {rfid_str})', user.rfid = self.input_str(f'RFID (currently {rfid_str})',
regex=User.rfid_re, length_range=(0, 10), regex=User.rfid_re, length_range=(0, 10),
empty_string_is_none=True) empty_string_is_none=True)
@ -100,15 +94,15 @@ class EditProductMenu(Menu):
('store', 'Store')]) ('store', 'Store')])
what = selector.execute() what = selector.execute()
if what == 'name': if what == 'name':
product.name = self.input_str(f'Name[{product.name}]', regex=Product.name_re, product.name = self.input_str('Name', default=product.name, regex=Product.name_re,
length_range=(1, product.name_length)) length_range=(1, product.name_length))
elif what == 'price': elif what == 'price':
product.price = self.input_int(f'Price[{product.price}]', allowed_range=(1, 100000)) product.price = self.input_int('Price', default=product.price, allowed_range=(1, 100000))
elif what == 'barcode': elif what == 'barcode':
product.bar_code = self.input_str(f'Bar code[{product.bar_code}]', regex=Product.bar_code_re, product.bar_code = self.input_str('Bar code', default=product.bar_code, regex=Product.bar_code_re,
length_range=(8, 13)) length_range=(8, 13))
elif what == 'hidden': elif what == 'hidden':
product.hidden = self.confirm('Hidden[%s]' % ("Y" if product.hidden else "N"), False) product.hidden = self.confirm(f'Hidden(currently {product.hidden})', default=False)
elif what == 'store': elif what == 'store':
try: try:
self.session.commit() self.session.commit()