def reset_seating_arrangement(): #reset seating arrangement object when go back to display, and various setting menus (set_seating_arrangement, class_seating_arrangement, special_class_seating_arrangement) student_lst = execute_sql("SELECT * FROM SeatingArrangement WHERE ClassLst != ''") for student in student_lst: StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo = student student = SeatingArrangement(StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo) student.set_CannotSeatNextTo('') student.set_SeatInFront(False) student.set_ClassLst('') student.set_SeatByGrades('') student.set_RowNo(0) student.set_ColumnNo(0) execute_sql(student.update_record())
def set_student_details(): Subject = None lst = [] if class_seating_arrangement() != None: ClassName = class_seating_arrangement() print(ClassName) lst = execute_sql( "SELECT * FROM Student WHERE ClassName = '{}'".format(ClassName)) lst = list(map(lambda x: x[0], lst)) #lst with all names of valid students print(lst) if special_class_seating_arrangement()[1] != None: ClassList, Subject = special_class_seating_arrangement() ClassList = ClassList.split(' ') lst = [] for i in ClassList: temp = execute_sql( "SELECT * FROM Student WHERE ClassName = '{}'".format(i)) for student in temp: if Subject in student[3].split(' '): lst.append(student) lst = list(map(lambda x: x[0], lst)) if lst != []: string = '' for i in lst: string += i + ',' string = string[:-1] for i in lst: #To identify, whether students belong to class which seating arrangement is generated for #set._ClassLst to lst for students in that class and set the rest of the students' ClassLst to default = [] #set._ClassLst to lst for students in this class temp = execute_sql( "SELECT * FROM SeatingArrangement WHERE StudentName = '{}'". format(i))[0] StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo = temp new_classlst = SeatingArrangement(StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo) new_classlst.set_ClassLst(string) execute_sql(new_classlst.update_record()) #setting rest to default ClassLst = [] student_lst = execute_sql( "SELECT * FROM SeatingArrangement WHERE ClassLst != '{}'".format( string)) print(student_lst) student_lst = list(map(lambda x: x[0], student_lst)) for i in student_lst: temp = execute_sql( "SELECT * FROM SeatingArrangement WHERE StudentName = '{}'". format(i))[0] StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo = temp new_classlst = SeatingArrangement(StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo) new_classlst.set_ClassLst('') execute_sql(new_classlst.update_record()) return render_template('set_student_details.html', Students=lst, student_range=range(len(lst)), range=range(5), Subject=Subject) if request.method == 'POST': seatbygrades = request.form.get( 'SeatByGrades') # strong pupils will seat next to weak pupils rowno = request.form.get('RowNo') columnno = request.form.get('ColumnNo') print('set_student_details', seatbygrades, rowno, columnno) lst = execute_sql( "SELECT * FROM SeatingArrangement WHERE ClassLst != ''") for student in lst: StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo = student student = SeatingArrangement(StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo) if seatbygrades == 'Yes': student.set_SeatByGrades(seatbygrades) if rowno != 0: student.set_RowNo(rowno) student.set_ColumnNo(columnno) execute_sql(student.update_record()) lst = list(map(lambda x: x[0], lst)) #To get valid names for i in range(len(lst)): StudentName = lst[i] SeatInFront = request.form.get('SeatInFront{}'.format(i)) if SeatInFront != None: student = execute_sql( 'SELECT * FROM SeatingArrangement WHERE StudentName = "{}"' .format(StudentName))[0] StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo = student set_student = SeatingArrangement(StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo) set_student.set_SeatInFront(True) execute_sql(set_student.update_record()) StudentName1 = request.form.get('StudentName1{}'.format(i)) StudentName2 = request.form.get('StudentName2{}'.format(i)) if StudentName1 != '' and StudentName1 != None: print(StudentName1) print( execute_sql( 'SELECT * FROM SeatingArrangement WHERE StudentName = "{}"' .format(StudentName1))) student1 = execute_sql( 'SELECT * FROM SeatingArrangement WHERE StudentName = "{}"' .format(StudentName1))[0] StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo = student1 set_student = SeatingArrangement(StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo) set_student.set_CannotSeatNextTo(StudentName2) execute_sql(set_student.update_record()) student2 = execute_sql( 'SELECT * FROM SeatingArrangement WHERE StudentName = "{}"' .format(StudentName2))[0] StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo = student2 set_student = SeatingArrangement(StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo) set_student.set_CannotSeatNextTo(StudentName1) execute_sql(set_student.update_record()) else: return render_template('set_student_details.html', Students=lst, student_range=range(len(lst)), range=range(5), Subject=Subject)
def display_all_student_records(): classes = execute_sql("SELECT * FROM Class") students = execute_sql("SELECT * FROM Student") records = execute_sql("SELECT * FROM StudentRecords") subjects = execute_sql("SELECT * FROM Subject") for x in range( len(classes) - 1 ): #to sort classes in order, so that when displayed will be according to class. smallest = x for y in range(x + 1, len(classes)): if classes[y][0] < classes[smallest][0]: smallest = y if smallest != x: classes[smallest], classes[x] = classes[x], classes[smallest] for i in range( len(students) - 1 ): #to sort reg.no in order, so that when displayed will be according to reg.no. smallest = i for j in range(i + 1, len(students)): if students[j][1] < students[smallest][1]: smallest = j if smallest != i: students[smallest], students[i] = students[i], students[smallest] classes_oop = list(map(lambda a: Class(a[0], a[1]), classes)) students_oop = list( map(lambda b: Student(b[0], b[1], b[2], b[3], b[4], b[5]), students)) records_oop = list(map(lambda c: StudentRecords(c[0], c[1], c[2]), records)) subjects_oop = list(map(lambda d: Subject(d[0], d[1]), subjects)) # collating all grades and adding it as attribute to Students as AllSubjectGrades for student in students_oop: if student.get_AllSubjectGrades() == '': temp = '' index = 0 while len(temp.split(' ')) - 1 != len( student.get_StudentSubjectCombi().split(' ')): for record in records: if student.get_StudentName( ) == record[0] and student.get_StudentSubjectCombi().split( ' ')[index] == record[2]: temp += '{} '.format(record[1]) index += 1 temp = temp[:-1] student.set_AllSubjectGrades(temp) execute_sql(student.update_record()) # Adding to WeakSubjects and StrongSubjects for seating arrangement # done in display so that after editing new strong subjects will be added and some removed as well # same for weak subjects for student in students_oop: student_seating_arrangement = execute_sql( 'SELECT * FROM SeatingArrangement WHERE StudentName = "{}"'.format( student.get_StudentName()))[0] StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo = student_seating_arrangement student_seating_arrangement = SeatingArrangement( StudentName, CannotSeatNextTo, SeatInFront, WeakSubjects, StrongSubjects, ClassLst, SeatByGrades, RowNo, ColumnNo) StrongSubjects = '' WeakSubjects = '' for i in range(len(student.get_AllSubjectGrades().split(' '))): if student.get_AllSubjectGrades().split(' ')[i] < 'C': #'A', 'B' StrongSubjects += student.get_StudentSubjectCombi().split( ' ')[i] + ' ' elif student.get_AllSubjectGrades().split(' ')[i] > 'D': WeakSubjects += student.get_StudentSubjectCombi().split( ' ')[i] + ' ' student_seating_arrangement.set_StrongSubjects(StrongSubjects[:-1]) student_seating_arrangement.set_WeakSubjects(WeakSubjects[:-1]) execute_sql(student_seating_arrangement.update_record()) reset_seating_arrangement() return render_template("display_all_records.html", classes=classes_oop, students=students_oop, records=records_oop, subjects=subjects_oop)