|
@@ -1,14 +1,24 @@
|
|
|
-from PyInquirer import prompt
|
|
|
+from PyInquirer import prompt, Validator, ValidationError
|
|
|
+from prompt_toolkit import document
|
|
|
+import regex
|
|
|
|
|
|
# Ask for a quantity
|
|
|
|
|
|
+class QuantityValidator(Validator):
|
|
|
+ def validate(self, document):
|
|
|
+ ok = regex.match('^[1-9][0-9]*00$', document.text)
|
|
|
+ if not ok:
|
|
|
+ raise ValidationError(message = 'Quantity must be a positive integer multiple of 100')
|
|
|
+
|
|
|
class QuantityAsker:
|
|
|
+ """Ask quantity for name entries"""
|
|
|
def __init__(self):
|
|
|
self.widget = [
|
|
|
{
|
|
|
'type':'input',
|
|
|
'name':'number',
|
|
|
- 'message':'Enter a quantity'
|
|
|
+ 'message':'Enter a quantity',
|
|
|
+ 'validate':QuantityValidator
|
|
|
}
|
|
|
]
|
|
|
|