Skip to content

Commit

Permalink
Revert "Backport completion-by-viewing logic"
Browse files Browse the repository at this point in the history
  • Loading branch information
naeem91 authored Jul 4, 2018
1 parent 5ec053b commit c198bd7
Show file tree
Hide file tree
Showing 20 changed files with 9 additions and 598 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ cms/envs/private.py
*.orig
/nbproject
.idea/
.vscode/
.redcar/
codekit-config.json
.pycharm_helpers/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
/* JavaScript for Vertical Student View. */

/* global markBlocksCompletedOnViewIfNeeded:false */

window.VerticalStudentView = function(runtime, element) {
'use strict';

markBlocksCompletedOnViewIfNeeded(runtime, element);

if (typeof RequireJS === 'undefined') {
// eslint-disable-next-line no-console
console.warn('Cannot initialize bookmarks for VerticalStudentView. RequireJS is not defined.');
console.log('Cannot initialize VerticalStudentView. RequireJS is not defined.');
return;
}
RequireJS.require(['js/bookmarks/views/bookmark_button'], function(BookmarkButton) {
Expand Down
18 changes: 2 additions & 16 deletions common/lib/xmodule/xmodule/vertical_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
VerticalBlock - an XBlock which renders its children in a column.
"""
import logging
import os
from copy import copy

from django.conf import settings
from lxml import etree
from xblock.core import XBlock
from xblock.fragment import Fragment
Expand All @@ -25,7 +23,6 @@


@XBlock.needs('user', 'bookmarks')
@XBlock.wants('completion')
class VerticalBlock(SequenceFields, XModuleFields, StudioEditableBlock, XmlParserMixin, MakoTemplateBlockBase, XBlock):
"""
Layout XBlock for rendering subblocks vertically.
Expand Down Expand Up @@ -58,24 +55,14 @@ def student_view(self, context):
if 'username' not in child_context:
user_service = self.runtime.service(self, 'user')
child_context['username'] = user_service.get_current_user().opt_attrs['edx-platform.username']
child_blocks = self.get_display_items()
child_blocks_to_complete_on_view = set()
completion_service = self.runtime.service(self, 'completion')
if completion_service and completion_service.completion_tracking_enabled():
child_blocks_to_complete_on_view = completion_service.blocks_to_mark_complete_on_view(child_blocks)

child_context['child_of_vertical'] = True

is_child_of_vertical = context.get('child_of_vertical', False)

# pylint: disable=no-member
for child in child_blocks:
child_block_context = copy(child_context)
if child in child_blocks_to_complete_on_view:
child_block_context['wrap_xblock_data'] = {
'mark-completed-on-view-after-delay': completion_service.get_complete_on_view_delay_ms()
}
rendered_child = child.render(STUDENT_VIEW, child_block_context)
for child in self.get_display_items():
rendered_child = child.render(STUDENT_VIEW, child_context)
fragment.add_frag_resources(rendered_child)

contents.append({
Expand All @@ -92,7 +79,6 @@ def student_view(self, context):
'bookmark_id': u"{},{}".format(child_context['username'], unicode(self.location))
}))

fragment.add_javascript_url(self.runtime.STATIC_URL + 'bundles/CompletionOnViewService.js')
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vertical_student_view.js'))
fragment.initialize_js('VerticalStudentView')

Expand Down
25 changes: 0 additions & 25 deletions common/test/acceptance/pages/lms/completion.py

This file was deleted.

26 changes: 1 addition & 25 deletions common/test/acceptance/pages/lms/courseware.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
from bok_choy.promise import EmptyPromise
from selenium.webdriver.common.action_chains import ActionChains

from common.test.acceptance.pages.lms import BASE_URL
from common.test.acceptance.pages.lms.bookmarks import BookmarksPage
from common.test.acceptance.pages.lms.completion import CompletionOnViewMixin
from common.test.acceptance.pages.lms.course_page import CoursePage


class CoursewarePage(CoursePage, CompletionOnViewMixin):
class CoursewarePage(CoursePage):
"""
Course info.
"""
Expand Down Expand Up @@ -589,25 +587,3 @@ def visit_course_outline_page(self):
# reload the same page with the course_outline_page flag
self.browser.get(self.browser.current_url + "&course_experience.course_outline_page=1")
self.wait_for_page()


class RenderXBlockPage(PageObject, CompletionOnViewMixin):
"""
render_xblock page.
"""

xblock_component_selector = '.xblock'

def __init__(self, browser, block_id):
super(RenderXBlockPage, self).__init__(browser)
self.block_id = block_id

@property
def url(self):
"""
Construct a URL to the page within the course.
"""
return BASE_URL + "/xblock/" + self.block_id

def is_browser_on_page(self):
return self.q(css='.course-content').present
128 changes: 1 addition & 127 deletions common/test/acceptance/tests/lms/test_lms_courseware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ...pages.common.auto_auth import AutoAuthPage
from ...pages.common.logout import LogoutPage
from ...pages.lms.course_home import CourseHomePage
from ...pages.lms.courseware import CoursewarePage, CoursewareSequentialTabPage, RenderXBlockPage
from ...pages.lms.courseware import CoursewarePage, CoursewareSequentialTabPage
from ...pages.lms.create_mode import ModeCreationPage
from ...pages.lms.dashboard import DashboardPage
from ...pages.lms.pay_and_verify import FakePaymentPage, FakeSoftwareSecureVerificationPage, PaymentAndVerificationFlow
Expand Down Expand Up @@ -947,129 +947,3 @@ def test_subsecton_hidden_after_due_date(self):

self.progress_page.visit()
self.assertEqual(self.progress_page.scores('Test Section 1', 'Test Subsection 1'), [(0, 1)])


@attr(shard=9)
class CompletionTestCase(UniqueCourseTest, EventsTestMixin):
"""
Test the completion on view functionality.
"""
USERNAME = "STUDENT_TESTER"
EMAIL = "student101@example.com"
COMPLETION_BY_VIEWING_DELAY_MS = '1000'

def setUp(self):
super(CompletionTestCase, self).setUp()

self.studio_course_outline = StudioCourseOutlinePage(
self.browser,
self.course_info['org'],
self.course_info['number'],
self.course_info['run']
)

# Install a course with sections/problems, tabs, updates, and handouts
course_fix = CourseFixture(
self.course_info['org'], self.course_info['number'],
self.course_info['run'], self.course_info['display_name']
)

self.html_1_block = XBlockFixtureDesc('html', 'html 1', data="<html>html 1 dummy body</html>")
self.problem_1_block = XBlockFixtureDesc(
'problem', 'Test Problem 1', data='<problem>problem 1 dummy body</problem>'
)

course_fix.add_children(
XBlockFixtureDesc('chapter', 'Test Section 1').add_children(
XBlockFixtureDesc('sequential', 'Test Subsection 1,1').add_children(
XBlockFixtureDesc('vertical', 'Test Unit 1,1,1').add_children(
XBlockFixtureDesc('html', 'html 1', data="<html>html 1 dummy body</html>"),
XBlockFixtureDesc(
'html', 'html 2',
data=("<html>html 2 dummy body</html>" * 100) + "<span id='html2-end'>End</span>",
),
XBlockFixtureDesc('problem', 'Test Problem 1', data='<problem>problem 1 dummy body</problem>'),
),
XBlockFixtureDesc('vertical', 'Test Unit 1,1,2').add_children(
XBlockFixtureDesc('html', 'html 1', data="<html>html 1 dummy body</html>"),
XBlockFixtureDesc('problem', 'Test Problem 1', data='<problem>problem 1 dummy body</problem>'),
),
XBlockFixtureDesc('vertical', 'Test Unit 1,1,2').add_children(
self.html_1_block,
self.problem_1_block,
),
),
),
).install()

# Auto-auth register for the course.
AutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL,
course_id=self.course_id, staff=False).visit()

def test_courseware_publish_completion_is_sent_on_view(self):
"""
Test that when viewing courseware XBlocks are correctly marked as completed on view.
"""
courseware_page = CoursewarePage(self.browser, self.course_id)
courseware_page.visit()
courseware_page.wait_for_page()

# Initially, the first two blocks in the first vertical should be marked as needing to be completed on view.
self.assertEqual(
courseware_page.xblock_components_mark_completed_on_view_value(),
[self.COMPLETION_BY_VIEWING_DELAY_MS, self.COMPLETION_BY_VIEWING_DELAY_MS, None],
)
# Wait and verify that the first block which is completely visible is marked as completed.
courseware_page.wait_for_xblock_component_to_be_marked_completed_on_view(0)
self.assertEqual(
courseware_page.xblock_components_mark_completed_on_view_value(),
['0', self.COMPLETION_BY_VIEWING_DELAY_MS, None],
)

# Scroll to the bottom of the second block.
courseware_page.scroll_to_element('#html2-end', 'Scroll to end of html 2 block')
# Wait and verify that the second block is also now marked as completed.
courseware_page.wait_for_xblock_component_to_be_marked_completed_on_view(1)
self.assertEqual(courseware_page.xblock_components_mark_completed_on_view_value(), ['0', '0', None])

# After page refresh, no blocks in the vertical should be marked as needing to be completed on view.
self.browser.refresh()
courseware_page.wait_for_page()
self.assertEqual(courseware_page.xblock_components_mark_completed_on_view_value(), [None, None, None])

courseware_page.go_to_sequential_position(2)

# Initially, the first block in the second vertical should be marked as needing to be completed on view.
self.assertEqual(
courseware_page.xblock_components_mark_completed_on_view_value(),
[self.COMPLETION_BY_VIEWING_DELAY_MS, None],
)
# Wait and verify that the first block which is completely visible is marked as completed.
courseware_page.wait_for_xblock_component_to_be_marked_completed_on_view(0)
self.assertEqual(courseware_page.xblock_components_mark_completed_on_view_value(), ['0', None])

# After page refresh, no blocks in the vertical should be marked as needing to be completed on view.
self.browser.refresh()
courseware_page.wait_for_page()
self.assertEqual(courseware_page.xblock_components_mark_completed_on_view_value(), [None, None])

def test_render_xblock_publish_completion_is_sent_on_view(self):
"""
Test that when viewing a XBlock in render_xblock, it is correctly marked as completed on view.
"""
block_page = RenderXBlockPage(self.browser, self.html_1_block.locator)
block_page.visit()
block_page.wait_for_page()

# Initially the block should be marked as needing to be completed on view.
self.assertEqual(
block_page.xblock_components_mark_completed_on_view_value(), [self.COMPLETION_BY_VIEWING_DELAY_MS]
)
# Wait and verify that the block is marked as completed on view.
block_page.wait_for_xblock_component_to_be_marked_completed_on_view(0)
self.assertEqual(block_page.xblock_components_mark_completed_on_view_value(), ['0'])

# After page refresh, it should not be marked as needing to be completed on view.
self.browser.refresh()
block_page.wait_for_page()
self.assertEqual(block_page.xblock_components_mark_completed_on_view_value(), [None])
9 changes: 0 additions & 9 deletions common/test/db_fixtures/waffle_flags.json

This file was deleted.

10 changes: 0 additions & 10 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,15 +1458,6 @@ def render_xblock(request, usage_key_string, check_if_enrolled=True):
student_view_context = request.GET.dict()
student_view_context['show_bookmark_button'] = False

enable_completion_on_view_service = False
completion_service = block.runtime.service(block, 'completion')
if completion_service and completion_service.completion_tracking_enabled():
if completion_service.blocks_to_mark_complete_on_view({block}):
enable_completion_on_view_service = True
student_view_context['wrap_xblock_data'] = {
'mark-completed-on-view-after-delay': completion_service.get_complete_on_view_delay_ms()
}

context = {
'fragment': block.render('student_view', context=student_view_context),
'course': course,
Expand All @@ -1475,7 +1466,6 @@ def render_xblock(request, usage_key_string, check_if_enrolled=True):
'disable_header': True,
'disable_footer': True,
'disable_window_wrap': True,
'enable_completion_on_view_service': enable_completion_on_view_service,
'staff_access': bool(has_access(request.user, 'staff', course)),
'xqa_server': settings.FEATURES.get('XQA_SERVER', 'http://your_xqa_server.com'),
}
Expand Down
18 changes: 0 additions & 18 deletions lms/djangoapps/lms_xblock/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
#from django.utils.translation import ugettext_noop as _
from lazy import lazy
from xblock.core import XBlock
from xblock.exceptions import JsonHandlerError
from xblock.fields import Boolean, Dict, Scope, String, XBlockMixin
from xblock.validation import ValidationMessage

from xmodule.modulestore.inheritance import UserPartitionList
from xmodule.partitions.partitions import NoSuchUserPartitionError, NoSuchUserPartitionGroupError


# Please do not remove, this is a workaround for Django 1.8.
# more information can be found here: https://openedx.atlassian.net/browse/PLAT-902
_ = lambda text: text
Expand All @@ -33,7 +31,6 @@ def to_json(self, access_dict):


@XBlock.needs('partitions')
@XBlock.wants('completion')
class LmsBlockMixin(XBlockMixin):
"""
Mixin that defines fields common to all blocks used in the LMS
Expand Down Expand Up @@ -182,18 +179,3 @@ def validate(self):
)
)
return validation

@XBlock.json_handler
def publish_completion(self, data, suffix=''): # pylint: disable=unused-argument
"""
Publish completion data from the front end.
"""
completion_service = self.runtime.service(self, 'completion')
if completion_service is None:
raise JsonHandlerError(500, u"No completion service found")
elif not completion_service.completion_tracking_enabled():
raise JsonHandlerError(404, u"Completion tracking is not enabled and API calls are unexpected")
if not completion_service.should_mark_block_completed_on_view(self):
raise JsonHandlerError(400, u"Block not configured for completion on view.")
self.runtime.publish(self, u"completion", data)
return {u'result': u'ok'}
3 changes: 0 additions & 3 deletions lms/djangoapps/lms_xblock/runtime.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""
Module implementing `xblock.runtime.Runtime` functionality for the LMS
"""

import xblock.reference.plugins
from completion.services import CompletionService
from django.conf import settings
from django.core.urlresolvers import reverse

Expand Down Expand Up @@ -180,7 +178,6 @@ class LmsModuleSystem(LmsCourse, LmsUser, ModuleSystem): # pylint: disable=abst
def __init__(self, **kwargs):
request_cache_dict = RequestCache.get_request_cache().data
services = kwargs.setdefault('services', {})
services['completion'] = CompletionService(user=kwargs.get('user'), course_key=kwargs.get('course_id'))
services['fs'] = xblock.reference.plugins.FSService()
services['i18n'] = ModuleI18nService
services['library_tools'] = LibraryToolsService(modulestore())
Expand Down
7 changes: 0 additions & 7 deletions lms/static/coffee/src/courseware.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ class @Courseware

render: ->
XBlock.initializeBlocks($('.course-content'))

courseContentElement = $('.course-content')[0]
blocks = XBlock.initializeBlocks(courseContentElement)

if (courseContentElement.dataset.enableCompletionOnViewService == 'true')
markBlocksCompletedOnViewIfNeeded(blocks[0].runtime, courseContentElement)

$('.course-content .histogram').each ->
id = $(this).attr('id').replace(/histogram_/, '')
try
Expand Down
Loading

0 comments on commit c198bd7

Please sign in to comment.