diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0b9904c..fd69014 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,7 +15,12 @@ Unreleased ~~~~~~~~~~ * Nothing -[0.0.6] - 2018-02-13 +[0.0.7] - 2018-02-15 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +* Add settings and service method for determining completion-by-viewing delay. + + [0.0.6] - 2018-02-13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Add the additional completion logic into the service and models from edx-platform diff --git a/completion/__init__.py b/completion/__init__.py index 763d755..9e579c8 100644 --- a/completion/__init__.py +++ b/completion/__init__.py @@ -5,6 +5,6 @@ from __future__ import unicode_literals -__version__ = '0.0.6' +__version__ = '0.0.7' default_app_config = 'completion.apps.CompletionAppConfig' # pylint: disable=invalid-name diff --git a/completion/services.py b/completion/services.py index ccfb2b5..6856a38 100644 --- a/completion/services.py +++ b/completion/services.py @@ -4,6 +4,8 @@ from __future__ import unicode_literals +from django.conf import settings + from .models import BlockCompletion from . import waffle @@ -99,3 +101,10 @@ def vertical_is_complete(self, item): if completions[child_location] < 1.0: return False return True + + def get_completion_by_viewing_delay_ms(self): + """ + Do not mark blocks complete-by-viewing until they have been visible for + the returned amount of time, in milliseconds. Defaults to 5000. + """ + return getattr(settings, 'COMPLETION_BY_VIEWING_DELAY_MS', 5000) diff --git a/completion/settings/common.py b/completion/settings/common.py index 5328729..7cd5d74 100644 --- a/completion/settings/common.py +++ b/completion/settings/common.py @@ -36,4 +36,8 @@ def plugin_settings(settings): # pylint: disable=unused-argument Defines completion-specific settings when app is used as a plugin to edx-platform. See: https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/plugins/README.rst """ - pass + # Once a complete-by-viewing (e.g. HTML) block has been visible on-screen for this many ms, mark it complete + settings.COMPLETION_BY_VIEWING_DELAY_MS = 5000 + # Once a user has watched this percentage of a video, mark it as complete: + # (0.0 = 0%, 1.0 = 100%) + settings.COMPLETION_VIDEO_COMPLETE_PERCENTAGE = 0.95 diff --git a/completion/tests/test_services.py b/completion/tests/test_services.py index fd00771..a6e5714 100644 --- a/completion/tests/test_services.py +++ b/completion/tests/test_services.py @@ -6,6 +6,7 @@ import ddt from django.test import TestCase +from django.test.utils import override_settings from opaque_keys.edx.keys import CourseKey, UsageKey from ..models import BlockCompletion @@ -78,3 +79,17 @@ def test_get_completions_block_keys_missing_run(self): def test_enabled_honors_waffle_switch(self, enabled): with self.override_completion_switch(enabled): self.assertEqual(self.completion_service.completion_tracking_enabled(), enabled) + + +@ddt.ddt +class CompletionDelayTestCase(CompletionSetUpMixin, TestCase): + """ + Test that the completion-by-viewing delay is properly passed in from + the project settings. + """ + + @ddt.data(1, 1000, 0) + def test_get_completion_by_viewing_delay_ms(self, delay): + service = CompletionService(self.user, self.course_key) + with override_settings(COMPLETION_BY_VIEWING_DELAY_MS=delay): + self.assertEqual(service.get_completion_by_viewing_delay_ms(), delay)