def read_file(file_name): with open(file_name) as f: line = f.readline() line = f.readline() while line: lst = line.split(';') ClassName = lst[0] TotalStudents = lst[1] StudentRegNo = lst[2] StudentName = lst[3] StudentGender = lst[4] StudentSubjectCombi = lst[5] SubjectName = lst[6] Description = lst[7] SubjectGrade = lst[8][:-1] #because of "\n" at the back c1 = Class(ClassName, TotalStudents) st1 = Student(StudentName, StudentRegNo, ClassName, StudentSubjectCombi, StudentGender, AllSubjectGrades = '') sr1 = StudentRecords(StudentName, SubjectGrade, SubjectName) sb1 = Subject(SubjectName, Description) sa1 = SeatingArrangement(StudentName, CannotSeatNextTo= '', SeatInFront= False,WeakSubjects='',StrongSubjects='', ClassLst = '', SeatByGrades= '' , RowNo = 0, ColumnNo=0) execute_sql(c1.create_new_record()) execute_sql(st1.create_new_record()) execute_sql(sr1.create_new_record()) execute_sql(sb1.create_new_record()) execute_sql(sa1.create_new_record()) line = f.readline() #f.close() #read_file('result_data.csv')
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 create_student_record(): if request.method == 'POST': #Create Class object new_class = Class(request.form.get('ClassName'), '') execute_sql(new_class.create_new_record()) #Create Student object new_student_details = Student( request.form.get('StudentName').strip(), request.form.get('StudentRegNo').strip(), request.form.get('ClassName').strip(), request.form.get('StudentSubjectCombi').strip(), request.form.get('StudentGender').strip(), request.form.get('AllSubjectGrades').strip()) execute_sql(new_student_details.create_new_record()) #Create StudentRecords object StudentSubjectCombi = request.form.get( 'StudentSubjectCombi').strip().split(' ') AllSubjectGrades = request.form.get('AllSubjectGrades').strip().split( ' ') for i in range(len(StudentSubjectCombi)): new_student_record = StudentRecords( request.form.get('StudentName').strip(), AllSubjectGrades[i], StudentSubjectCombi[i]) execute_sql(new_student_record.create_new_record()) subject_lst = execute_sql('SELECT * FROM Subject') subject_lst = list(map(lambda tuple: tuple[0], subject_lst)) for subject in StudentSubjectCombi: if subject not in subject_lst: new_subject = Subject(subject, subject_description(subject)) execute_sql(new_subject.create_new_record()) #Create Seating Arrangement object new_seating_arrangement = SeatingArrangement( request.form.get('StudentName'), CannotSeatNextTo='', SeatInFront=False, WeakSubjects='', StrongSubjects='', ClassLst='', SeatByGrades='', RowNo=0, ColumnNo=0) execute_sql(new_seating_arrangement.create_new_record()) return redirect(url_for('display_all_student_records')) else: return render_template('create_student_record.html')
def create_table(): execute_sql(Class.create_table()) execute_sql(Student.create_table()) execute_sql(StudentRecords.create_table()) execute_sql(Subject.create_table()) execute_sql(SeatingArrangement.create_table()) execute_sql(User.create_table()) execute_sql(CurrentUser.create_table()) execute_sql(SavedSeatArr.create_table()) execute_sql(Comment.create_table()) execute_sql(UserInfo.create_table())
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)
def read_file(file_name): with open(file_name) as f: line = f.readline() line = f.readline() while line: lst = line.split(';') ClassName = lst[0] TotalStudents = lst[1] StudentRegNo = lst[2] StudentName = lst[3] StudentGender = lst[4] StudentSubjectCombi = lst[5] SubjectName = lst[6] Description = lst[7] SubjectGrade = lst[8] SeatArrName = lst[9] CommentIDs = lst[10] CommentID = lst[11] CommentText = lst[12] CommentDatetime = lst[13][:-1] #because of "\n" at the back c1 = Class(ClassName, TotalStudents) st1 = Student(StudentName, StudentRegNo, ClassName, StudentSubjectCombi, StudentGender, AllSubjectGrades='') sr1 = StudentRecords(StudentName, SubjectGrade, SubjectName) sb1 = Subject(SubjectName, Description) sa1 = SeatingArrangement(StudentName, CannotSeatNextTo='', SeatInFront=False, WeakSubjects='', StrongSubjects='', ClassLst='', SeatByGrades='', RowNo=0, ColumnNo=0) user1 = User(UserName='******', Password='') currentuser1 = CurrentUser(UserName='******') comment = Comment(SeatArrName, int(CommentID), CommentText, CommentDatetime, UserName="******") ssr1 = SavedSeatArr(UserName='******', SeatArrName=SeatArrName, SeatArrSeq="", RowNo=0, ColumnNo=0, CommentIDs=CommentIDs) #TODO Username does not have to be class specific as CP will add in student info by themselves, most important is to do a back-end validation to check if username is taken alr or not #TODO set user to an example user first, by right upon creating an account on login, user info will be created and added into User table #TODO set current user to nth by default until someone logins, then current user will become that username, must always reset current user execute_sql(c1.create_new_record()) execute_sql(st1.create_new_record()) execute_sql(sr1.create_new_record()) execute_sql(sb1.create_new_record()) execute_sql(sa1.create_new_record()) execute_sql(user1.create_new_record()) execute_sql(currentuser1.create_new_record()) execute_sql(comment.create_new_record()) execute_sql(ssr1.create_new_record()) line = f.readline() f.close()
def create_table(): execute_sql(Class.create_table()) execute_sql(Student.create_table()) execute_sql(StudentRecords.create_table()) execute_sql(Subject.create_table()) execute_sql(SeatingArrangement.create_table())
def create_student_record(): if request.method == 'POST': error = False if request.form['ClassName'].strip() == "": error = "Invalid Class, Please write something for Class..." elif len(request.form['ClassName'].strip()) != 2: error = "Invalid Class, Class should consist of one number and one letter (e.g. 6M)" elif len(request.form['ClassName'].strip()) == 2: if not (request.form['ClassName'].strip()[0].isdigit() and request.form['ClassName'][1].strip().isalpha() and ord(request.form['ClassName'][1].strip()) >= 65 and ord(request.form['ClassName'][1].strip()) <= 90 ): error = "Invalid Class, Class should consist of one number and one capital letter (e.g. 6M)" return render_template('create_student_record.html', SubjectAbbrev=SubjectAbbrev, SubjectFull=SubjectFull, error=error) existing_students = execute_sql("SELECT * FROM Student WHERE ClassName = '{}'".format(request.form['ClassName'].strip())) existing_regno = list(map(lambda tuple: tuple[1], existing_students)) if request.form['StudentName'].strip() == "": error = "Invalid Name, Please write something for Name..." return render_template('create_student_record.html', SubjectAbbrev=SubjectAbbrev, SubjectFull=SubjectFull, error=error) elif hasNumbers(request.form['StudentName']): error = "Invalid Name, Name should not contain numbers" return render_template('create_student_record.html', SubjectAbbrev=SubjectAbbrev, SubjectFull=SubjectFull, error=error) elif request.form['StudentRegNo'].strip() == "": error = "Invalid Register No., Please write something for Register No..." return render_template('create_student_record.html', SubjectAbbrev=SubjectAbbrev, SubjectFull=SubjectFull, error=error) elif not request.form['StudentRegNo'].strip().isdigit(): error = "Invalid Register No., Register No. should only consist of numbers" return render_template('create_student_record.html', SubjectAbbrev=SubjectAbbrev, SubjectFull=SubjectFull, error=error) if request.form['StudentRegNo'].strip().isdigit(): if int(request.form['StudentRegNo'].strip()) in existing_regno: error = "Register No. has already been used, please key in another register no." return render_template('create_student_record.html', SubjectAbbrev=SubjectAbbrev, SubjectFull=SubjectFull, error=error) if request.form['StudentGender'].strip() == "": error = "Invalid Gender, Please write something for Gender..." elif request.form['StudentGender'].strip() not in ["F","M"]: error = "Invalid Gender, Gender should only be M or F" elif request.form['StudentSubjectCombi'].strip() == "": error = "Invalid Subject Combination, Please write something for Subject Combination..." for SubCom in list(request.form['StudentSubjectCombi'].split(' ')): if SubCom[:3:] not in SubjectAbbrev: error = 'Invalid Subject Combination, An impossible subject was entered' for SubGrade in (list(filter(lambda x: x != ' ', request.form['AllSubjectGrades'].strip()))): if SubGrade not in ['A', 'B', 'C', 'D', 'E', 'S', 'U']: print(SubGrade, 'Subgrade') error = 'Invalid Grades, An impossible grade was entered' if request.form['AllSubjectGrades'].strip() == "": error = "Invalid Grades, Please write something for Grades..." elif len(request.form['StudentSubjectCombi'].strip().split(" ")) != len(request.form['AllSubjectGrades'].strip().split(" ")): error = "Number of grades should correspond to number of subjects keyed in" if error != False: return render_template('create_student_record.html', SubjectAbbrev=SubjectAbbrev, SubjectFull=SubjectFull, error=error) #Create Class object new_class = Class(request.form.get('ClassName').strip(),'') execute_sql(new_class.create_new_record()) #Create Student object new_student_details = Student(request.form.get('StudentName').strip(), request.form.get('StudentRegNo').strip(), request.form.get('ClassName').strip(),request.form.get('StudentSubjectCombi').strip(), request.form.get('StudentGender').strip(), request.form.get('AllSubjectGrades').strip()) execute_sql(new_student_details.create_new_record()) #Create StudentRecords object StudentSubjectCombi = request.form.get('StudentSubjectCombi').strip().split(' ') AllSubjectGrades = request.form.get('AllSubjectGrades').strip().split(' ') for i in range(len(StudentSubjectCombi)): new_student_record = StudentRecords(request.form.get('StudentName').strip(), AllSubjectGrades[i], StudentSubjectCombi[i]) execute_sql(new_student_record.create_new_record()) subject_lst = execute_sql('SELECT * FROM Subject') subject_lst = list(map(lambda tuple: tuple[0],subject_lst)) for subject in StudentSubjectCombi: if subject not in subject_lst: new_subject = Subject(subject, subject_description(subject)) execute_sql(new_subject.create_new_record()) #Create Seating Arrangement object new_seating_arrangement = SeatingArrangement(request.form.get('StudentName').strip(), CannotSeatNextTo = '', SeatInFront = False, WeakSubjects = '', StrongSubjects = '', ClassLst= '', SeatByGrades='', RowNo=0, ColumnNo=0) execute_sql(new_seating_arrangement.create_new_record()) return redirect(url_for('display_all_student_records')) else: return render_template('create_student_record.html', SubjectAbbrev=SubjectAbbrev, SubjectFull=SubjectFull)