Browse Source

A skeleton for the customer order application

Jovian (Netbook) 6 years ago
parent
commit
f3fe9ade30
3 changed files with 74 additions and 0 deletions
  1. 43 0
      app_customer.py
  2. 18 0
      cli/customer_action_asker.py
  3. 13 0
      consumer/connect.py

+ 43 - 0
app_customer.py

@@ -0,0 +1,43 @@
+from consumer.connect import DataConsumer
+from consumer.credentials import getCredentials
+from basic_display import BasicDisplay
+from cli.name_asker import NameAsker
+from cli.pass_asker import PassAsker
+from cli.customer_action_asker import CustomerActionAsker
+
+print('|Customer application|')
+
+credentials = getCredentials()
+consumer = DataConsumer(credentials)
+
+nameAsker = NameAsker()
+passAsker = PassAsker()
+actionAsker = CustomerActionAsker()
+
+display = BasicDisplay()
+
+# Login phase
+login = nameAsker.ask()
+pwd = passAsker.ask()
+
+compList = consumer.getCompanyNames()
+compList.append('dev')
+
+if login in compList:
+    print('Successfully logged as', login)
+else:
+    print('Name', login, 'not recognized.')
+    exit()
+
+# Action phase
+running = True
+while running:
+    ans = actionAsker.ask()
+    action = ans['action']
+    
+    if action == 'quit':
+        running = False
+    else:
+        print('Action', action, 'not implemented yet.')
+
+print('End')

+ 18 - 0
cli/customer_action_asker.py

@@ -0,0 +1,18 @@
+from PyInquirer import prompt 
+
+# Ask for an action to manage orders
+
+class CustomerActionAsker:
+    def __init__(self):
+        self.widget = [
+            {
+                'type':'list',
+                'name':'action',
+                'message':'What do you want to do about orders ?',
+                'choices':['list orders','list warehouses','new command','quit']
+            }
+        ]
+
+    def ask(self):
+        return prompt(self.widget)
+

+ 13 - 0
consumer/connect.py

@@ -26,6 +26,19 @@ class DataConsumer():
 
         cursor.close()
 
+    def getCompanyNames(self):
+        cursor = self.conn.cursor()
+
+        cursor.execute("SELECT com_name FROM Company")
+
+        ans = []
+        for t in cursor:
+            ans.append(t[0])
+
+        cursor.close()
+
+        return ans
+
     def commit(self):
         """Make the changes to the database persistent"""
         self.conn.commit()