示例#1
0
 def get(self):
     user = Authorization.isAuthenticated()
     if user:
         employees = EmployeeService.getAll()
         template_values = {
             'employees' : employees
         }
         template = JINJA_ENVIRONMENT.get_template('partials/employees.html')
         self.response.write(template.render(template_values))
     else:
         self.redirect('/')
示例#2
0
 def get(self, employeeKeyUrlSafe):
     user = Authorization.isAuthenticated()
     if user:
         employee = EmployeeService.get(employeeKeyUrlSafe)
         template_values = {
             'employeeName' : employee.employeeName,
             'employeeKeyUrlSafe' : employeeKeyUrlSafe
         }
         template = JINJA_ENVIRONMENT.get_template('partials/employeeEdit.html')
         self.response.write(template.render(template_values))
     else:
         self.redirect('/')
示例#3
0
 def get(self, employeeKeyUrlSafe):
     user = Authorization.isAuthenticated()
     if user:
         try:
             dateFrom = CalendarDetail.dateFrom
         except:
             dateFrom = DateService.getFirstDateOfMonth().strftime('%m/%d/%Y')
         try:
             dateTo = CalendarDetail.dateTo
         except:
             dateTo = DateService.getLastDateOfMonth().strftime('%m/%d/%Y')
         employee = EmployeeService.get(employeeKeyUrlSafe)
         clients = ClientService.getAll()
         lineItems = LineItemService.getAllInRangeForEmployee(employeeKeyUrlSafe, clients, dateFrom, dateTo)
         if lineItems == None:
             lineItems = []
         lineItemDates = []
         for lineItem in lineItems:
             if lineItem.dateOfService not in lineItemDates:
                 lineItemDates.append(lineItem.dateOfService)
         calendarLineItemViewModels = []
         for lineItemDate in lineItemDates:
             lineItemServices = []
             for lineItem in lineItems:
                 if lineItem.dateOfService == lineItemDate:
                     lineItemServices.append(lineItem.service)
             calendarLineItemViewModel = CalendarLineItem(lineItemDate, lineItemServices)
             calendarLineItemViewModels.append(calendarLineItemViewModel)
         template_values = {
             'dateFrom' : dateFrom,
             'dateTo' : dateTo,
             'employee' : employee,
             'calendarLineItemViewModels' : calendarLineItemViewModels
         }
         template = JINJA_ENVIRONMENT.get_template('partials/calendarDetail.html')
         self.response.write(template.render(template_values))
     else:
         self.redirect('/')
示例#4
0
 def post(self):
     user = Authorization.isAuthenticated()
     if user:
         try:
             addNewEmployee = self.request.get('addNewEmployee')
             updateEmployee = self.request.get('updateEmployee')
             deleteEmployee = self.request.get('deleteEmployee')
             employeeAccountManagerSubmit = self.request.get('employeeAccountManagerSubmit')
             if addNewEmployee:
                 EmployeeService.saveNew(self.request)
             elif updateEmployee:
                 EmployeeService.update(self.request)
             elif deleteEmployee:
                 EmployeeService.delete(self.request)
             elif employeeAccountManagerSubmit:
                 AccountManagerService.update(self.request)
         except:
             logging.error("Employees.py => post")
         finally:
             self.redirect('/employees')
     else:
         self.redirect('/')
