Beispiel #1
0
 def add(self):
     print(Style.create_title('Add %s' % self.table_name))
     data = self.input_add_data()
     self.validate_model_data(data['own'])
     if self.model.is_valid():
         self.save_data(data)
     else:
         self.display_errors('%s not added' % self.table_name)
     Menu.wait_for_input()
Beispiel #2
0
 def show_jobs_by_assigned_to(self, staff_id):
     print(Style.create_title('Select job to log time'))
     job = self.paginated_menu(
         find=lambda limit, page: self.repository.
         find_paginated_by_assigned_to(staff_id, limit, page),
         find_by_id=self.repository.find_by_id)
     if job:
         self.show_item_detail(job)
         self.show_item_menu(job['id'])
 def select_foreign_key_relationship(relationship):
     repository = relationship.repository()
     print(Style.create_title('Select %s' % relationship.name))
     paginated_menu = relationship.paginated_menu or Pagination(repository)
     item = paginated_menu()
     if item:
         return item[0]
     else:
         return False
Beispiel #4
0
 def generate(self):
     print(Style.create_title('Generate Invoice'))
     invoice = self.make_paginated_menu()
     if invoice:
         jobRepository = JobRepository()
         jobs = jobRepository.find_jobs_by_invoice_id(invoice['id'])
         self.enter_billable_time(jobRepository, jobs)
         jobs = jobRepository.find_jobs_by_invoice_id(invoice['id'])
         invoice_data = self.make_invoice_dictionary(invoice, jobs)
         LatexInvoice().generate(**invoice_data)
         self.mark_invoiced_jobs_as_complete(jobRepository, jobs)
         Menu.wait_for_input()
Beispiel #5
0
 def enter_billable_time(self, jobRepository, jobs):
     print(Style.create_title('Enter Billable Time'))
     for job in jobs:
         print('Title: %s' % job['title'])
         print('Description: %s' % job['description'])
         print('Estimated Time: %s' % job['estimated_time'])
         print('Logged Time: %s' % job['actual_time'])
         billable = ''
         while not Validation.isFloat(billable):
             billable = input('Billable Time: ')
         jobRepository.update_billable_time(job['id'], billable)
         jobRepository.save()
         jobRepository.check_rows_updated('Job Updated')
Beispiel #6
0
 def edit(self):
     print(Style.create_title('Edit %s' % self.table_name))
     item = self.make_paginated_menu()
     if item:
         data = self.input_edit_data(item)
         data['own'] = self.validate_model_data(data['own'])
         if self.model.is_valid:
             self.save_update(data, item)
         else:
             self.display_errors('%s not updated' % self.table_name)
     else:
         print('No changes made')
     Menu.wait_for_input()
Beispiel #7
0
 def delete(self):
     print(Style.create_title('Delete %s' % self.table_name))
     item = self.make_paginated_menu()
     if item:
         user_action = False
         while not user_action == 'delete':
             user_action = input(
                 'Type \'%s\' to remove this item or %s to cancel: ' %
                 (Colour.red('delete'), Colour.green('c')))
             if user_action == 'c':
                 return
         self.save_remove(item)
         Menu.wait_for_input()
 def select_foreign_key_relationship_inverse(relationship):
     foreign_keys = []
     repository = relationship.repository()
     while Menu.yes_no_question('Add %s' % relationship.name):
         print(Style.create_title('Select %s' % relationship.name))
         paginated_menu = relationship.paginated_menu or Pagination(
             repository)
         item = paginated_menu()
         if item:
             foreign_keys.append(item['id'])
         else:
             print('\nNo relationship added\n')
     return relationship.related_name, foreign_keys
Beispiel #9
0
 def create(title, action_collection: ActionCollection):
     user_input = 0
     keys = []
     while True:
         print(Style.create_title(title))
         for action in action_collection.actions:
             print(Colour.green(action.key) + ": " + str(action))
             keys.append(action.key)
         while user_input not in keys:
             user_input = input('\nSelect an option: ')
         for action in action_collection.actions:
             if action.check_input(user_input):
                 action.execute()
         if user_input == 'b' or user_input == 'q':
             break
         else:
             user_input = 0
Beispiel #10
0
 def show_item_detail(self, item):
     print(Style.create_title('%s Data' % self.table_name))
     for header in self.repository.get_headers():
         label = Style.make_label(header)
         print('%s: %s' % (label, Colour.blue(str(item[header]))))
Beispiel #11
0
 def show(self):
     print(Style.create_title('Show %s' % self.table_name))
     item = self.make_paginated_menu()
     if item:
         self.show_item_detail(item)
         self.show_item_menu(item['id'])
Beispiel #12
0
 def display_errors(self, message):
     print(Style.create_title(message))
     for (key, value) in self.model.get_errors().items():
         print("%s: %s" % (key.capitalize(), Colour.red(value)))