def delete_student_record():
    student_name = request.form.get('delete')
    student_details = execute_sql("SELECT * FROM Student WHERE StudentName = '{}'".format(student_name))[0]
    StudentName, StudentRegNo, ClassName, StudentSubjectCombi, StudentGender, AllSubjectGrades = student_details
    delete_student_details = Student(StudentName, StudentRegNo, ClassName, StudentSubjectCombi, StudentGender, AllSubjectGrades)

    student_records = execute_sql("SELECT * FROM StudentRecords WHERE StudentName = '{}'".format(student_name))

    seating_arrangement_record = execute_sql("SELECT * FROM SeatingArrangement WHERE StudentName = '{}'".format(student_name))[0]
    StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo = seating_arrangement_record
    delete_seating_arrangement_record = SeatingArrangement(StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo)

    #Delete the database
    execute_sql(delete_student_details.delete_record())
    execute_sql(delete_seating_arrangement_record.delete_record())
    for i in range(len(student_records)):
        StudentName, SubjectGrade, SubjectName = student_records[i]
        delete_student_record = StudentRecords(StudentName, SubjectGrade, SubjectName)
        execute_sql(delete_student_record.delete_record())

    #remove class if the class no longer has any students in it
    students_from_class = execute_sql("SELECT * FROM Student WHERE ClassName == '{}'".format(ClassName))
    if students_from_class == []:
        class_details = execute_sql("SELECT * FROM Class WHERE ClassName == '{}'".format(ClassName))[0]
        ClassName, TotalStudents = class_details
        delete_class = Class(ClassName, TotalStudents)
        execute_sql(delete_class.delete_record())

    #Return to the main page
    return redirect(url_for("display_all_student_records"))
def delete_student_record(student_name):
    student_details = execute_sql(
        "SELECT * FROM Student WHERE StudentName = '{}'".format(
            student_name))[0]
    StudentName, StudentRegNo, ClassName, StudentSubjectCombi, StudentGender, AllSubjectGrades = student_details
    delete_student_details = Student(StudentName, StudentRegNo, ClassName,
                                     StudentSubjectCombi, StudentGender,
                                     AllSubjectGrades)

    student_records = execute_sql(
        "SELECT * FROM StudentRecords WHERE StudentName = '{}'".format(
            student_name))

    seating_arrangement_record = execute_sql(
        "SELECT * FROM SeatingArrangement WHERE StudentName = '{}'".format(
            student_name))[0]
    StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo = seating_arrangement_record
    delete_seating_arrangement_record = SeatingArrangement(
        StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects,
        StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo)

    if request.method == 'POST':
        #Delete the database
        execute_sql(delete_student_details.delete_record())
        execute_sql(delete_seating_arrangement_record.delete_record())
        for i in range(len(student_records)):
            StudentName, SubjectGrade, SubjectName = student_records[i]
            delete_student_record = StudentRecords(StudentName, SubjectGrade,
                                                   SubjectName)
            execute_sql(delete_student_record.delete_record())

        #Return to the main page
        return redirect(url_for("display_all_student_records"))

    else:
        return render_template('delete_student_record.html',
                               delete_student_details=delete_student_details)