示例#1
0
def create_employee(cursor, row):
    _row = sqlite3.Row(cursor, row)

    employee = Employee()
    employee.id = _row["employee_id"]
    employee.first_name = _row["first_name"]
    employee.last_name = _row["last_name"]
    employee.start_date = _row["start_date"]
    employee.department_id = _row["department_id"]
    employee.is_supervisor = _row["is_supervisor"]

    department = Department()
    department.id = _row["department_id"]
    department.dept_name = _row["dept_name"]

    computer = Computer()
    computer.manufacturer = _row["manufacturer"]
    computer.make = _row["make"]
    computer.id = _row["computer_id"]

    # training_program = TrainingProgram()
    # training_program.title = _row["title"]

    employee.department = department
    employee.computer = computer
    # employee.training_program = training_program

    return employee
def employee_list(request):
    if request.method == 'GET':
        with sqlite3.connect(Connection.db_path) as conn:
            conn.row_factory = sqlite3.Row
            db_cursor = conn.cursor()

            # TODO: Add to query: e.department,
            db_cursor.execute("""
            	select
                e.id,
                e.first_name,
                e.last_name,
                e.start_date,
                e.is_supervisor,
                d.dept_name
                from hrapp_employee e
                join hrapp_department d               
                on e.department_id = d.id
            """)

            all_employees = []
            dataset = db_cursor.fetchall()

            for row in dataset:
                employee = Employee()
                employee.id = row['id']
                employee.first_name = row['first_name']
                employee.last_name = row['last_name']
                employee.start_date = row['start_date']
                employee.is_supervisor = row['is_supervisor']

                department = Department()
                department.name = row['dept_name']

                employee.department = department

                all_employees.append(employee)

            template = 'employees/employees_list.html'
            context = {'employees': all_employees}
            return render(request, template, context)

    elif request.method == 'POST':
        form_data = request.POST

        with sqlite3.connect(Connection.db_path) as conn:
            db_cursor = conn.cursor()

            db_cursor.execute(
                """
            INSERT INTO hrapp_employee
            (first_name, last_name, start_date, is_supervisor, department_id)
            VALUES(?,?,?,?,?)
            """, (form_data['first'], form_data['last'],
                  form_data['start_date'], form_data['is_supervisor'],
                  form_data['department']))

        return redirect(reverse('hrapp:employee_list'))
def create_employee(cursor, row):
    _row = sqlite3.Row(cursor, row)

    e = Employee()
    e.id = _row["id"]
    e.first_name = _row["first_name"]
    e.last_name = _row["last_name"]

    d = Department()
    d.name = _row["department"]

    e.department = d

    return e
def employee_list(request):
    if request.method == 'GET':
        with sqlite3.connect(Connection.db_path) as conn:
            conn.row_factory = sqlite3.Row
            db_cursor = conn.cursor()

            db_cursor.execute("""
            select
                e.id,
                e.first_name,
                e.last_name,
                e.is_supervisor,
                e.start_date,
                e.department_id,
                d.name
            FROM hrapp_employee e LEFT JOIN hrapp_department d ON e.department_id = d.id;
            """)

            all_employees = []
            dataset = db_cursor.fetchall()

            for row in dataset:
                employee = Employee()
                employee.id = row['id']
                employee.first_name = row['first_name']
                employee.last_name = row['last_name']
                employee.is_supervisor = row['is_supervisor']
                employee.start_date = row['start_date']
                employee.department_id = row['department_id']

                department = Department()
                department.id = row['id']
                department.name = row['name']
                # department.budget = row['budget']

                employee.department = department

                all_employees.append(employee)

    template = 'employees/employees_list.html'
    context = {
        'employees': all_employees
    }

    return render(request, template, context)
示例#5
0
def create_employee(cursor, row):
    _row = sqlite3.Row(cursor, row)

    e = Employee()
    e.id = _row["id"]
    e.first_name = _row["first_name"]
    e.last_name = _row["last_name"]

    d = Department()
    d.name = _row["department"]

    c = Computer()
    c.id = _row["computer_id"]
    c.make = _row["computer"]

    e.department = d
    e.computer = c

    return e