def createClassroom(): form = forms.CreateClassroom(request.form) # Dynamic drop-down menu to choose the available assigments for professor assigments = assigmentsTupleList(session['id_professor']) form.assigment.choices = assigments if (request.method == 'POST' and form.validate()): # Form information about the new classroom rows = form['rows'].data columns = form['columns'].data room = form['room'].data selectedAssigmentID = form['assigment'].data # Classroom objects initialization assigmentObj = DBUtils.getAssigment( selectedAssigmentID) # Object assigment currentProfessor = DBUtils.getProfessor( su.get_professor_id(session)) # Object professor classroom = dataStructures.Classroom((rows, columns), currentProfessor, assigmentObj, room) # Object ClassRoom runningClasses[ classroom. id] = classroom # Add to runningClasses (dict) with id to be able to track different courses su.set_class_id(session, classroom.id) # Add to professor's session # Messages flash( 'Classroom created for assigment id = ' + str(selectedAssigmentID), 'success') return redirect(url_for('professor.classroom')) return render_template('createClassroom.html', form=form)
def registerGeneral(): formStudent = RegisterFormStudent(request.form) formProfessor = RegisterFormProfessor(request.form) if (request.method == 'POST'): if request.form['btn'] == 'Submit student' and formStudent.validate(): # flash('student', 'success') DBUtils.putStudent( formStudent.name.data, formStudent.lastName.data, formStudent.lastNameSecond.data, formStudent.nia.data, formStudent.email.data, sha256_crypt.encrypt(str(formStudent.password.data))) flash('You are now registerd as student and can log in', 'success') return redirect(url_for('home.login')) elif request.form[ 'btn'] == 'Submit professor' and formProfessor.validate(): # flash('Professor', 'success') DBUtils.putProfessor( formProfessor.name.data, formProfessor.lastName.data, formProfessor.lastNameSecond.data, formProfessor.email.data, sha256_crypt.encrypt(str(formProfessor.password.data))) flash('You are now registerd as professor and can log in', 'success') return redirect(url_for('home.login')) return render_template('register.html', formStudent=formStudent, formProfessor=formProfessor)
def addSections(): form = forms.AddSectionForm(request.form) if (request.method == 'POST' and request.form['btn'] == 'cancel'): # Not needed to validate the form return redirect(url_for('professor.dashboard')) elif (request.method == 'POST' and form.validate()): if request.form['btn'] == 'add' or request.form['btn'] == 'addFinish': su.increment_orderInAssigment(session) # Update order id_assigment = su.get_assigment_id(session) order_in_assigment = su.get_orderInAssigment(session) name = form['name'].data text = form['text'].data flash('Section saved', 'success') DBUtils.putSection(id_assigment, order_in_assigment, name, text) # Add table row if request.form['btn'] == 'add': return redirect(url_for('professor.addSections')) elif request.form['btn'] == 'addFinish': flash('Saved', 'success') return redirect(url_for('professor.dashboard')) else: flash('Something uncontrolled append', 'danger') return redirect(url_for('professor.dashboard')) else: flash('Something uncontrolled happened', 'danger') return redirect(url_for('professor.dashboard')) ### Fetch info to render ### order_in_assigment = su.get_orderInAssigment( session) + 1 # Do not update here because user can reload the page sections = DBUtils.getSections( su.get_assigment_id(session)) # Get sections tmpAssigment = dataStructures.Assigment(sections) # Create a temporal dicSections = tmpAssigment.sections_dict( ) # Create dict from temporal to render later return render_template('addSections.html', form=form, order_in_assigment=order_in_assigment, sections=dicSections)
def add_Answer(self, answerText, resolver, postToDB=True): from classOn import DBUtils self._answerText = answerText db_id = -1 if postToDB: db_id = DBUtils.answerDoubt(self, answerText, resolver) answ = DoubtAnswer(db_id, answerText) self.answers.append(answ)
def handle_answerPost(doubtId, answer): # $$$$ Professors are not supported to solve doubts currentClass = runningClasses[su.get_class_id(session)] solvedDoubt = currentClass.getDoubt(doubtId) # We are using variables in memory solver = DBUtils.getStudentBy_id(su.get_student_id(session)) # Student solver room = su.get_classRoom(session) # Room to send the response # Update currentClass.doubts and db solvedDoubt.add_Answer(answer, solver) # Do not use DBUtils. answerJson = '{"doubtid":' + str(doubtId) + ',"text":"' + answer + '"}' socketio.emit('new_answer', answerJson, room=room)
def selectPlace(): # form = forms.PlaceSelectionForm(request.form) selectedRunningClass = runningClasses[su.get_class_id(session)] rows = selectedRunningClass.classSize[0] cols = selectedRunningClass.classSize[1] takenPlaces = selectedRunningClass.filledPlaces() if (request.method == 'POST'): # Get running classroom instance # Form information placeStr = request.form['place'] placeList = placeStr.split('_') row = int(placeList[0]) column = int(placeList[1]) # Form info # row = form['row'].data # column = form['column'].data # Check if is out of bounds if (row <= rows and column <= cols): # Inside of bounds. The student can take the seat. student_id = su.get_student_id(session) student = DBUtils.getStudentBy_id(student_id) # Generate student groupIsIn = selectedRunningClass.addStudentToPlace( student, (row, column)) # Add to selected class su.set_grupo_id(session, groupIsIn.groupID) # Store id as reference flash('Place selected', 'success') assigmentID = selectedRunningClass.assigment.db_id # Current assigment id groupIsIn.assigmentProgress = su.get_page( session) # Last visited page startPage = su.get_page(session) # Last visited page ''' Socket.io notification''' handle_joinGroup(groupIsIn) # Render de selected assigment at the start page return redirect( url_for('assigment.assigmentByID', id=assigmentID, page=startPage)) # Go to assigment else: flash('Place out of bounds', 'danger') return redirect(url_for('student.selectPlace')) return render_template('selectPlace.html', rows=rows, columns=cols, takenPlaces=takenPlaces)
def assigmentByID(id, page): page_no = int(page) # Conversion to int assigment = DBUtils.getAssigment( id) # Get requested assigment (db_id -> id) currentClass = runningClasses[su.get_class_id(session)] global class_id_aux class_id_aux = su.get_class_id(session) print('class id aux 1: ' + str(class_id_aux)) global group_id_aux group_id_aux = su.get_grupo_id(session) print('group_id_aux 1: ' + str(group_id_aux)) currentGroup = currentClass.studentGroups[su.get_grupo_id(session)] form = forms.PostDoubtForm(request.form) if assigment is None: # Doesn't exist an assigment with the requested id flash('Doesn\'t exists an assigment with id: ' + str(id), 'danger') else: # If zero last one visited in session if page_no == 0: page_no = su.get_page(session) # Render last visited else: su.set_page(session, page_no) # Update session currentGroup.assigmentProgress = page_no # Update group obj totalSections = len(assigment.sections) progress = ProgressPercentaje(page_no, totalSections) if totalSections > 0: if page_no > 0 and page_no <= len(assigment.sections): # The requested page exists updateGroupAssigmentProgress(page_no) # Notify return render_template( 'assigment.html', assigment=assigment, progress=progress, page=page_no, totalSections=totalSections, section=assigment.sections_dict() [page_no - 1], # -1 Because the computer starts counting at 0 form=form) else: # Error flash('Requested page out of bounds', 'danger') else: # Error flash('No sections in current assigment', 'danger')
def openClassroom(): form = forms.OpenClassroom(request.form) # Dynamic drop-down menu to choose the available assigments for professor assigments = assigmentsTupleList(session['id_professor']) form.assigment.choices = assigments classrooms = classroomsTupleList() form.classroom.choices = classrooms if (request.method == 'POST' and form.validate()): # Form information about the new classroom selectedAssigmentID = form['assigment'].data selectedClassroomID = form['classroom'].data # Classroom objects initialization classroomObj = DBUtils.getClassroom(selectedClassroomID) assigmentObj = DBUtils.getAssigment(selectedAssigmentID) rows = int(float(classroomObj.rows)) columns = int(float(classroomObj.columns)) room = classroomObj.name # Object assigment currentProfessor = DBUtils.getProfessor( su.get_professor_id(session)) # Object professor classroom = dataStructures.Classroom((rows, columns), currentProfessor, assigmentObj, room) # Object ClassRoom runningClasses[ classroom. id] = classroom # Add to runningClasses (dict) with id to be able to track different courses su.set_class_id(session, classroom.id) # Add to professor's session return redirect(url_for('professor.classroom')) return render_template('openClassroom.html', form=form)
def addNewMember(): if (request.method == 'POST'): # Data structures to store the information studentPasswordIncorrect = None # Check the button pressed, and tries to log in if request.form['btn'] == 'isStudent': studentPasswordIncorrect = ac.access.loginStudent(request, session) else: flash('Error', 'danger') raise IOError('login error') pass # Logging if studentPasswordIncorrect is not None: # Professor found if (not studentPasswordIncorrect): # Correct password flash('You are now logged in', 'success') # Success now join the desired group selectedRunningClass = runningClasses[su.get_class_id(session)] groupIsIn = selectedRunningClass.studentGroups[su.get_grupo_id( session)] studentid = su.get_students_id_group(session)[ -1] # last student to join the group student = DBUtils.getStudentBy_id(studentid) selectedRunningClass.addStudentToPlace( student, groupIsIn.positionInClass) # Redirect for assigment page assigmentID = selectedRunningClass.assigment.db_id # Current assigment id ''' Socket.io notification''' StudentClass.handle_joinGroup(groupIsIn) # Render de selected assigment at the start page return redirect( url_for('assigment.assigmentByID', id=assigmentID, page=su.get_page(session))) else: # Incorrect password error = 'Password Not matched' return render_template('login.html', error=error) else: error = 'Email not found' return render_template('login.html', error=error) # By default render Login template return render_template('appendStudent.html')
def createAssigment(): form = forms.CreateAssigmentForm(request.form) if (request.method == 'POST' and form.validate()): cur = mysql.connection.cursor() course = form['course'].data name = form['name'].data # Put information at DB id_professor = su.get_professor_id(session) id = DBUtils.putAssigment(course, name, id_professor) su.set_assigment_id(session, id) # Store id to add sections su.set_orderInAssigment(session, 0) # To be in control adding sections return redirect( url_for('professor.addSections', course=course, name=name)) return render_template('createAssigment.html', form=form)
def loginProfessor(request, session): # Logging in as professor email = request.form['email'] password_candidate = request.form['password'] professor = DBUtils.getProfessorBy_email( email ) # Load professor information from DB if exists (None if not) passwordIncorrect = False if professor is not None: if (sha256_crypt.verify( password_candidate, professor.passwordHash)): # Correct password # Session variables # Store information while the user is logged in sessionUtils.professorLogIn(session, professor) else: passwordIncorrect = True return passwordIncorrect
def loginStudent(request, session): email = request.form['email'] password_candidate = request.form['password'] student = DBUtils.getStudentBy_email( email) # Load student information from DB if exists (None if not) passwordIncorrect = False if student is not None: # Professor found if (sha256_crypt.verify(password_candidate, student.passwordHash)): # Correct password # Session variables # Store information while the user is logged in # if not sessionUtils.get_isLoggedIn(session): if "logged_in" in session: # If is a group add the new member sessionUtils.set_student_id(session, student.db_id) else: # If is not a group add just one member sessionUtils.studentLogIn(session, student) else: passwordIncorrect = True return passwordIncorrect
def postToDB(self): from classOn import DBUtils DBUtils.putDoubt(self, self._studentGroup)