示例#1
0
def classroom():
    rows = runningClasses[su.get_class_id(session)].classSize[0]
    columns = runningClasses[su.get_class_id(session)].classSize[1]
    name = runningClasses[su.get_class_id(session)].room

    return render_template('classroomMap.html',
                           rows=rows,
                           columns=columns,
                           name=name)
示例#2
0
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')
示例#3
0
def hadle_queryDoubts():
    '''
    Handles a petition for all doubts and answers in the system. Sends the doubts to how asked for them.
    :return:
    '''
    currentClass = runningClasses[su.get_class_id(session)]
    doubtsJson = currentClass.JSON()                                # JSON string with doubts structure
    room = su.get_ownRoom(session)                                  # Who asked for doubts
    socketio.emit('doubt_query_result', doubtsJson, room=room)
示例#4
0
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)
示例#5
0
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)
示例#6
0
def logout():
    # Cleaning procedures
    selectedRunningClass = runningClasses[su.get_class_id(session)]
    groupIsIn = selectedRunningClass.studentGroups[su.get_grupo_id(session)]

    # Delete the group from the memory
    del selectedRunningClass.studentGroups[su.get_grupo_id(session)]
    # Notify to the professor the changes
    removeGroup(groupIsIn)

    su.logOut(session)
    flash('You are now logged out', 'success')
    return redirect(url_for('home.login'))
示例#7
0
def updateGroupAssigmentProgress(groupID, progress):
    '''
    Updates the assigment progress to all the interested.
    IMPROVE: In order to improve this, we can create groups to send the info only to interested clients.
    :param groupID:
    :param progress:
    :return:
    '''
    selectedRunningClass = runningClasses[su.get_class_id(session)]
    currentGroup = selectedRunningClass.studentGroups[su.get_grupo_id(session)]
    currentGroup.assigmentProgress = progress
    su.set_classRoom(session, selectedRunningClass.id)
    handle_assigmentChangePage(currentGroup)
示例#8
0
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')
示例#9
0
def handle_postDoubt(text):
    '''
    New doubt from a student. Stores the doubt in the system and send it to all other students and professor
    :param text:
    :return:
    '''
    currentClass = runningClasses[su.get_class_id(session)]
    currentGroup = currentClass.studentGroups[su.get_grupo_id(session)]
    page_no = currentGroup.assigmentProgress

    doubtText = text
    doubt = Doubt(doubtText, currentClass.assigment.sections[page_no - 1], currentGroup)
    doubt.postToDB()
    currentClass.addDoubt(doubt)
    currentGroup.doubts.append(doubt)

    flash('Doubt sent', 'success')

    # Notify to Professor and Students
    room = su.get_classRoom(session)
    socketio.emit('doubt_new', doubt.JSON(), room=room)
示例#10
0
def handle_connection():
    selectedRunningClass = runningClasses[su.get_class_id(session)]
    su.set_classRoom(session, selectedRunningClass.id)
    su.set_ownRoom(session, request.sid)
    join_room(selectedRunningClass.id)
示例#11
0
def removeGroup(group):
    currentClass = runningClasses[su.get_class_id(session)]
    # stateJson = currentClass.JSON()
    room = su.get_classRoom(session)
    socketio.emit('removeGroup', group.JSON(), room=room)
示例#12
0
def hadle_queryDoubts():
    currentClass = runningClasses[su.get_class_id(session)]
    stateJson = currentClass.JSON()
    room = su.get_ownRoom(session)
    socketio.emit('classroom_query_result', stateJson, room=room)