def login(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = LogIn() loginFailed = False if form.validate_on_submit(): email = form.email.data.lower() password = form.password.data CheckTeacher = Teacher.query.filter_by(teacher_email=email).first() if CheckTeacher != None and CheckTeacher.teacher_email == email and CheckTeacher.check_password( password): g.teacherLoggedIn = True g.whichTeacher = CheckTeacher return redirect(url_for('index')) else: return render_template('tlogin.html', form=form, loginFailed=True, searchForm=searchForm) return render_template('tlogin.html', form=form, loginFailed=False, searchForm=searchForm)
def privacy(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) user = Settings.query.filter_by(student_id=current_user.id).first() displayRankCheck = user.display_rank displayStatCheck = user.display_stats form = PrivacyTab() if form.validate_on_submit(): if form.validate_on_submit(): user.display_rank = form.displayRank.data user.display_stats = form.displayStats.data displayRankCheck = user.display_rank displayStatCheck = user.display_stats db.session.add(user) db.session.commit() return render_template('privacy.html', form=form, fname=current_user.student_fname, lname=current_user.student_lname, searchForm=searchForm, displayRankCheck=displayRankCheck, displayStatCheck=displayStatCheck)
def deactivate_account(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = DeactivateTab() passwordMatchFailed = False if form.validate_on_submit(): updated_teacher = Teacher.query.filter_by( teacher_email=g.whichTeacher.teacher_email).first() print(updated_teacher.check_password(form.password.data)) if updated_teacher.check_password(form.password.data): db.session.delete(updated_teacher) db.session.commit() whichTeacher = False g.teacherLoggedIn = False return redirect(url_for('teachers.signout')) else: print('here') passwordMatchFailed = True return render_template('tdeactivate_account.html', form=form, teacherLoggedIn=g.teacherLoggedIn, fname=g.whichTeacher.teacher_fname, lname=g.whichTeacher.teacher_lname, passwordMatchFailed=passwordMatchFailed, searchForm=searchForm)
def signup(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = SignUp() signupFailed1 = False signupFailed2 = False signupFailed3 = False if form.validate_on_submit(): fname = form.fname.data lname = form.lname.data uname = form.uname.data email = form.email.data.lower() password1 = form.password1.data password2 = form.password2.data checkTeacherEmail = bool( Teacher.query.filter_by(teacher_email=email).first()) checkStudentEmail = bool( Student.query.filter_by(student_email=email).first()) checkTeacherUname = bool( Teacher.query.filter( func.lower(Teacher.teacher_uname) == func.lower( uname)).first()) checkStudentUname = bool( Student.query.filter( func.lower(Student.student_uname) == func.lower( uname)).first()) if checkTeacherUname or checkStudentUname: # Check if Uname is already taken return render_template('signup.html', form=form, signupFailed1=True, searchForm=searchForm) elif checkTeacherEmail or checkStudentEmail: # Check if Email is already registered return render_template('signup.html', form=form, signupFailed2=True, searchForm=searchForm) if password1 != '' and password1 == password2: new_student = Student(fname, lname, uname, email, password1, 0, 0, 0, 0, "", True, 4) db.session.add(new_student) db.session.commit() settings = Settings(new_student.id, True, True) db.session.add(settings) db.session.commit() return redirect(url_for('students.login')) else: return render_template('signup.html', form=form, signupFailed3=True, searchForm=searchForm) return render_template('signup.html', form=form, searchForm=searchForm)
def description(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) return render_template('description.html', teacherLoggedIn=g.teacherLoggedIn, searchForm=searchForm)
def payment_method(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) return render_template('payment_method.html', fname=current_user.student_fname, lname=current_user.student_lname, searchForm=searchForm)
def profile(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = ProfileTab() if form.validate_on_submit(): updated_teacher = Teacher.query.filter_by( teacher_email=g.whichTeacher.teacher_email).first() if form.uname.data != "": CheckStudent = bool( Student.query.filter( func.lower(Student.student_uname) == func.lower( form.uname.data)).first()) CheckTeacher = bool( Teacher.query.filter( and_( (func.lower(Teacher.teacher_uname) == func.lower( form.uname.data)), (func.lower(Teacher.teacher_uname) != func.lower( updated_teacher.teacher_uname)), )).first()) CheckUser = CheckTeacher or CheckStudent if not CheckUser: updated_teacher.teacher_uname = form.uname.data else: pass if form.fname.data != "": updated_teacher.teacher_fname = form.fname.data if form.lname.data != "": updated_teacher.teacher_lname = form.lname.data if form.bio.data != "": updated_teacher.teacher_bio = form.bio.data db.session.add(updated_teacher) db.session.commit() g.whichTeacher = updated_teacher form.uname.data = "" form.fname.data = "" form.lname.data = "" form.bio.data = "" return render_template('tprofile.html', form=form, teacherLoggedIn=g.teacherLoggedIn, fname=g.whichTeacher.teacher_fname.capitalize(), lname=g.whichTeacher.teacher_lname.capitalize(), uname=g.whichTeacher.teacher_uname, bio=g.whichTeacher.teacher_bio, searchForm=searchForm)
def payment_method(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) return render_template('tpayment_method.html', teacherLoggedIn=g.teacherLoggedIn, fname=g.whichTeacher.teacher_fname, lname=g.whichTeacher.teacher_lname, searchForm=searchForm)
def public_profile(uname): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) teacher = Teacher.query.filter_by(teacher_uname=uname).first() return render_template('tpublic_profile.html', teacher=teacher, searchForm=searchForm, teacherLoggedIn=g.teacherLoggedIn)
def profile(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = ProfileTab() if form.validate_on_submit(): user = Student.query.filter_by( student_email=current_user.student_email).first() if form.uname.data != "": CheckTeacher = bool( Teacher.query.filter( func.lower(Teacher.teacher_uname) == func.lower( form.uname.data)).first()) CheckStudent = bool( Student.query.filter( and_( (func.lower(Student.student_uname) == func.lower( form.uname.data)), (func.lower(Student.student_uname) != func.lower( current_user.student_uname)), )).first()) CheckUser = CheckTeacher or CheckStudent if not CheckUser: user.student_uname = form.uname.data else: pass if form.fname.data != "": user.student_fname = form.fname.data if form.lname.data != "": user.student_lname = form.lname.data if form.bio.data != "": user.student_bio = form.bio.data db.session.add(user) db.session.commit() form.fname.data = "" form.lname.data = "" form.bio.data = "" form.uname.data = "" return render_template('profile.html', form=form, fname=current_user.student_fname, lname=current_user.student_lname, searchForm=searchForm)
def display_leaderboard(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) # leaderboard contains all the students with score > 0 in descending order leaderboard = Student.query.order_by( Student.student_rank.asc()).filter(Student.student_score > 0) return render_template('leaderboard.html', leaderboard=leaderboard, searchForm=searchForm, teacherLoggedIn=g.teacherLoggedIn)
def public_profile(uname): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) student = Student.query.filter_by(student_uname=uname).first() # Calculating student's accuracy accuracy = 0 if student.student_attempted != 0: accuracy = (student.student_solved / student.student_attempted) * 100 return render_template('spublic_profile.html', student=student, searchForm=searchForm, accuracy=accuracy)
def searching(searched): searched = searched.lower() ref_teachers = None ref_assignments = None assignments = Assignments.query.filter( func.lower(Assignments.assignment_name) == searched).first() if assignments != None: ref_teachers = Assignments.query.filter_by( teacher_id=assignments.teacher_id) students = Student.query.filter( or_( (func.lower(Student.student_fname) == searched), (func.lower(Student.student_lname) == searched), (func.lower(Student.student_uname) == searched), )) teachers = Teacher.query.filter( or_( Teacher.teacher_fname.like(searched), Teacher.teacher_lname.like(searched), Teacher.teacher_uname.like(searched), )) courses = Courses.query.filter( func.lower(Courses.course_name) == searched).first() if courses != None: ref_assignments = Assignments.query.filter_by(course_id=courses.id) searchForm = Searching() if searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) return render_template('results.html', searchForm=searchForm, teachers=teachers, students=students, assignments=assignments, courses=courses, ref_teachers=ref_teachers, ref_assignments=ref_assignments, teacherLoggedIn=g.teacherLoggedIn)
def list_assignment(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) all_assignments = Assignments.query.filter_by(teacher_id=g.whichTeacher.id) teacher = Teacher.query.filter_by(id=g.whichTeacher.id).first() total_assignments = 0 for assignment in all_assignments: total_assignments += 1 return render_template('list_assignment.html', teacher=teacher, all_assignments=all_assignments, teacherLoggedIn=g.teacherLoggedIn, searchForm=searchForm, total_assignments=total_assignments)
def account(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = AccountTab() passwordChangeFailed = False passwordMatchFailed = False if form.validate_on_submit(): updated_teacher = Teacher.query.filter_by( teacher_email=g.whichTeacher.teacher_email).first() if not updated_teacher.check_password(form.password1.data): passwordChangeFailed = True return render_template('taccount.html', form=form, teacherLoggedIn=g.teacherLoggedIn, fname=g.whichTeacher.teacher_fname, lname=g.whichTeacher.teacher_lname, passwordChangeFailed=passwordChangeFailed, passwordMatchFailed=passwordMatchFailed, userEmail=g.whichTeacher.teacher_email, searchForm=searchForm) if form.password2.data == form.password3.data: updated_teacher.hash_password(form.password2.data) db.session.add(updated_teacher) db.session.commit() g.whichTeacher = updated_teacher else: passwordMatchFailed = True return render_template('taccount.html', form=form, teacherLoggedIn=g.teacherLoggedIn, fname=g.whichTeacher.teacher_fname, lname=g.whichTeacher.teacher_lname, passwordChangeFailed=passwordChangeFailed, passwordMatchFailed=passwordMatchFailed, userEmail=g.whichTeacher.teacher_email, searchForm=searchForm)
def categories(category): courses = None if int(category) == 1: assignments = Assignments.query.filter_by(course_id=1) elif int(category) == 2: assignments = Assignments.query.filter_by(course_id=2) elif int(category) == 5: assignments = Assignments.query.filter_by(course_id=5) elif int(category) == 6: assignments = Assignments.query.filter_by(course_id=6) elif int(category) == 8: assignments = Assignments.query.filter_by(course_id=8) elif int(category) == 9: assignments = Assignments.query.filter_by(course_id=9) elif int(category) == 10: assignments = Assignments.query.filter_by(course_id=10) elif int(category) == 11: assignments = Assignments.query.filter_by(course_id=11) elif int(category) == 12: assignments = Assignments.query.filter_by(course_id=12) elif int(category) == 13: assignments = Assignments.query.filter_by(course_id=13) else: assignments = None courses = Courses.query.all() #endif if assignments == None: assignments = Assignments.query.filter_by(course_id=int(category)) searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) return render_template('display_category.html', assignments=assignments, teacherLoggedIn=g.teacherLoggedIn, searchForm=searchForm, courses=courses)
def privacy(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = PrivacyTab() if form.validate_on_submit(): updated_teacher = Teacher.query.filter_by( teacher_email=g.whichTeacher.teacher_email).first() if form.validate_on_submit(): print(form.displayRank.data) print(form.displayStats.data) # additional code here return render_template('tprivacy.html', form=form, teacherLoggedIn=g.teacherLoggedIn, fname=g.whichTeacher.teacher_fname.capitalize(), lname=g.whichTeacher.teacher_lname.capitalize(), searchForm=searchForm)
def account(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = AccountTab() passwordChangeFailed = False passwordMatchFailed = False if form.validate_on_submit(): user = Student.query.filter_by( student_email=current_user.student_email).first() if not user.check_password(form.password1.data): passwordChangeFailed = True return render_template('account.html', form=form, fname=current_user.student_fname, lname=current_user.student_lname, passwordChangeFailed=passwordChangeFailed, passwordMatchFailed=passwordMatchFailed, searchForm=searchForm) if form.password2.data == form.password3.data: user.hash_password(form.password2.data) db.session.add(user) db.session.commit() else: passwordMatchFailed = True return render_template('account.html', form=form, fname=current_user.student_fname, lname=current_user.student_lname, passwordChangeFailed=passwordChangeFailed, passwordMatchFailed=passwordMatchFailed, searchForm=searchForm)
def login(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = LogIn() loginFailed = False if form.validate_on_submit(): email = form.email.data.lower() password = form.password.data CheckStudent = Student.query.filter_by(student_email=email).first() if CheckStudent != None and CheckStudent.student_email == email and CheckStudent.check_password( password): login_user(CheckStudent) next = request.args.get('next') if next == None or not next[0] == '/': next = url_for('index') # session['user'] = '******' return redirect(next) else: return render_template('login.html', form=form, loginFailed=True, searchForm=searchForm) return render_template('login.html', form=form, loginFailed=False, searchForm=searchForm)
def add_assignment(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) course = SelectField("Courses", [validators.Required()], choices=[(course.id, course.course_name) for course in Courses.query.all()]) setattr(AddAssignment, 'course', course) all_questions = [] questions = [] index = [] assignment_questions = 1 for x in range(1): #for no of questions field = StringField([validators.Required()]) setattr(AddAssignment, 'Question' + str(assignment_questions), field) questions.append('Question' + str(assignment_questions)) choice = 1 for y in range(4): setattr(AddAssignment, 'Choice' + str(assignment_questions) + str(choice), field) questions.append('Choice' + str(assignment_questions) + str(choice)) choice += 1 setattr(AddAssignment, 'Answer' + str(assignment_questions), field) questions.append('Answer' + str(assignment_questions)) index.append(str(assignment_questions)) assignment_questions += 1 all_questions.append(questions) questions = [] setattr(AddAssignment, 'submit', SubmitField('Add Assignment')) form = AddAssignment() if form.validate_on_submit(): assignment_name = form.assignment_name.data difficulty = form.difficulty.data course_id = form.course.data updated_course = Courses.query.filter_by(id=course_id).first() updated_course.no_of_assignments += 1 #incrementing the number of assignments for a course db.session.add(updated_course) db.session.commit() CheckAssignment = bool( Assignments.query.filter( func.lower(Assignments.assignment_name) == func.lower( assignment_name)).first()) if not CheckAssignment: new_assignment = Assignments(assignment_name, course_id, difficulty, 0, 0, 0, 1, g.whichTeacher.id) db.session.add(new_assignment) db.session.commit() question = [] for x in range(1, assignment_questions): question.append(new_assignment.id) question.append(x) question.append(getattr(form, 'Question' + str(x)).data) for y in range(1, 5): question.append( getattr(form, 'Choice' + str(x) + str(y)).data) question.append(getattr(form, 'Answer' + str(x)).data) new_question = Assignment_Data(question[0], question[1], question[2], question[3], question[4], question[5], question[6], question[7]) db.session.add(new_question) db.session.commit() question = [] else: pass return redirect(url_for('assignments.list_assignment')) return render_template('add_assignment.html', all_questions=all_questions, index=index, form=form, teacherLoggedIn=g.teacherLoggedIn, searchForm=searchForm)
def after_submit(passed, aid, temp): rank_changed = False points_earned = 0 old_rank = int(temp) # assignment = Assignments.query.filter_by() # checking how much points earned by student in this assignment solve = Solved_Assignemnts.query.filter( and_( Solved_Assignemnts.assignment_id.like(int(aid)), Solved_Assignemnts.student_id.like(current_user.id), )).first() points_earned = solve.points # --- Searching ---- searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = SubmitAssignment() # Check if student has already given his assignment review or not. aid = int(aid) review_already_given = Assignment_Review.query.filter( and_( Assignment_Review.assignment_id.like(aid), Assignment_Review.student_id.like(current_user.id), )).first() # the Entire "Giving Assignment, Teacher rating and reviews" coding. if form.validate_on_submit(): #if this happens, then this is the first time, student is rating and giving review AND student must have given both rating and review to the solved assignment(because validator required at both fields). # get all reviews of assignment whose assignment_id = aid. last_review = Assignment_Review.query.filter_by( assignment_id=aid).all() if last_review != []: # if not empty print("here") review_no = last_review[-1].review_id + 1 # add 1 to last review_id else: review_no = 1 #endif # Done with Assignment_Review Table assignment_review = Assignment_Review(review_no, aid, current_user.id, form.rating.data, form.review.data) db.session.add(assignment_review) # Now updating Assignment assignment_rating,assignment_no_of_reviews and assignment_no_of_ratings. assignment = Assignments.query.filter_by(id=aid).first() assignment.assignment_no_of_reviews += 1 if assignment.assignment_no_of_ratings == 0: assignment.assignment_rating = form.rating.data else: assignment.assignment_rating = ( (assignment.assignment_rating * assignment.assignment_no_of_ratings) + float(form.rating.data) ) / (assignment.assignment_no_of_ratings + 1) #endif assignment.assignment_no_of_ratings += 1 db.session.add(assignment) db.session.commit() # Now updating Teacher teacher_rating and teacher_no_Of_reviews. teacher = Teacher.query.filter_by(id=assignment.teacher_id).first() teacher_assignments = Assignments.query.filter_by( teacher_id=teacher.id) count = 0 avg_teacher_rating = 0 for assignment in teacher_assignments: if assignment.assignment_rating > 0: count += 1 avg_teacher_rating += assignment.assignment_rating #endfor teacher.teacher_rating = avg_teacher_rating / count teacher.teacher_no_Of_reviews += 1 db.session.add(teacher) db.session.commit() return redirect(url_for('index')) #endif return render_template('after_submit.html', form=form, searchForm=searchForm, passed=passed, rank_changed=rank_changed, old_rank=old_rank, points_earned=points_earned, review_already_given=review_already_given)
def solve_assignment(aid): # ----------Searching Section------------ searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) questions = Assignment_Data.query.filter_by(assignment_id=aid) #-----------Making a form------------------ no_of_question = 1 field_list = [] for record in questions: field = RadioField(choices=[('1', record.choice1), ( '2', record.choice2), ('3', record.choice3), ('4', record.choice4)]) setattr(SolveAssignment, 'radioField' + str(no_of_question), field) # i.e: choice1 = RadioField(choices=[('1' , record[3]) , ('2' , record[4]), ('3' , record[5]), ('4' , record[6]) ]) field_list.append('radioField' + str(no_of_question)) no_of_question = no_of_question + 1 setattr(SolveAssignment, 'submit', SubmitField("Submit")) #----- Checking Assignment Difficulty and Points ------------ if questions[0].assignment.difficulty == 'Expert': total_points = 5 * (no_of_question - 1) points = 5 elif questions[0].assignment.difficulty == 'Intermediate': total_points = 3 * (no_of_question - 1) points = 3 else: total_points = 1 * (no_of_question - 1) points = 1 form = SolveAssignment() print(getattr(form, field_list[0]).data) # The Entire SOLVE ASSIGNMENT LOGIC with maintainence of Leaderboard starts from here... if form.validate_on_submit(): earned_points = 0 passed = False student = None # When student press submit: student_attempted = student_attempted + 1 ; student = Student.query.filter_by(id=current_user.id).first() if student.student_attempted == 0: old_rank_points = 0 else: old_rank_points = (student.student_score * student.student_solved ) / student.student_attempted student.student_attempted += 1 # Calculating student earned points for this assignment count = -1 for record in questions: count = count + 1 if getattr(form, field_list[count]).data == record.answer: getattr(form, field_list[count]).data = '' earned_points += points #checking if student has already solved this assignment or not. assignment_already_solved = Solved_Assignemnts.query.filter( and_( Solved_Assignemnts.assignment_id.like(aid), Solved_Assignemnts.student_id.like(current_user.id), )).first() # if student has already solved this assignment before if assignment_already_solved != None: passed = True # then Check if student newScore is greated than his previousScore in this assignment; else score unchanged. if earned_points > assignment_already_solved.points: #if it is greater then : remove his previoseScore from his total score.. student.student_score = student.student_score - assignment_already_solved.points # and add this new score to his total score student.student_score = student.student_score + earned_points assignment_already_solved.points = earned_points db.session.add(assignment_already_solved) elif assignment_already_solved.points == total_points: student.student_attempted -= 1 #endif # if this is student first attempt.. else: # then check whether student has passed or failed if (questions[0].assignment.difficulty == 'Expert') and (earned_points >= (total_points * 0.70)): passed = True elif (questions[0].assignment.difficulty == 'Intermediate') and (earned_points >= (total_points * 0.60)): passed = True elif (questions[0].assignment.difficulty == 'Beginner') and (earned_points >= (total_points * 0.50)): passed = True else: passed = False #endif # if passed if passed == True: #then student_solved ++ and student_score = student_score + earned_points student.student_solved += 1 student.student_score += earned_points #endif solved = Solved_Assignemnts(student.id, int(aid), earned_points) db.session.add(solved) #endif # student record is updated db.session.add(student) db.session.commit() #Updating the Leaderboard #======================== student = Student.query.filter_by(id=current_user.id).first() #student_new_position new_rank_points = (student.student_score * student.student_solved) / student.student_attempted #finding all the students who have attempted atleast one assignment, sorted by thier rank in asc order. all_students = Student.query.order_by( Student.student_rank.asc()).filter(Student.student_attempted > 0) # counting no of students in all_students no_of_students = 0 for studs in all_students: no_of_students += 1 # check if there is only one student and his rank is 0 and he has passed the assignment. rank_increased = False rank_decreased = False temp = 1 if no_of_students == 1: for stud in all_students: stud.student_rank = 1 db.session.add(stud) #endfor # if more than one student (here there will always be one student with rank = 1st) elif no_of_students > 1: for stud in all_students: print(f"stud.id: {stud.id}") if stud.id == student.id: if stud.student_rank == 0: student.student_rank = no_of_students if old_rank_points > new_rank_points: print("continue") continue break #endif position = (stud.student_score * stud.student_solved) / stud.student_attempted if new_rank_points > position and old_rank_points <= new_rank_points: print("in first if") temp = student.student_rank new_rank = int(stud.student_rank) rank_increased = True break elif old_rank_points > new_rank_points and position > new_rank_points: print("in second if") new_rank = stud.student_rank temp = student.student_rank rank_decreased = True #endif #endfor #endif if rank_increased == True: for stud in all_students: if stud.student_rank == temp: break #endif if stud.student_rank >= new_rank: stud.student_rank += 1 db.session.add(stud) #endif #endfor student.student_rank = new_rank db.session.add(student) elif rank_decreased == True: for stud in all_students: if stud.student_rank == new_rank + 1: break #endif if stud.student_rank > student.student_rank: stud.student_rank -= 1 db.session.add(stud) #endif #endfor student.student_rank = new_rank db.session.add(student) #endif db.session.commit() return redirect( url_for('assignments.after_submit', passed=passed, aid=aid, temp=temp)) #endif return render_template('solve_assignment.html', form=form, questions=questions, total_points=total_points, points=points, field_list=field_list, searchForm=searchForm)
def delete_assignment(aid): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) assignment_data = Assignment_Data.query.filter_by(assignment_id=aid).all() no_of_question = 0 for question in assignment_data: no_of_question += 1 if assignment_data[0].assignment.difficulty == 'Expert': total_points = 5 * (no_of_question) points = 5 elif assignment_data[0].assignment.difficulty == 'Intermediate': total_points = 3 * (no_of_question) points = 3 else: total_points = 1 * (no_of_question) points = 1 form = DeleteAssignment() #try with multiple questions if form.validate_on_submit(): assignment = Assignments.query.filter_by(id=aid).first() updated_course = Courses.query.filter_by( id=assignment.course_id).first() if updated_course.no_of_assignments == 0: updated_course.no_of_assignments = 0 else: updated_course.no_of_assignments -= 1 #incrementing the number of assignments for a course db.session.add(updated_course) db.session.commit() assignment = Assignments.query.filter_by(id=aid).first() db.session.delete(assignment) db.session.commit() # Now updating Teacher teacher_rating and teacher_no_Of_reviews. teacher = Teacher.query.filter_by(id=g.whichTeacher.id).first() teacher_assignments = Assignments.query.filter_by( teacher_id=teacher.id).all() count = 0 avg_teacher_rating = 0 for assignment in teacher_assignments: if assignment.assignment_rating > 0: count += 1 avg_teacher_rating += assignment.assignment_rating #endif #endfor if count == 0: teacher.teacher_rating = 0 teacher.teacher_no_Of_reviews = 0 else: teacher.teacher_rating = avg_teacher_rating / count teacher.teacher_no_Of_reviews -= assignment.assignment_no_of_reviews #endif db.session.add(teacher) db.session.commit() return redirect(url_for('assignments.list_assignment')) return render_template('delete_assignment.html', form=form, teacherLoggedIn=g.teacherLoggedIn, assignment_data=assignment_data, searchForm=searchForm, total_points=total_points, points=points)
def index(): all_assignments = [] recomended_assignments_x = [] recomended_assignments_y = [] recomended_assignments_z = [] top_pick = None # Finding his preferences if current_user.is_authenticated: x = [0, -sys.maxsize] y = [0, -sys.maxsize] z = [0, -sys.maxsize] # Displaying Random Assignments assignments = Assignments.query.order_by( Assignments.assignment_rating.desc()).filter( and_( Assignments.course_id != x[0], Assignments.course_id != y[0], Assignments.course_id != z[0], )) for assignment in assignments: check = Solved_Assignemnts.query.filter( and_( Solved_Assignemnts.assignment_id.like(assignment.id), Solved_Assignemnts.student_id.like(current_user.id), )).first() if check == None: all_assignments.append(assignment) if len(all_assignments) == 8: break #endfor preffered_courses = [] count_assignments = 0 for assignment in Solved_Assignemnts.query.filter_by( student_id=current_user.id): preffered_courses.append(assignment.assignment.course.id) count_assignments += 1 #endfor if count_assignments > 5: Hash = dict() for i in range(len(preffered_courses)): if preffered_courses[i] in Hash.keys(): Hash[preffered_courses[i]] += 1 else: Hash[preffered_courses[i]] = 1 #endif #endfor for cid in Hash: if Hash[cid] > 1 and Hash[cid] > x[1]: z = copy.deepcopy(y) y = copy.deepcopy(x) x[0] = cid x[1] = Hash[cid] elif Hash[cid] > 1 and Hash[cid] > y[1]: z = copy.deepcopy(y) y[0] = cid y[1] = Hash[cid] elif Hash[cid] > 1 and Hash[cid] > z[1]: z[0] = cid z[1] = Hash[cid] #endfor if x[0] == 0: x = list(Hash.items())[-1] y = list(Hash.items())[-2] z = list(Hash.items())[-3] elif y[0] == 0: del Hash[x[0]] y = list(Hash.items())[-1] z = list(Hash.items())[-2] elif z[0] == 0: del Hash[x[0]] del Hash[y[0]] z = list(Hash.items())[-1] #endif #Student Course-wise Preferences for assignment in Assignments.query.order_by( Assignments.assignment_rating.desc()).filter_by( course_id=x[0]): check = Solved_Assignemnts.query.filter( and_( Solved_Assignemnts.assignment_id.like(assignment.id), Solved_Assignemnts.student_id.like(current_user.id), )).first() if check == None: recomended_assignments_x.append(assignment) if len(recomended_assignments_x) == 4: break for assignment in Assignments.query.order_by( Assignments.assignment_rating.desc()).filter_by( course_id=y[0]): check = Solved_Assignemnts.query.filter( and_( Solved_Assignemnts.assignment_id.like(assignment.id), Solved_Assignemnts.student_id.like(current_user.id), )).first() if check == None: recomended_assignments_y.append(assignment) if len(recomended_assignments_y) == 4: break for assignment in Assignments.query.order_by( Assignments.assignment_rating.desc()).filter_by( course_id=z[0]): check = Solved_Assignemnts.query.filter( and_( Solved_Assignemnts.assignment_id.like(assignment.id), Solved_Assignemnts.student_id.like(current_user.id), )).first() if check == None: recomended_assignments_z.append(assignment) if len(recomended_assignments_z) == 4: break # finding the TOP PICK for assignment in Assignments.query.filter_by( course_id=x[0]).order_by( Assignments.assignment_rating.desc(), Assignments.assignment_no_of_reviews.desc()): check = Solved_Assignemnts.query.filter( and_( Solved_Assignemnts.assignment_id.like(assignment.id), Solved_Assignemnts.student_id.like(current_user.id), )).first() if check == None and assignment.assignment_rating >= 4.0: top_pick = assignment break #endif #endfor if top_pick != None: for assignment in Assignments.query.filter_by( course_id=y[0]).order_by( Assignments.assignment_rating.desc(), Assignments.assignment_no_of_reviews.desc()): check = Solved_Assignemnts.query.filter( and_( Solved_Assignemnts.assignment_id.like( assignment.id), Solved_Assignemnts.student_id.like( current_user.id), )).first() if check == None: if top_pick.assignment_rating < assignment.assignment_rating: top_pick = assignment elif top_pick.assignment_rating == assignment.assignment_rating: if top_pick.assignment_no_of_reviews < assignment.assignment_no_of_reviews: top_pick = assignment break #endif #endfor for assignment in Assignments.query.filter_by( course_id=z[0]).order_by( Assignments.assignment_rating.desc(), Assignments.assignment_no_of_reviews.desc()): check = Solved_Assignemnts.query.filter( and_( Solved_Assignemnts.assignment_id.like( assignment.id), Solved_Assignemnts.student_id.like( current_user.id), )).first() if check == None: if top_pick.assignment_rating < assignment.assignment_rating: top_pick = assignment elif top_pick.assignment_rating == assignment.assignment_rating: if top_pick.assignment_no_of_reviews < assignment.assignment_no_of_reviews: top_pick = assignment break #endif #endfor #endif else: all_assignments = Assignments.query.order_by( Assignments.assignment_rating.desc()).limit(16) #endif searchForm = Searching() if searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) #endif return render_template('home.html', teacherLoggedIn=g.teacherLoggedIn, all_assignments=all_assignments, recomended_assignments_x=recomended_assignments_x, recomended_assignments_y=recomended_assignments_y, recomended_assignments_z=recomended_assignments_z, top_pick=top_pick, searchForm=searchForm)
def deactivate_account(): searchForm = Searching() if searchForm.searched.data != '' and searchForm.validate_on_submit(): return redirect( url_for('search.searching', searched=searchForm.searched.data)) form = DeactivateTab() passwordMatchFailed = False if form.validate_on_submit(): user = Student.query.filter_by( student_email=current_user.student_email).first() if user.check_password(form.password.data): for q in Students_in_Classroom.query.filter_by( student_id=current_user.id).all(): db.session.delete(q) for q in Solved_Classroom_Assignment.query.filter_by( student_id=current_user.id).all(): db.session.delete(q) for q in Solved_Assignemnts.query.filter_by( student_id=current_user.id).all(): db.session.delete(q) for q in Assignment_Review.query.filter_by( student_id=current_user.id).all(): # Now updating Assignment assignment_rating,assignment_no_of_reviews and assignment_no_of_ratings. assignment = Assignments.query.filter_by( id=q.assignment_id).first() assignment.assignment_no_of_reviews -= 1 if assignment.assignment_no_of_ratings == 1: assignment.assignment_rating = 0 else: assignment.assignment_rating = ( (assignment.assignment_rating * assignment.assignment_no_of_ratings) - float(q.assignment_rating)) / ( assignment.assignment_no_of_ratings - 1) #endif assignment.assignment_no_of_ratings -= 1 db.session.add(assignment) # Now updating Teacher teacher_rating and teacher_no_Of_reviews. teacher = Teacher.query.filter_by( id=q.assignment.teacher_id).first() teacher_assignments = Assignments.query.filter_by( teacher_id=teacher.id).all() db.session.delete(q) db.session.commit() count = 0 avg_teacher_rating = 0 for assignment in teacher_assignments: if assignment.assignment_rating > 0: count += 1 avg_teacher_rating += assignment.assignment_rating #endif #endfor if count == 0: teacher.teacher_rating = 0 teacher.teacher_no_Of_reviews = 0 else: teacher.teacher_rating = avg_teacher_rating / count teacher.teacher_no_Of_reviews -= 1 #endif db.session.add(teacher) db.session.commit() #endfor settings = Settings.query.filter_by( student_id=current_user.id).first() db.session.delete(settings) db.session.delete(user) db.session.commit() return redirect(url_for('students.signout')) else: passwordMatchFailed = True return render_template('deactivate_account.html', form=form, fname=current_user.student_fname, lname=current_user.student_lname, passwordMatchFailed=passwordMatchFailed, searchForm=searchForm)