Пример #1
0
    def handle_deprecated_progress_event(block, event):
        """
        DEPRECATED: Submit a completion for the block represented by the
        progress event.

        This exists to support the legacy progress extension used by
        edx-solutions.  New XBlocks should not emit these events, but instead
        emit completion events directly.
        """
        if not completion_waffle.waffle().is_enabled(completion_waffle.ENABLE_COMPLETION_TRACKING):
            raise Http404
        else:
            requested_user_id = event.get('user_id', user.id)
            if requested_user_id != user.id:
                log.warning("{} tried to submit a completion on behalf of {}".format(user, requested_user_id))
                return

            # If blocks explicitly declare support for the new completion API,
            # we expect them to emit 'completion' events,
            # and we ignore the deprecated 'progress' events
            # in order to avoid duplicate work and possibly conflicting semantics.
            if not getattr(block, 'has_custom_completion', False):
                BlockCompletion.objects.submit_completion(
                    user=user,
                    course_key=course_id,
                    block_key=block.scope_ids.usage_id,
                    completion=1.0,
                )
Пример #2
0
 def handle_completion_event(block, event):
     """
     Submit a completion object for the block.
     """
     if not completion_waffle.waffle().is_enabled(completion_waffle.ENABLE_COMPLETION_TRACKING):
         raise Http404
     else:
         BlockCompletion.objects.submit_completion(
             user=user,
             course_key=course_id,
             block_key=block.scope_ids.usage_id,
             completion=event['completion'],
         )
Пример #3
0
 def handle_completion_event(block, event):
     """
     Submit a completion object for the block.
     """
     if not completion_waffle.waffle().is_enabled(completion_waffle.ENABLE_COMPLETION_TRACKING):
         raise Http404
     else:
         BlockCompletion.objects.submit_completion(
             user=user,
             course_key=course_id,
             block_key=block.scope_ids.usage_id,
             completion=event['completion'],
         )
Пример #4
0
    def get_event_handler(event_type):
        """
        Return an appropriate function to handle the event.

        Returns None if no special processing is required.
        """
        handlers = {
            'grade': handle_grade_event,
        }
        if completion_waffle.waffle().is_enabled(completion_waffle.ENABLE_COMPLETION_TRACKING):
            handlers.update({
                'completion': handle_completion_event,
                'progress': handle_deprecated_progress_event,
            })
        return handlers.get(event_type)
Пример #5
0
    def handle_deprecated_progress_event(block, event):
        """
        DEPRECATED: Submit a completion for the block represented by the
        progress event.

        This exists to support the legacy progress extension used by
        edx-solutions.  New XBlocks should not emit these events, but instead
        emit completion events directly.
        """
        if not completion_waffle.waffle().is_enabled(completion_waffle.ENABLE_COMPLETION_TRACKING):
            raise Http404
        else:
            requested_user_id = event.get('user_id', user.id)
            if requested_user_id != user.id:
                log.warning("{} tried to submit a completion on behalf of {}".format(user, requested_user_id))
                return
            BlockCompletion.objects.submit_completion(
                user=user,
                course_key=course_id,
                block_key=block.scope_ids.usage_id,
                completion=1.0,
            )
Пример #6
0
    def handle_deprecated_progress_event(block, event):
        """
        DEPRECATED: Submit a completion for the block represented by the
        progress event.

        This exists to support the legacy progress extension used by
        edx-solutions.  New XBlocks should not emit these events, but instead
        emit completion events directly.
        """
        if not completion_waffle.waffle().is_enabled(completion_waffle.ENABLE_COMPLETION_TRACKING):
            raise Http404
        else:
            requested_user_id = event.get('user_id', user.id)
            if requested_user_id != user.id:
                log.warning("{} tried to submit a completion on behalf of {}".format(user, requested_user_id))
                return
            BlockCompletion.objects.submit_completion(
                user=user,
                course_key=course_id,
                block_key=block.scope_ids.usage_id,
                completion=1.0,
            )