Esempio n. 1
0
 def get_employee_name(self):
     """Get employee name from user"""
     # Get imput
     name = input('Please give name of the employee to search for\t')
     employees = Employee.find_by_name(name)
     employees = [employee for employee in employees]
     if employees == []:
         return None
     if len(employees) == 1:
         # Return employee if we only got 1 match
         return employees[0].name
     # Let the user choose an employee if we found more than 1
     print('We found multiple employees with that name. Please choose one from the list below (specify number)\n')
     inp = []
     for x, emp in enumerate(employees):
         inp.append('{}: {}'.format(x, emp.name))
     option = input('\n'.join(inp) + '\n')
     # Validate input
     try:
         emp = employees[int(option)]
     except (IndexError, ValueError) as e:
         if self.test:
             raise e
         print('Invalid option')
         sleep(1)
         return self.get_employee_name()
     # Return employee
     return emp.name
Esempio n. 2
0
 def new(cls, title, employee, time, notes):
     """Create new entry"""
     try:
         emp = Employee.with_name(employee)
     except IntegrityError:
         emp = Employee.find_by_name(employee)[0]
     employee = emp.name
     return cls.create(title=title,
                       employee=employee,
                       time=time,
                       notes=notes)