Example #1
0
class CheckpointProgressSubmit(Resource):
    method_decorators = [
        user_session_exists,
        roles_accepted("Student"), checkpoint_exists
    ]

    # Function to retrieve data from a checkpoint progress
    @checkpoint_progress_exist
    def get(self, checkpoint_id):
        user_data = session["profile"]
        checkpoint_prog = CheckpointProgress.query.filter_by(
            checkpoint_id=checkpoint_id,
            student_id=user_data["student_id"]).first()

        return get_checkpoint_data(checkpoint_prog)

    # Function to return data on a single checkpoint
    @checkpoint_progress_exist
    @valid_checkpoint_progress_data
    @multiple_choice_is_completed
    def put(self, checkpoint_id):
        data = request.form
        user_data = session["profile"]
        checkpoint_prog = CheckpointProgress.query.filter_by(
            checkpoint_id=checkpoint_id,
            student_id=user_data["student_id"]).first()
        fill_in_checkpoint_progress(data, checkpoint_prog)

        db.session.commit()
        is_activity_completed(checkpoint_prog.activity_progress_id,
                              checkpoint_prog.student_id)
        db.session.commit()

        return get_checkpoint_data(checkpoint_prog)
Example #2
0
class TrackProgress(Resource):
    method_decorators = [track_exists, roles_accepted("Student")]

    # Function to retrieve the students track progress
    def get(self, track_id):
        user_data = session["profile"]
        track_progress = get_track_progress(user_data["student_id"], track_id)

        return track_progress_schema.dump(track_progress)
Example #3
0
class TopicProgress(Resource):
    method_decorators = [roles_accepted("Student"), topic_exists]

    # Function to retrieve the module progress for a student given an id
    def get(self, topic_id):
        user_data = session["profile"]
        topic_progress = get_topic_progress(user_data["student_id"], topic_id)

        return topic_progress_schema.dump(topic_progress)
Example #4
0
class TopicProgressAdd(Resource):
    method_decorators = [roles_accepted("Student"), module_exists]

    # Function to add a module to a student's inprogress_modules
    @module_is_incomplete
    def put(self, topic_id, module_id):
        user_data = session["profile"]
        student = Student.query.get(user_data["student_id"])
        module = Module.query.get(module_id)
        student.inprogress_modules.append(module)
        student.incomplete_modules.remove(module)

        db.session.commit()

        return {"message": "Module added!"}, 201
Example #5
0
class TrackProgressUpdate(Resource):
    method_decorators = [roles_accepted("Student"), topic_exists]

    # Function to update the student's completed topic
    @can_complete_topic
    @has_completed_topic
    def put(self, topic_id):
        user_data = session["profile"]
        student = Student.query.get(user_data["student_id"])
        topic = Topic.query.get(topic_id)
        student.completed_topics.append(topic)
        student.inprogress_topics.remove(topic)

        db.session.commit()

        return {"message": "Student topic successfully updated!"}
Example #6
0
class TrackProgressAdd(Resource):
    method_decorators = [roles_accepted("Student"), topic_exists]

    # Function to add a topic to a student's inprogress_topics
    @can_add_topic
    @topic_is_incomplete
    def put(self, topic_id):
        user_data = session["profile"]
        student = Student.query.get(user_data["student_id"])
        topic = Topic.query.get(topic_id)
        student.inprogress_topics.append(topic)
        student.incomplete_topics.remove(topic)

        db.session.commit()

        return {"message": "Topic added!"}, 201
Example #7
0
class ActivityProgressHints(Resource):
    method_decorators = [
        user_session_exists,
        roles_accepted("Student"), activity_exists, hint_exists
    ]

    # Function to unlock a hint by its hint_id
    @activity_prog_exists
    def put(self, activity_id, hint_id):
        user_data = session["profile"]
        student_activity_prog = ActivityProgress.query.filter_by(
            student_id=user_data["student_id"],
            activity_id=activity_id).first()
        hint = Hint.query.get(hint_id)
        unlock_message = unlock_hint(student_activity_prog, hint)

        db.session.commit()

        return {"message": unlock_message}, 200
Example #8
0
class TopicProgressUpdate(Resource):
    method_decorators = [
        roles_accepted("Student"), topic_exists, module_exists
    ]

    # Function to update the student's completed module
    @module_is_complete
    @module_in_inprogress
    def put(self, topic_id, module_id):
        user_data = session["profile"]
        student = Student.query.get(user_data["student_id"])
        module = Module.query.get(module_id)
        student.completed_modules.append(module)
        student.inprogress_modules.remove(module)

        db.session.commit()

        return {
            "message": "Successfully updated student completed modules"
        }, 202
Example #9
0
class ActivityProgressUpdate(Resource):
    method_decorators = [user_session_exists, roles_accepted("Student")]

    # Function to return the last card completed on an activity
    @cards_exist_in_activity
    # @has_completed_prerequisites
    def get(self, activity_id):
        user_data = session["profile"]
        student = Student.query.get(user_data["student_id"])
        student_activity_prog = ActivityProgress.query.filter_by(
            student_id=student.id, activity_id=activity_id).first()

        if not student_activity_prog:
            # Create Activity Progress if it does not exist
            student_activity_prog = create_progress(activity_id, student.id)
            student.current_activities.append(student_activity_prog.activity)
            fill_in_rels(student_activity_prog, student)
            # TODO edit the relationship function later
            topics = update_module_progresses(student_activity_prog.activity,
                                              student)
            update_topic_progresses(topics, student)

        card = Card.query.get(student_activity_prog.last_card_unlocked)
        progress = activity_progress_schema.dump(student_activity_prog)
        progress["last_card_unlocked_id"] = card.id
        db.session.commit()

        return progress

    @activity_prog_exists
    def delete(self, activity_id):
        user_data = session["profile"]
        student_activity_prog = ActivityProgress.query.filter_by(
            student_id=user_data["student_id"],
            activity_id=activity_id).first()
        db.session.delete(student_activity_prog)
        db.session.commit()

        return {
            "message": "Student activity progress successfully deleted."
        }, 200
Example #10
0
class CardGetHints(Resource):
    method_decorators = [
        user_session_exists,
        roles_accepted("Student"), activity_prog_exists, card_exists,
        card_exists_in_activity
    ]

    # Function to unlock the next card
    # @card_is_unlockable
    def put(self, activity_id, card_id):
        user_data = session["profile"]
        card = Card.query.get(card_id)
        student_activity_prog = ActivityProgress.query.filter_by(
            student_id=user_data["student_id"],
            activity_id=activity_id).first()
        unlock_card(student_activity_prog, card)
        student_activity_prog.last_card_unlocked = card.id
        db.session.commit()
        is_activity_completed(student_activity_prog.id,
                              user_data["student_id"])
        db.session.commit()

        return {"message": "Card successfully updated"}, 200