コード例 #1
0
ファイル: capture_events.py プロジェクト: ubc/compair
def learning_record_on_detach_file(sender, user, **extra):
    file_record = extra.get('file')
    mimetype, encoding = mimetypes.guess_type(file_record.name)

    assignment = extra.get('assignment')
    answer = extra.get('answer')

    if assignment:
        if XAPI.enabled():
            XAPI.emit(
                XAPIStatement.generate(
                    user=user,
                    verb=XAPIVerb.generate('removed'),
                    object=XAPIObject.assignment_attachment(
                        file_record, mimetype),
                    context=XAPIContext.assignment_attachment(assignment)))

        if CaliperSensor.enabled():
            CaliperSensor.emit(
                caliper.events.Event(
                    action=caliper.constants.CALIPER_ACTIONS["REMOVED"],
                    profile=caliper.constants.CALIPER_PROFILES['GENERAL'],
                    object=CaliperEntities.assignment_attachment(
                        assignment, file_record, mimetype),
                    **CaliperEvent._defaults(user, course=assignment.course)))

    elif answer:
        if XAPI.enabled():
            XAPI.emit(
                XAPIStatement.generate(
                    user=user,
                    verb=XAPIVerb.generate('removed'),
                    object=XAPIObject.answer_attachment(file_record, mimetype),
                    context=XAPIContext.answer_attachment(answer)))

        if CaliperSensor.enabled():
            CaliperSensor.emit(
                caliper.events.Event(
                    action=caliper.constants.CALIPER_ACTIONS["REMOVED"],
                    profile=caliper.constants.CALIPER_PROFILES['GENERAL'],
                    object=CaliperEntities.answer_attachment(
                        answer, file_record, mimetype),
                    **CaliperEvent._defaults(user,
                                             course=answer.assignment.course)))
コード例 #2
0
ファイル: capture_events.py プロジェクト: ubc/compair
def learning_record_on_get_file(sender, user, **extra):
    file_type = extra.get('file_type')
    file_name = extra.get('file_name')
    mimetype, encoding = mimetypes.guess_type(file_name)

    # only send when file_type is report
    if file_type and file_type == 'report':
        if XAPI.enabled():
            XAPI.emit(
                XAPIStatement.generate(user=user,
                                       verb=XAPIVerb.generate('downloaded'),
                                       object=XAPIObject.report(
                                           file_name, mimetype)))

        if CaliperSensor.enabled():
            CaliperSensor.emit(
                caliper.events.ResourceManagementEvent(
                    action=caliper.constants.CALIPER_ACTIONS["DOWNLOADED"],
                    profile=caliper.constants.
                    CALIPER_PROFILES['RESOURCE_MANAGEMENT'],
                    object=CaliperEntities.report(file_name, mimetype),
                    **CaliperEvent._defaults(user)))

    elif file_type and file_type == 'attachment':
        file_record = File.query.filter_by(name=file_name).first()
        if file_record:
            assignment = file_record.assignments.first()
            answer = file_record.answers.first()

            if assignment:
                if XAPI.enabled():
                    XAPI.emit(
                        XAPIStatement.generate(
                            user=user,
                            verb=XAPIVerb.generate('downloaded'),
                            object=XAPIObject.assignment_attachment(
                                file_record, mimetype),
                            context=XAPIContext.assignment_attachment(
                                assignment)))

                if CaliperSensor.enabled():
                    CaliperSensor.emit(
                        caliper.events.ResourceManagementEvent(
                            action=caliper.constants.
                            CALIPER_ACTIONS["DOWNLOADED"],
                            profile=caliper.constants.
                            CALIPER_PROFILES['RESOURCE_MANAGEMENT'],
                            object=CaliperEntities.assignment_attachment(
                                assignment, file_record, mimetype),
                            **CaliperEvent._defaults(
                                user, course=assignment.course)))

            elif answer:
                if XAPI.enabled():
                    XAPI.emit(
                        XAPIStatement.generate(
                            user=user,
                            verb=XAPIVerb.generate('downloaded'),
                            object=XAPIObject.answer_attachment(
                                file_record, mimetype),
                            context=XAPIContext.answer_attachment(answer)))

                if CaliperSensor.enabled():
                    CaliperSensor.emit(
                        caliper.events.ResourceManagementEvent(
                            action=caliper.constants.
                            CALIPER_ACTIONS["DOWNLOADED"],
                            profile=caliper.constants.
                            CALIPER_PROFILES['RESOURCE_MANAGEMENT'],
                            object=CaliperEntities.answer_attachment(
                                answer, file_record, mimetype),
                            **CaliperEvent._defaults(
                                user, course=answer.assignment.course)))