示例#5
0
class EmployeeUI:
    def __init__(self):
        self.__employee_service = EmployeeService()

    def header(self, i):
        """
        This the header on the employee user interface
        we use it here in the functions down below
        :param i:
        :return:
        """
        print("-" * 50)
        print("|{:^48}|".format(i))
        print("-" * 50)
        print()

    def print_employees(self, emp):
        """
        Prints out all style up and prints out the employees
        :param emp:
        :return:
        """
        start = 0
        stop = 10
        count = 1
        while True:
            print(
                "{:^6}|{:^22}|{:^17}|{:^11}|{:^17}|{:^32}|{:^14}|{:^18}|{:^5}|"
                .format("ID", "Name", "Passport number", "Country", "Address",
                        "E-mail", "Phone number", "Driving license", "Age"))
            print("-" * 153)
            for ix, customer in enumerate(emp[start:stop]):
                print("{:^8}{:<23}{:<18}{:<12}{:<18}{:<33}{:<15}{:<19}{:<7}".
                      format(ix + count, customer["Name"],
                             customer["Passport number"], customer["Country"],
                             customer["Address"], customer["Mail"],
                             customer["Phone number"], customer["license"],
                             customer["Age"]))
            print()
            y_n = input("Next / Previous / Quit searching (N/P/Q): ").lower()
            if y_n == "n" and count + 10 < len(emp):
                start, stop, count = self.__employee_service.next_list(stop)
            elif y_n == "n" and count + 10 >= len(emp):
                print("\nCant go forwards while on the last page\n")
            elif y_n == "p" and count != 1:
                start, stop, count = self.__employee_service.prev_list(start)
            elif y_n == 'p' and count == 1:
                print("\nCant go back while on the first page\n")
                continue
            elif y_n == 'q':
                return y_n
            else:
                print("\n\33[;31mWrong input, try again!\33[;0m\n")
                continue

    def add_employee(self):
        """
        this give you the chance to create an employee. by asking you details about the customer.
        :return:
        """
        self.header("Add employee")
        try:
            print("Creating Employee:")
            kt = input("\tEnter PPN/Kt number: ").translate(remove_punct_map)
            if self.__employee_service.check_kt(kt):
                print("\nCustomer already exists\n")
            else:
                name = input("\tEnter name: ").translate(remove_punct_map)
                country = input("\tEnter country: ").translate(
                    remove_punct_map)
                address = input("\tEnter address: ").translate(
                    remove_punct_map)
                mail = input("\tEnter mail: ").strip()
                phone = input("\tEnter phone number: ").translate(
                    remove_punct_map)
                customer_license = input("\tEnter drivers license: ")
                age = int(input("\tEnter age: "))
                new_employee = Employee(name, kt, country, address, mail,
                                        phone, customer_license, age)
                print(new_employee)
                if input(
                        "Do you want to create this Employee? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                ).upper() == "Y":
                    self.__employee_service.add_employee(new_employee)
                    print("\nEmployee created!\n")
                else:
                    print("\nNo employee created.\n")

        except Exception:
            print(
                "\n\33[;31mSomething went wrong, no employee created.\33[;0m\n"
            )
        input("\33[;32mPress enter to continue \33[;0m")

    def list_employees(self, employees):
        """
        This calls the print_employees function and list the employees, or tells you
        that there are no employees in the csv file.
        :param employees:
        :return:
        """
        self.header("Employees")
        if employees:
            self.print_employees(employees)
        else:
            print("No employees\n")
        input("\33[;32mPress enter to continue \33[;0m")

    def remove_employee(self, employees):
        """
        Remove an employee from the csv file.. by delete all employees, and all all the employee back without
        the specific employee that you chose by the ID
        :param employees:
        :return:
        """
        self.header("Remove employee")
        if employees:
            removing = True
            while removing:
                self.print_employees(employees)
                employee_to_delete = input(
                    "Select employee by Id (\33[;31mq to quit\33[;0m): ")
                if employee_to_delete.isdigit():
                    try:
                        are_you_sure = input(
                            "Are you sure you want to delete this employee? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                        ).lower()
                        if are_you_sure == "y":
                            emp = self.__employee_service.get_employee_by_id(
                                int(employee_to_delete))
                            print(emp["Name"])
                            self.__employee_service.remove_employee(
                                int(employee_to_delete))
                            removing = False
                    except Exception:
                        print("\n\33[;31mCanceled\33[;0m\n")
                elif employee_to_delete.lower() == 'q':
                    break
                else:
                    print("\nPlease enter a correct input\n")
        else:
            print("No employee to delete\n")
        input("\33[;32mPress enter to continue \33[;0m")

    def edit_employee(self, employees):
        """
        offers you you change details about the employee (e. Edit name)
        :param employees:
        :return:
        """
        self.header("Edit employee")
        if employees:
            try:
                editing = True
                while editing:
                    self.print_employees(employees)
                    c_id = input(
                        "Select employee by Id (\33[;31mq to quit\33[;0m): ")
                    if c_id.isdigit() and int(c_id) <= len(employees):
                        employee = self.__employee_service.get_employee_by_id(
                            int(c_id))
                        if employee:
                            print(employee["Name"])
                            new_employee = Employee(
                                employee["Name"], employee["Passport number"],
                                employee["Country"], employee["Address"],
                                employee["Mail"], employee["Phone number"],
                                int(employee["license"]), employee["Age"])

                            choice = ""
                            while choice != "q":
                                print(
                                    "\n1. Edit Name\n2. Edit Passport\n3. Edit country\n4. Edit Address\n5. Edit mail\n"
                                    "6. Edit Phone number\n7. Edit license\n8. Edit Age\n\n\33[;31mPress q to quit\33[;0m\n"
                                )
                                choice = input("Enter your choice: ").lower()
                                if choice == "1":
                                    new_employee.set_name(
                                        input("Enter new Name: ").translate(
                                            remove_punct_map))
                                elif choice == "2":
                                    new_employee.set_kt(
                                        input("Enter new PPN/Kt: ").translate(
                                            remove_punct_map))
                                elif choice == "3":
                                    new_employee.set_country(
                                        input("Enter new Country: ").translate(
                                            remove_punct_map))
                                elif choice == "4":
                                    new_employee.set_address(
                                        input("Enter Address: ").translate(
                                            remove_punct_map))
                                elif choice == "5":
                                    new_employee.set_mail(
                                        input("Enter new Mail: "))
                                elif choice == "6":
                                    new_employee.set_phone_number(
                                        input("Enter new Phone number: ").
                                        translate(remove_punct_map))
                                elif choice == "7":
                                    new_employee.set_license(
                                        input("Enter new License: ").translate(
                                            remove_punct_map))
                                elif choice == "8":
                                    new_employee.set_age(
                                        input("Enter new Age: ").replace(
                                            string.punctuation, ""))

                            self.__employee_service.remove_employee(int(c_id))
                            self.__employee_service.add_employee(new_employee)
                            print(new_employee)
                            editing = False
                    elif c_id.lower() == 'q':
                        break
                    else:
                        print(
                            "\n\33[;31mPlease enter a correct input\33[;0m\n")
            except Exception:
                print("\n\33[;31mSomething went wrong!\33[;0m\n")
        else:
            print("No employee to edit\n")
        input("\33[;32mPress enter to continue \33[;0m")

    def main_menu(self):
        """
        This is the main menu for the employees user interface.. offers you to press (e. 1. list all the employees.
        :return:
        """
        action = ""
        while action != 'q':
            employees = self.__employee_service.get_employees()
            os.system('cls')
            self.header("Employees")
            print("You can do the following: ")
            print(
                "1. Add an employee\n2. List all employees\n3. Remove employee\n4. Edit employee\n\33[;31mPress q to go back \33[;0m"
            )

            action = input("\nChoose an option: ").lower()

            if action == "1":
                self.add_employee()

            elif action == '2':
                self.list_employees(employees)

            elif action == "3":
                self.remove_employee(employees)

            elif action == "4":
                self.edit_employee(employees)
示例#6
0
 def __init__(self):
     self.__employee_service = EmployeeService()
示例#7
0
class Employee(Model, UserMixin):
    __tablename__ = 'employee'
    __table_args__ = {
        'autoload': True,
        'autoload_with': DatabaseService.DBEngine()
    }
    service = EmployeeService()

    def __init__(self):
        self.is_authenticated = True
        self.type = "Employee"

    def setCredentials(self, username, passw):
        self.username = username
        self.setPassword(passw)

    def setPassword(self, passw):
        self.password = generate_password_hash(passw)

    def __repr__(self):
        return '<User %r>' % self.username

    def is_authenticated(self):
        return self.is_authenticated

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.employee_id)

    @staticmethod
    def getById(id):
        employee = Employee.service.get(id)
        print employee
        if (employee != None):
            employee.new = False
        return employee

    @staticmethod
    def getByUsername(username):
        employee = Employee.service.getByUsername(username)
        print employee
        if (employee != None):
            employee.new = False
        return employee

    @staticmethod
    def getAllExcluding(ids, visible='Y'):
        employee = Employee.service.getAllByFilter(ids, visible)
        print employee
        return employee

    @staticmethod
    def getAll():
        employee = Employee.service.getAll()
        print employee
        return employee

    @staticmethod
    def getByCredential(username, passw):
        employee = Employee.service.getByCredential(username, passw)
        print employee
        if (employee is not None):
            employee.new = False
        return employee

    @staticmethod
    def add(employee):
        old_employee = Employee.service.getByUsername(employee.username)
        if (old_employee is not None):
            "throw exception user already exists"
            return False
        Employee.service.add(employee)
        return True

    @staticmethod
    def delete(employee):
        return Employee.service.delete(employee)

    def update(self):
        Employee.service.update(self)