def past_training_list(request):
    pass
    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
                *
            from hrapp_trainingprogram ht
            """)

            past_programs = []
            dataset = db_cursor.fetchall()

            d = datetime.datetime.today()
            current_date = str(d).split(' ')[0]
            for row in dataset:
                training_program = TrainingProgram()
                training_program.id = row['id']
                training_program.title = row['title']
                training_program.description = row['description']
                training_program.start_date = row['start_date']
                training_program.end_date = row['end_date']
                training_program.capacity = row['capacity']

                if (row['start_date'] < current_date):
                    past_programs.append(training_program)

        template = 'training_programs/past_training_list.html'
        context = {'trainings': past_programs}

        return render(request, template, context)
def training_programs_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
                tp.id,
                tp.title,
                tp.description,
                tp.start_date,
				tp.end_date,
				tp.capacity
            from hrapp_trainingprogram tp
            """)

            all_programs = []
            dataset = db_cursor.fetchall()

            for row in dataset:
                training_program = TrainingProgram()
                training_program.id = row['id']
                training_program.title = row['title']
                training_program.description = row['description']
                # training_program.start_date = row['start_date']
                training_program.start_date = datetime.strptime(
                    row['start_date'], '%Y-%m-%d')
                training_program.end_date = row['end_date']
                training_program.capacity = row['capacity']

                today = datetime.today()

                # if (training_program.start_date > today):
                all_programs.append(training_program)

        template = 'training_programs/training_programs_list.html'
        context = {'programs': all_programs, 'time': today}

        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_trainingprogram
            (
                title, description, start_date,
                end_date, capacity
            )
            VALUES (?, ?, ?, ?, ?)
            """, (form_data['title'], form_data['description'],
                  form_data['start_date'], form_data['end_date'],
                  form_data["capacity"]))

        return redirect(reverse('hrapp:training_programs'))
def training_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
                *
            from hrapp_trainingprogram ht
            """)

            all_programs = []
            dataset = db_cursor.fetchall()

            d = datetime.datetime.today()
            current_date = str(d).split(' ')[0]
            for row in dataset:
                training_program = TrainingProgram()
                training_program.id = row['id']
                training_program.title = row['title']
                training_program.description = row['description']
                training_program.start_date = row['start_date']
                training_program.end_date = row['end_date']
                training_program.capacity = row['capacity']

                if (row['start_date'] > current_date):
                    all_programs.append(training_program)

        if request.user.is_authenticated:
            template = 'training_programs/training_list.html'
        else:
            template = 'training_programs/training_list_view_only.html'

        context = {'trainings': all_programs}

        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_trainingprogram
            (
            title, description, start_date, end_date, capacity
            )
            VALUES (?, ?, ?, ?, ?)
            """, (form_data['title'], form_data['description'],
                  form_data['start_date'], form_data['end_date'],
                  form_data['capacity']))

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

    training_program = TrainingProgram()
    training_program.id = _row["training_program_id"]
    training_program.title = _row["title"]
    training_program.start_date = _row["start_date"]
    training_program.end_date = _row["end_date"]
    training_program.capacity = _row["capacity"]
    training_program.description = _row["description"]

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

    training_program.employee = employee

    return training_program
def past_program_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
                tp.id,
                tp.title,
                tp.start_date,
                tp.end_date,
                tp.capacity,
                tp.description
            from hrapp_trainingprogram tp
            """)


            future_training_programs = []
            past_training_programs = []
            todaydate = datetime.today().strftime("%Y-%m-%d")
            dataset = db_cursor.fetchall()

            for row in dataset:
                training_program = TrainingProgram()
                training_program.id = row['id']
                training_program.title = row['title']
                training_program.start_date = row['start_date']
                training_program.end_date = row['end_date']
                training_program.capacity = row['capacity']
                training_program.description = row['description']


                if(training_program.start_date > todaydate):
                    future_training_programs.append(training_program)
                else:
                    past_training_programs.append(training_program)



            template = 'trainingprograms/past.html',
            context = {
                'past_training_programs': past_training_programs,
                'future_training_programs': future_training_programs
            }

        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_trainingprogram
            (
                title, start_date, end_date,
                capacity, description
            )
            VALUES (?, ?, ?, ?, ?)
            """,
            (form_data['title'], form_data['start_date'],
                form_data['end_date'], form_data['capacity'],
                form_data["description"]))

            return redirect(reverse('hrapp:trainingprograms'))