Commit 0b6da4cd by Nimisha Asthagiri

Merge pull request #12267 from edx/tnl/refactor_courseware_index

Refactor courseware index
parents f0f06450 c6954902
...@@ -298,7 +298,7 @@ class DashboardTest(ModuleStoreTestCase): ...@@ -298,7 +298,7 @@ class DashboardTest(ModuleStoreTestCase):
self.assertIsNone(course_mode_info['days_for_upsell']) self.assertIsNone(course_mode_info['days_for_upsell'])
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@patch('courseware.views.log.warning') @patch('courseware.views.index.log.warning')
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_PAID_COURSE_REGISTRATION': True}) @patch.dict('django.conf.settings.FEATURES', {'ENABLE_PAID_COURSE_REGISTRATION': True})
def test_blocked_course_scenario(self, log_warning): def test_blocked_course_scenario(self, log_warning):
...@@ -349,7 +349,10 @@ class DashboardTest(ModuleStoreTestCase): ...@@ -349,7 +349,10 @@ class DashboardTest(ModuleStoreTestCase):
# Direct link to course redirect to user dashboard # Direct link to course redirect to user dashboard
self.client.get(reverse('courseware', kwargs={"course_id": self.course.id.to_deprecated_string()})) self.client.get(reverse('courseware', kwargs={"course_id": self.course.id.to_deprecated_string()}))
log_warning.assert_called_with( log_warning.assert_called_with(
u'User %s cannot access the course %s because payment has not yet been received', self.user, self.course.id.to_deprecated_string()) u'User %s cannot access the course %s because payment has not yet been received',
self.user,
unicode(self.course.id),
)
# Now re-validating the invoice # Now re-validating the invoice
invoice = shoppingcart.models.Invoice.objects.get(id=sale_invoice_1.id) invoice = shoppingcart.models.Invoice.objects.get(id=sale_invoice_1.id)
......
...@@ -43,7 +43,7 @@ What is supported: ...@@ -43,7 +43,7 @@ What is supported:
(http://www.imsglobal.org/lti/ltiv2p0/uml/purl.imsglobal.org/vocab/lis/v2/outcomes/Result/service.html) (http://www.imsglobal.org/lti/ltiv2p0/uml/purl.imsglobal.org/vocab/lis/v2/outcomes/Result/service.html)
a.) Discovery of all such LTI http endpoints for a course. External tools GET from this discovery a.) Discovery of all such LTI http endpoints for a course. External tools GET from this discovery
endpoint and receive URLs for interacting with individual grading units. endpoint and receive URLs for interacting with individual grading units.
(see lms/djangoapps/courseware/views.py:get_course_lti_endpoints) (see lms/djangoapps/courseware/views/views.py:get_course_lti_endpoints)
b.) GET, PUT and DELETE in LTI Result JSON binding b.) GET, PUT and DELETE in LTI Result JSON binding
(http://www.imsglobal.org/lti/ltiv2p0/mediatype/application/vnd/ims/lis/v2/result+json/index.html) (http://www.imsglobal.org/lti/ltiv2p0/mediatype/application/vnd/ims/lis/v2/result+json/index.html)
for a provider to synchronize grades into edx-platform. Reading, Setting, and Deleteing for a provider to synchronize grades into edx-platform. Reading, Setting, and Deleteing
......
...@@ -91,7 +91,7 @@ The LMS is a django site, with root in `lms/`. It runs in many different enviro ...@@ -91,7 +91,7 @@ The LMS is a django site, with root in `lms/`. It runs in many different enviro
- `lms/djangoapps/courseware/models.py` - `lms/djangoapps/courseware/models.py`
- Core rendering path: - Core rendering path:
- `lms/urls.py` points to `courseware.views.index`, which gets module info from the course xml file, pulls list of `StudentModule` objects for this user (to avoid multiple db hits). - `lms/urls.py` points to `courseware.views.views.index`, which gets module info from the course xml file, pulls list of `StudentModule` objects for this user (to avoid multiple db hits).
- Calls `render_accordion` to render the "accordion"--the display of the course structure. - Calls `render_accordion` to render the "accordion"--the display of the course structure.
......
...@@ -44,7 +44,7 @@ MOCK_MODULES = [ ...@@ -44,7 +44,7 @@ MOCK_MODULES = [
'courseware.access', 'courseware.access',
'courseware.model_data', 'courseware.model_data',
'courseware.module_render', 'courseware.module_render',
'courseware.views', 'courseware.views.views',
'util.request', 'util.request',
'eventtracking', 'eventtracking',
'xmodule', 'xmodule',
......
...@@ -196,7 +196,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase): ...@@ -196,7 +196,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase):
self.factory = RequestFactory() self.factory = RequestFactory()
@patch('student.views.render_to_response', RENDER_MOCK) @patch('student.views.render_to_response', RENDER_MOCK)
@patch('courseware.views.render_to_response', RENDER_MOCK) @patch('courseware.views.views.render_to_response', RENDER_MOCK)
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': False}) @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': False})
def test_course_discovery_off(self): def test_course_discovery_off(self):
""" """
...@@ -220,7 +220,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase): ...@@ -220,7 +220,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase):
self.assertIn('<div class="courses no-course-discovery"', response.content) self.assertIn('<div class="courses no-course-discovery"', response.content)
@patch('student.views.render_to_response', RENDER_MOCK) @patch('student.views.render_to_response', RENDER_MOCK)
@patch('courseware.views.render_to_response', RENDER_MOCK) @patch('courseware.views.views.render_to_response', RENDER_MOCK)
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': True}) @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': True})
def test_course_discovery_on(self): def test_course_discovery_on(self):
""" """
...@@ -242,7 +242,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase): ...@@ -242,7 +242,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase):
self.assertIn('<div class="courses"', response.content) self.assertIn('<div class="courses"', response.content)
@patch('student.views.render_to_response', RENDER_MOCK) @patch('student.views.render_to_response', RENDER_MOCK)
@patch('courseware.views.render_to_response', RENDER_MOCK) @patch('courseware.views.views.render_to_response', RENDER_MOCK)
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': False}) @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': False})
def test_course_cards_sorted_by_default_sorting(self): def test_course_cards_sorted_by_default_sorting(self):
response = self.client.get('/') response = self.client.get('/')
...@@ -267,7 +267,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase): ...@@ -267,7 +267,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase):
self.assertEqual(context['courses'][2].id, self.course_with_default_start_date.id) self.assertEqual(context['courses'][2].id, self.course_with_default_start_date.id)
@patch('student.views.render_to_response', RENDER_MOCK) @patch('student.views.render_to_response', RENDER_MOCK)
@patch('courseware.views.render_to_response', RENDER_MOCK) @patch('courseware.views.views.render_to_response', RENDER_MOCK)
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_SORTING_BY_START_DATE': False}) @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_SORTING_BY_START_DATE': False})
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': False}) @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': False})
def test_course_cards_sorted_by_start_date_disabled(self): def test_course_cards_sorted_by_start_date_disabled(self):
......
...@@ -15,7 +15,7 @@ from django.contrib.staticfiles.storage import staticfiles_storage ...@@ -15,7 +15,7 @@ from django.contrib.staticfiles.storage import staticfiles_storage
from edxmako.shortcuts import render_to_response from edxmako.shortcuts import render_to_response
import student.views import student.views
from student.models import CourseEnrollment from student.models import CourseEnrollment
import courseware.views import courseware.views.views
from microsite_configuration import microsite from microsite_configuration import microsite
from edxmako.shortcuts import marketing_link from edxmako.shortcuts import marketing_link
from util.cache import cache_if_anonymous from util.cache import cache_if_anonymous
...@@ -97,7 +97,7 @@ def courses(request): ...@@ -97,7 +97,7 @@ def courses(request):
""" """
Render the "find courses" page. If the marketing site is enabled, redirect Render the "find courses" page. If the marketing site is enabled, redirect
to that. Otherwise, if subdomain branding is on, this is the university to that. Otherwise, if subdomain branding is on, this is the university
profile page. Otherwise, it's the edX courseware.views.courses page profile page. Otherwise, it's the edX courseware.views.views.courses page
""" """
enable_mktg_site = microsite.get_value( enable_mktg_site = microsite.get_value(
'ENABLE_MKTG_SITE', 'ENABLE_MKTG_SITE',
...@@ -112,7 +112,7 @@ def courses(request): ...@@ -112,7 +112,7 @@ def courses(request):
# we do not expect this case to be reached in cases where # we do not expect this case to be reached in cases where
# marketing is enabled or the courses are not browsable # marketing is enabled or the courses are not browsable
return courseware.views.courses(request) return courseware.views.views.courses(request)
def _footer_static_url(request, name): def _footer_static_url(request, name):
......
...@@ -7,7 +7,7 @@ import itertools ...@@ -7,7 +7,7 @@ import itertools
import mock import mock
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
from courseware.views import progress from courseware.views.views import progress
from courseware.field_overrides import OverrideFieldData from courseware.field_overrides import OverrideFieldData
from datetime import datetime from datetime import datetime
from django.conf import settings from django.conf import settings
......
...@@ -983,10 +983,10 @@ class TestCCXGrades(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -983,10 +983,10 @@ class TestCCXGrades(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertEqual(data['HW 03'], '0.25') self.assertEqual(data['HW 03'], '0.25')
self.assertEqual(data['HW Avg'], '0.5') self.assertEqual(data['HW Avg'], '0.5')
@patch('courseware.views.render_to_response', intercept_renderer) @patch('courseware.views.views.render_to_response', intercept_renderer)
def test_student_progress(self): def test_student_progress(self):
self.course.enable_ccx = True self.course.enable_ccx = True
patch_context = patch('courseware.views.get_course_with_access') patch_context = patch('courseware.views.views.get_course_with_access')
get_course = patch_context.start() get_course = patch_context.start()
get_course.return_value = self.course get_course.return_value = self.course
self.addCleanup(patch_context.stop) self.addCleanup(patch_context.stop)
......
...@@ -39,7 +39,7 @@ class BlockSerializer(serializers.Serializer): # pylint: disable=abstract-metho ...@@ -39,7 +39,7 @@ class BlockSerializer(serializers.Serializer): # pylint: disable=abstract-metho
request=self.context['request'], request=self.context['request'],
), ),
'student_view_url': reverse( 'student_view_url': reverse(
'courseware.views.render_xblock', 'courseware.views.views.render_xblock',
kwargs={'usage_key_string': unicode(block_key)}, kwargs={'usage_key_string': unicode(block_key)},
request=self.context['request'], request=self.context['request'],
), ),
......
...@@ -25,7 +25,7 @@ def course_has_entrance_exam(course): ...@@ -25,7 +25,7 @@ def course_has_entrance_exam(course):
return True return True
def user_can_skip_entrance_exam(request, user, course): def user_can_skip_entrance_exam(user, course):
""" """
Checks all of the various override conditions for a user to skip an entrance exam Checks all of the various override conditions for a user to skip an entrance exam
Begin by short-circuiting if the course does not have an entrance exam Begin by short-circuiting if the course does not have an entrance exam
...@@ -38,7 +38,7 @@ def user_can_skip_entrance_exam(request, user, course): ...@@ -38,7 +38,7 @@ def user_can_skip_entrance_exam(request, user, course):
return True return True
if EntranceExamConfiguration.user_can_skip_entrance_exam(user, course.id): if EntranceExamConfiguration.user_can_skip_entrance_exam(user, course.id):
return True return True
if not get_entrance_exam_content(request, course): if not get_entrance_exam_content(user, course):
return True return True
return False return False
...@@ -66,7 +66,7 @@ def user_must_complete_entrance_exam(request, user, course): ...@@ -66,7 +66,7 @@ def user_must_complete_entrance_exam(request, user, course):
whether or not the user is allowed to clear the Entrance Exam gate and access the rest of the course. whether or not the user is allowed to clear the Entrance Exam gate and access the rest of the course.
""" """
# First, let's see if the user is allowed to skip # First, let's see if the user is allowed to skip
if user_can_skip_entrance_exam(request, user, course): if user_can_skip_entrance_exam(user, course):
return False return False
# If they can't actually skip the exam, we'll need to see if they've already passed it # If they can't actually skip the exam, we'll need to see if they've already passed it
if user_has_passed_entrance_exam(request, course): if user_has_passed_entrance_exam(request, course):
...@@ -157,11 +157,11 @@ def get_entrance_exam_score(request, course): ...@@ -157,11 +157,11 @@ def get_entrance_exam_score(request, course):
return _calculate_entrance_exam_score(request.user, course, exam_modules) return _calculate_entrance_exam_score(request.user, course, exam_modules)
def get_entrance_exam_content(request, course): def get_entrance_exam_content(user, course):
""" """
Get the entrance exam content information (ie, chapter module) Get the entrance exam content information (ie, chapter module)
""" """
required_content = get_required_content(course, request.user) required_content = get_required_content(course, user)
exam_module = None exam_module = None
for content in required_content: for content in required_content:
......
"""
Exception classes used in lms/courseware.
"""
class Redirect(Exception):
"""
Exception class that requires redirecting to a URL.
"""
def __init__(self, url):
super(Redirect, self).__init__()
self.url = url
...@@ -18,7 +18,7 @@ class RedirectUnenrolledMiddleware(object): ...@@ -18,7 +18,7 @@ class RedirectUnenrolledMiddleware(object):
course_key = exception.course_key course_key = exception.course_key
return redirect( return redirect(
reverse( reverse(
'courseware.views.course_about', 'courseware.views.views.course_about',
args=[course_key.to_deprecated_string()] args=[course_key.to_deprecated_string()]
) )
) )
...@@ -123,13 +123,20 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_ ...@@ -123,13 +123,20 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_
Create a table of contents from the module store Create a table of contents from the module store
Return format: Return format:
[ {'display_name': name, 'url_name': url_name, { 'chapters': [
'sections': SECTIONS, 'active': bool}, ... ] {'display_name': name, 'url_name': url_name, 'sections': SECTIONS, 'active': bool},
],
'previous_of_active_section': {..},
'next_of_active_section': {..}
}
where SECTIONS is a list where SECTIONS is a list
[ {'display_name': name, 'url_name': url_name, [ {'display_name': name, 'url_name': url_name,
'format': format, 'due': due, 'active' : bool, 'graded': bool}, ...] 'format': format, 'due': due, 'active' : bool, 'graded': bool}, ...]
where previous_of_active_section and next_of_active_section have information on the
next/previous sections of the active section.
active is set for the section and chapter corresponding to the passed active is set for the section and chapter corresponding to the passed
parameters, which are expected to be url_names of the chapter+section. parameters, which are expected to be url_names of the chapter+section.
Everything else comes from the xml, or defaults to "". Everything else comes from the xml, or defaults to "".
...@@ -139,7 +146,7 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_ ...@@ -139,7 +146,7 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_
NOTE: assumes that if we got this far, user has access to course. Returns NOTE: assumes that if we got this far, user has access to course. Returns
None if this is not the case. None if this is not the case.
field_data_cache must include data from the course module and 2 levels of its descendents field_data_cache must include data from the course module and 2 levels of its descendants
''' '''
with modulestore().bulk_operations(course.id): with modulestore().bulk_operations(course.id):
...@@ -221,7 +228,11 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_ ...@@ -221,7 +228,11 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_
'sections': sections, 'sections': sections,
'active': chapter.url_name == active_chapter 'active': chapter.url_name == active_chapter
}) })
return toc_chapters, previous_of_active_section, next_of_active_section return {
'chapters': toc_chapters,
'previous_of_active_section': previous_of_active_section,
'next_of_active_section': next_of_active_section,
}
def _add_timed_exam_info(user, course, section, section_context): def _add_timed_exam_info(user, course, section, section_context):
......
...@@ -28,7 +28,7 @@ from courseware.tests.factories import ( ...@@ -28,7 +28,7 @@ from courseware.tests.factories import (
StaffFactory, StaffFactory,
UserFactory, UserFactory,
) )
import courseware.views as views import courseware.views.views as views
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from edxmako.tests import mako_middleware_process_request from edxmako.tests import mako_middleware_process_request
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
......
...@@ -62,7 +62,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest ...@@ -62,7 +62,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest
parent=self.course, parent=self.course,
display_name='Overview' display_name='Overview'
) )
ItemFactory.create( self.welcome = ItemFactory.create(
parent=self.chapter, parent=self.chapter,
display_name='Welcome' display_name='Welcome'
) )
...@@ -250,7 +250,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest ...@@ -250,7 +250,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest
kwargs={ kwargs={
'course_id': unicode(self.course.id), 'course_id': unicode(self.course.id),
'chapter': self.chapter.location.name, 'chapter': self.chapter.location.name,
'section': self.chapter_subsection.location.name 'section': self.welcome.location.name
}) })
resp = self.client.get(url) resp = self.client.get(url)
self.assertRedirects(resp, expected_url, status_code=302, target_status_code=200) self.assertRedirects(resp, expected_url, status_code=302, target_status_code=200)
...@@ -278,14 +278,14 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest ...@@ -278,14 +278,14 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest
""" """
test get entrance exam content method test get entrance exam content method
""" """
exam_chapter = get_entrance_exam_content(self.request, self.course) exam_chapter = get_entrance_exam_content(self.request.user, self.course)
self.assertEqual(exam_chapter.url_name, self.entrance_exam.url_name) self.assertEqual(exam_chapter.url_name, self.entrance_exam.url_name)
self.assertFalse(user_has_passed_entrance_exam(self.request, self.course)) self.assertFalse(user_has_passed_entrance_exam(self.request, self.course))
answer_entrance_exam_problem(self.course, self.request, self.problem_1) answer_entrance_exam_problem(self.course, self.request, self.problem_1)
answer_entrance_exam_problem(self.course, self.request, self.problem_2) answer_entrance_exam_problem(self.course, self.request, self.problem_2)
exam_chapter = get_entrance_exam_content(self.request, self.course) exam_chapter = get_entrance_exam_content(self.request.user, self.course)
self.assertEqual(exam_chapter, None) self.assertEqual(exam_chapter, None)
self.assertTrue(user_has_passed_entrance_exam(self.request, self.course)) self.assertTrue(user_has_passed_entrance_exam(self.request, self.course))
...@@ -314,7 +314,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest ...@@ -314,7 +314,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest
kwargs={ kwargs={
'course_id': unicode(self.course.id), 'course_id': unicode(self.course.id),
'chapter': self.entrance_exam.location.name, 'chapter': self.entrance_exam.location.name,
'section': self.exam_1.location.name 'section': self.exam_1.location.name,
} }
) )
resp = self.client.get(url) resp = self.client.get(url)
...@@ -457,11 +457,13 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest ...@@ -457,11 +457,13 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest
kwargs={'course_id': unicode(self.course.id), 'chapter': self.chapter.url_name} kwargs={'course_id': unicode(self.course.id), 'chapter': self.chapter.url_name}
) )
response = self.client.get(url) response = self.client.get(url)
redirect_url = reverse('courseware', args=[unicode(self.course.id)]) expected_url = reverse('courseware_section',
self.assertRedirects(response, redirect_url, status_code=302, target_status_code=302) kwargs={
response = self.client.get(redirect_url) 'course_id': unicode(self.course.id),
exam_url = response.get('Location') 'chapter': self.entrance_exam.location.name,
self.assertRedirects(response, exam_url) 'section': self.exam_1.location.name
})
self.assertRedirects(response, expected_url, status_code=302, target_status_code=200)
@patch('courseware.entrance_exams.user_has_passed_entrance_exam', Mock(return_value=False)) @patch('courseware.entrance_exams.user_has_passed_entrance_exam', Mock(return_value=False))
def test_courseinfo_page_access_without_passing_entrance_exam(self): def test_courseinfo_page_access_without_passing_entrance_exam(self):
...@@ -516,7 +518,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest ...@@ -516,7 +518,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest
""" """
Test can_skip_entrance_exam method with anonymous user Test can_skip_entrance_exam method with anonymous user
""" """
self.assertFalse(user_can_skip_entrance_exam(self.request, self.anonymous_user, self.course)) self.assertFalse(user_can_skip_entrance_exam(self.anonymous_user, self.course))
def test_has_passed_entrance_exam_with_anonymous_user(self): def test_has_passed_entrance_exam_with_anonymous_user(self):
""" """
...@@ -583,7 +585,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest ...@@ -583,7 +585,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest
self.request.user, self.request.user,
self.entrance_exam self.entrance_exam
) )
toc, __, __ = toc_for_course( toc = toc_for_course(
self.request.user, self.request.user,
self.request, self.request,
self.course, self.course,
...@@ -591,7 +593,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest ...@@ -591,7 +593,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest
self.exam_1.url_name, self.exam_1.url_name,
self.field_data_cache self.field_data_cache
) )
return toc return toc['chapters']
def answer_entrance_exam_problem(course, request, problem, user=None): def answer_entrance_exam_problem(course, request, problem, user=None):
......
...@@ -11,7 +11,7 @@ from django.conf import settings ...@@ -11,7 +11,7 @@ from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from courseware.tests import BaseTestXmodule from courseware.tests import BaseTestXmodule
from courseware.views import get_course_lti_endpoints from courseware.views.views import get_course_lti_endpoints
from lms.djangoapps.lms_xblock.runtime import quote_slashes from lms.djangoapps.lms_xblock.runtime import quote_slashes
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
......
...@@ -668,13 +668,13 @@ class TestTOC(ModuleStoreTestCase): ...@@ -668,13 +668,13 @@ class TestTOC(ModuleStoreTestCase):
course = self.store.get_course(self.toy_course.id, depth=2) course = self.store.get_course(self.toy_course.id, depth=2)
with check_mongo_calls(toc_finds): with check_mongo_calls(toc_finds):
actual, prev_sequential, next_sequential = render.toc_for_course( actual = render.toc_for_course(
self.request.user, self.request, course, self.chapter, None, self.field_data_cache self.request.user, self.request, course, self.chapter, None, self.field_data_cache
) )
for toc_section in expected: for toc_section in expected:
self.assertIn(toc_section, actual) self.assertIn(toc_section, actual['chapters'])
self.assertIsNone(prev_sequential) self.assertIsNone(actual['previous_of_active_section'])
self.assertIsNone(next_sequential) self.assertIsNone(actual['next_of_active_section'])
# Mongo makes 3 queries to load the course to depth 2: # Mongo makes 3 queries to load the course to depth 2:
# - 1 for the course # - 1 for the course
...@@ -709,13 +709,13 @@ class TestTOC(ModuleStoreTestCase): ...@@ -709,13 +709,13 @@ class TestTOC(ModuleStoreTestCase):
'url_name': 'secret:magic', 'display_name': 'secret:magic', 'display_id': 'secretmagic'}]) 'url_name': 'secret:magic', 'display_name': 'secret:magic', 'display_id': 'secretmagic'}])
with check_mongo_calls(toc_finds): with check_mongo_calls(toc_finds):
actual, prev_sequential, next_sequential = render.toc_for_course( actual = render.toc_for_course(
self.request.user, self.request, self.toy_course, self.chapter, section, self.field_data_cache self.request.user, self.request, self.toy_course, self.chapter, section, self.field_data_cache
) )
for toc_section in expected: for toc_section in expected:
self.assertIn(toc_section, actual) self.assertIn(toc_section, actual['chapters'])
self.assertEquals(prev_sequential['url_name'], 'Toy_Videos') self.assertEquals(actual['previous_of_active_section']['url_name'], 'Toy_Videos')
self.assertEquals(next_sequential['url_name'], 'video_123456789012') self.assertEquals(actual['next_of_active_section']['url_name'], 'video_123456789012')
@attr('shard_1') @attr('shard_1')
...@@ -856,7 +856,7 @@ class TestProctoringRendering(SharedModuleStoreTestCase): ...@@ -856,7 +856,7 @@ class TestProctoringRendering(SharedModuleStoreTestCase):
""" """
self._setup_test_data(enrollment_mode, is_practice_exam, attempt_status) self._setup_test_data(enrollment_mode, is_practice_exam, attempt_status)
actual, prev_sequential, next_sequential = render.toc_for_course( actual = render.toc_for_course(
self.request.user, self.request.user,
self.request, self.request,
self.toy_course, self.toy_course,
...@@ -864,15 +864,15 @@ class TestProctoringRendering(SharedModuleStoreTestCase): ...@@ -864,15 +864,15 @@ class TestProctoringRendering(SharedModuleStoreTestCase):
'Toy_Videos', 'Toy_Videos',
self.field_data_cache self.field_data_cache
) )
section_actual = self._find_section(actual, 'Overview', 'Toy_Videos') section_actual = self._find_section(actual['chapters'], 'Overview', 'Toy_Videos')
if expected: if expected:
self.assertIn(expected, [section_actual['proctoring']]) self.assertIn(expected, [section_actual['proctoring']])
else: else:
# we expect there not to be a 'proctoring' key in the dict # we expect there not to be a 'proctoring' key in the dict
self.assertNotIn('proctoring', section_actual) self.assertNotIn('proctoring', section_actual)
self.assertIsNone(prev_sequential) self.assertIsNone(actual['previous_of_active_section'])
self.assertEquals(next_sequential['url_name'], u"Welcome") self.assertEquals(actual['next_of_active_section']['url_name'], u"Welcome")
@ddt.data( @ddt.data(
( (
...@@ -1114,7 +1114,7 @@ class TestGatedSubsectionRendering(SharedModuleStoreTestCase, MilestonesTestCase ...@@ -1114,7 +1114,7 @@ class TestGatedSubsectionRendering(SharedModuleStoreTestCase, MilestonesTestCase
""" """
Test generation of TOC for a course with a gated subsection Test generation of TOC for a course with a gated subsection
""" """
actual, prev_sequential, next_sequential = render.toc_for_course( actual = render.toc_for_course(
self.request.user, self.request.user,
self.request, self.request,
self.course, self.course,
...@@ -1122,11 +1122,11 @@ class TestGatedSubsectionRendering(SharedModuleStoreTestCase, MilestonesTestCase ...@@ -1122,11 +1122,11 @@ class TestGatedSubsectionRendering(SharedModuleStoreTestCase, MilestonesTestCase
self.open_seq.display_name, self.open_seq.display_name,
self.field_data_cache self.field_data_cache
) )
self.assertIsNotNone(self._find_sequential(actual, 'Chapter', 'Open_Sequential')) self.assertIsNotNone(self._find_sequential(actual['chapters'], 'Chapter', 'Open_Sequential'))
self.assertIsNone(self._find_sequential(actual, 'Chapter', 'Gated_Sequential')) self.assertIsNone(self._find_sequential(actual['chapters'], 'Chapter', 'Gated_Sequential'))
self.assertIsNone(self._find_sequential(actual, 'Non-existant_Chapter', 'Non-existant_Sequential')) self.assertIsNone(self._find_sequential(actual['chapters'], 'Non-existent_Chapter', 'Non-existent_Sequential'))
self.assertIsNone(prev_sequential) self.assertIsNone(actual['previous_of_active_section'])
self.assertIsNone(next_sequential) self.assertIsNone(actual['next_of_active_section'])
@attr('shard_1') @attr('shard_1')
......
...@@ -44,7 +44,7 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -44,7 +44,7 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
cls.section9 = ItemFactory.create(parent=cls.chapter9, cls.section9 = ItemFactory.create(parent=cls.chapter9,
display_name='factory_section') display_name='factory_section')
cls.unit0 = ItemFactory.create(parent=cls.section0, cls.unit0 = ItemFactory.create(parent=cls.section0,
display_name='New Unit') display_name='New Unit 0')
cls.chapterchrome = ItemFactory.create(parent=cls.course, cls.chapterchrome = ItemFactory.create(parent=cls.course,
display_name='Chrome') display_name='Chrome')
...@@ -119,6 +119,7 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -119,6 +119,7 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
'section': displayname, 'section': displayname,
})) }))
self.assertEquals('course-tabs' in response.content, tabs) self.assertEquals('course-tabs' in response.content, tabs)
self.assertEquals('course-navigation' in response.content, accordion)
self.assertTabInactive('progress', response) self.assertTabInactive('progress', response)
self.assertTabActive('courseware', response) self.assertTabActive('courseware', response)
...@@ -165,7 +166,6 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -165,7 +166,6 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
resp = self.client.get(reverse('courseware', resp = self.client.get(reverse('courseware',
kwargs={'course_id': self.course.id.to_deprecated_string()})) kwargs={'course_id': self.course.id.to_deprecated_string()}))
self.assertRedirects(resp, reverse( self.assertRedirects(resp, reverse(
'courseware_section', kwargs={'course_id': self.course.id.to_deprecated_string(), 'courseware_section', kwargs={'course_id': self.course.id.to_deprecated_string(),
'chapter': 'Overview', 'chapter': 'Overview',
...@@ -174,30 +174,26 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -174,30 +174,26 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
def test_redirects_second_time(self): def test_redirects_second_time(self):
""" """
Verify the accordion remembers we've already visited the Welcome section Verify the accordion remembers we've already visited the Welcome section
and redirects correpondingly. and redirects correspondingly.
""" """
email, password = self.STUDENT_INFO[0] email, password = self.STUDENT_INFO[0]
self.login(email, password) self.login(email, password)
self.enroll(self.course, True) self.enroll(self.course, True)
self.enroll(self.test_course, True) self.enroll(self.test_course, True)
self.client.get(reverse('courseware_section', kwargs={ section_url = reverse(
'course_id': self.course.id.to_deprecated_string(), 'courseware_section',
'chapter': 'Overview',
'section': 'Welcome',
}))
resp = self.client.get(reverse('courseware',
kwargs={'course_id': self.course.id.to_deprecated_string()}))
redirect_url = reverse(
'courseware_chapter',
kwargs={ kwargs={
'course_id': self.course.id.to_deprecated_string(), 'course_id': self.course.id.to_deprecated_string(),
'chapter': 'Overview' 'chapter': 'Overview',
} 'section': 'Welcome',
},
) )
self.assertRedirects(resp, redirect_url) self.client.get(section_url)
resp = self.client.get(
reverse('courseware', kwargs={'course_id': self.course.id.to_deprecated_string()}),
)
self.assertRedirects(resp, section_url)
def test_accordion_state(self): def test_accordion_state(self):
""" """
...@@ -209,15 +205,15 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -209,15 +205,15 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
self.enroll(self.test_course, True) self.enroll(self.test_course, True)
# Now we directly navigate to a section in a chapter other than 'Overview'. # Now we directly navigate to a section in a chapter other than 'Overview'.
url = reverse( section_url = reverse(
'courseware_section', 'courseware_section',
kwargs={ kwargs={
'course_id': self.course.id.to_deprecated_string(), 'course_id': self.course.id.to_deprecated_string(),
'chapter': 'factory_chapter', 'chapter': 'factory_chapter',
'section': 'factory_section' 'section': 'factory_section',
} }
) )
self.assert_request_status_code(200, url) self.assert_request_status_code(200, section_url)
# And now hitting the courseware tab should redirect to 'factory_chapter' # And now hitting the courseware tab should redirect to 'factory_chapter'
url = reverse( url = reverse(
...@@ -225,15 +221,7 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -225,15 +221,7 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
kwargs={'course_id': self.course.id.to_deprecated_string()} kwargs={'course_id': self.course.id.to_deprecated_string()}
) )
resp = self.client.get(url) resp = self.client.get(url)
self.assertRedirects(resp, section_url)
redirect_url = reverse(
'courseware_chapter',
kwargs={
'course_id': self.course.id.to_deprecated_string(),
'chapter': 'factory_chapter',
}
)
self.assertRedirects(resp, redirect_url)
def test_incomplete_course(self): def test_incomplete_course(self):
email = self.staff_user.email email = self.staff_user.email
...@@ -247,7 +235,8 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -247,7 +235,8 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
'courseware', 'courseware',
kwargs={'course_id': test_course_id} kwargs={'course_id': test_course_id}
) )
self.assert_request_status_code(200, url) response = self.assert_request_status_code(200, url)
self.assertIn("No content has been added to this course", response.content)
section = ItemFactory.create( section = ItemFactory.create(
parent_location=self.test_course.location, parent_location=self.test_course.location,
...@@ -257,21 +246,25 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -257,21 +246,25 @@ class TestNavigation(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
'courseware', 'courseware',
kwargs={'course_id': test_course_id} kwargs={'course_id': test_course_id}
) )
self.assert_request_status_code(200, url) response = self.assert_request_status_code(200, url)
self.assertNotIn("No content has been added to this course", response.content)
self.assertIn("New Section", response.content)
subsection = ItemFactory.create( subsection = ItemFactory.create(
parent_location=section.location, parent_location=section.location,
display_name='New Subsection' display_name='New Subsection',
) )
url = reverse( url = reverse(
'courseware', 'courseware',
kwargs={'course_id': test_course_id} kwargs={'course_id': test_course_id}
) )
self.assert_request_status_code(200, url) response = self.assert_request_status_code(200, url)
self.assertIn("New Subsection", response.content)
self.assertNotIn("sequence-nav", response.content)
ItemFactory.create( ItemFactory.create(
parent_location=subsection.location, parent_location=subsection.location,
display_name='New Unit' display_name='New Unit',
) )
url = reverse( url = reverse(
'courseware', 'courseware',
......
...@@ -6,7 +6,6 @@ from django.core.urlresolvers import reverse ...@@ -6,7 +6,6 @@ from django.core.urlresolvers import reverse
from django.http import Http404 from django.http import Http404
from mock import MagicMock, Mock, patch from mock import MagicMock, Mock, patch
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.courses import get_course_by_id from courseware.courses import get_course_by_id
from courseware.tabs import ( from courseware.tabs import (
...@@ -15,7 +14,7 @@ from courseware.tabs import ( ...@@ -15,7 +14,7 @@ from courseware.tabs import (
) )
from courseware.tests.helpers import get_request_for_user, LoginEnrollmentTestCase from courseware.tests.helpers import get_request_for_user, LoginEnrollmentTestCase
from courseware.tests.factories import InstructorFactory, StaffFactory from courseware.tests.factories import InstructorFactory, StaffFactory
from courseware.views import get_static_tab_contents, static_tab from courseware.views.views import get_static_tab_contents, static_tab
from student.models import CourseEnrollment from student.models import CourseEnrollment
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from util.milestones_helpers import ( from util.milestones_helpers import (
...@@ -272,7 +271,7 @@ class StaticTabDateTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase): ...@@ -272,7 +271,7 @@ class StaticTabDateTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase):
self.assertIn('static_tab', tab_content) self.assertIn('static_tab', tab_content)
# Test when render raises an exception # Test when render raises an exception
with patch('courseware.views.get_module') as mock_module_render: with patch('courseware.views.views.get_module') as mock_module_render:
mock_module_render.return_value = MagicMock( mock_module_render.return_value = MagicMock(
render=Mock(side_effect=Exception('Render failed!')) render=Mock(side_effect=Exception('Render failed!'))
) )
......
...@@ -26,7 +26,7 @@ from xblock.core import XBlock ...@@ -26,7 +26,7 @@ from xblock.core import XBlock
from xblock.fields import String, Scope from xblock.fields import String, Scope
from xblock.fragment import Fragment from xblock.fragment import Fragment
import courseware.views as views import courseware.views.views as views
import shoppingcart import shoppingcart
from certificates import api as certs_api from certificates import api as certs_api
from certificates.models import CertificateStatuses, CertificateGenerationConfiguration from certificates.models import CertificateStatuses, CertificateGenerationConfiguration
...@@ -40,6 +40,7 @@ from courseware.testutils import RenderXBlockTestMixin ...@@ -40,6 +40,7 @@ from courseware.testutils import RenderXBlockTestMixin
from courseware.tests.factories import StudentModuleFactory from courseware.tests.factories import StudentModuleFactory
from courseware.url_helpers import get_redirect_url from courseware.url_helpers import get_redirect_url
from courseware.user_state_client import DjangoXBlockUserStateClient from courseware.user_state_client import DjangoXBlockUserStateClient
from courseware.views.index import render_accordion, CoursewareIndex
from edxmako.tests import mako_middleware_process_request from edxmako.tests import mako_middleware_process_request
from lms.djangoapps.commerce.utils import EcommerceService # pylint: disable=import-error from lms.djangoapps.commerce.utils import EcommerceService # pylint: disable=import-error
from milestones.tests.utils import MilestonesTestCaseMixin from milestones.tests.utils import MilestonesTestCaseMixin
...@@ -255,7 +256,7 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -255,7 +256,7 @@ class ViewsTestCase(ModuleStoreTestCase):
self._verify_index_response(expected_response_code=404, chapter_name='non-existent') self._verify_index_response(expected_response_code=404, chapter_name='non-existent')
def test_index_nonexistent_chapter_masquerade(self): def test_index_nonexistent_chapter_masquerade(self):
with patch('courseware.views.setup_masquerade') as patch_masquerade: with patch('courseware.views.index.setup_masquerade') as patch_masquerade:
masquerade = MagicMock(role='student') masquerade = MagicMock(role='student')
patch_masquerade.return_value = (masquerade, self.user) patch_masquerade.return_value = (masquerade, self.user)
self._verify_index_response(expected_response_code=302, chapter_name='non-existent') self._verify_index_response(expected_response_code=302, chapter_name='non-existent')
...@@ -264,7 +265,7 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -264,7 +265,7 @@ class ViewsTestCase(ModuleStoreTestCase):
self._verify_index_response(expected_response_code=404, section_name='non-existent') self._verify_index_response(expected_response_code=404, section_name='non-existent')
def test_index_nonexistent_section_masquerade(self): def test_index_nonexistent_section_masquerade(self):
with patch('courseware.views.setup_masquerade') as patch_masquerade: with patch('courseware.views.index.setup_masquerade') as patch_masquerade:
masquerade = MagicMock(role='student') masquerade = MagicMock(role='student')
patch_masquerade.return_value = (masquerade, self.user) patch_masquerade.return_value = (masquerade, self.user)
self._verify_index_response(expected_response_code=302, section_name='non-existent') self._verify_index_response(expected_response_code=302, section_name='non-existent')
...@@ -416,14 +417,6 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -416,14 +417,6 @@ class ViewsTestCase(ModuleStoreTestCase):
get_redirect_url(self.course_key, self.section.location), get_redirect_url(self.course_key, self.section.location),
) )
def test_redirect_to_course_position(self):
mock_module = MagicMock()
mock_module.descriptor.id = 'Underwater Basketweaving'
mock_module.position = 3
mock_module.get_display_items.return_value = []
self.assertRaises(Http404, views.redirect_to_course_position,
mock_module, views.CONTENT_DEPTH)
def test_invalid_course_id(self): def test_invalid_course_id(self):
response = self.client.get('/courses/MITx/3.091X/') response = self.client.get('/courses/MITx/3.091X/')
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
...@@ -462,15 +455,6 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -462,15 +455,6 @@ class ViewsTestCase(ModuleStoreTestCase):
response = self.client.get(request_url) response = self.client.get(request_url)
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_registered_for_course(self):
self.assertFalse(views.registered_for_course('Basketweaving', None))
mock_user = MagicMock()
mock_user.is_authenticated.return_value = False
self.assertFalse(views.registered_for_course('dummy', mock_user))
mock_course = MagicMock()
mock_course.id = self.course_key
self.assertTrue(views.registered_for_course(mock_course, self.user))
@override_settings(PAID_COURSE_REGISTRATION_CURRENCY=["USD", "$"]) @override_settings(PAID_COURSE_REGISTRATION_CURRENCY=["USD", "$"])
def test_get_cosmetic_display_price(self): def test_get_cosmetic_display_price(self):
""" """
...@@ -917,10 +901,10 @@ class TestAccordionDueDate(BaseDueDateTests): ...@@ -917,10 +901,10 @@ class TestAccordionDueDate(BaseDueDateTests):
def get_text(self, course): def get_text(self, course):
""" Returns the HTML for the accordion """ """ Returns the HTML for the accordion """
table_of_contents, __, __ = toc_for_course( table_of_contents = toc_for_course(
self.request.user, self.request, course, unicode(course.get_children()[0].scope_ids.usage_id), None, None self.request.user, self.request, course, unicode(course.get_children()[0].scope_ids.usage_id), None, None
) )
return views.render_accordion(self.request, course, table_of_contents) return render_accordion(self.request, course, table_of_contents['chapters'])
@attr('shard_1') @attr('shard_1')
...@@ -1331,7 +1315,7 @@ class GenerateUserCertTests(ModuleStoreTestCase): ...@@ -1331,7 +1315,7 @@ class GenerateUserCertTests(ModuleStoreTestCase):
# status valid code # status valid code
# mocking xqueue and analytics # mocking xqueue and analytics
analytics_patcher = patch('courseware.views.analytics') analytics_patcher = patch('courseware.views.views.analytics')
mock_tracker = analytics_patcher.start() mock_tracker = analytics_patcher.start()
self.addCleanup(analytics_patcher.stop) self.addCleanup(analytics_patcher.stop)
...@@ -1455,7 +1439,7 @@ class ViewCheckerBlock(XBlock): ...@@ -1455,7 +1439,7 @@ class ViewCheckerBlock(XBlock):
@ddt.ddt @ddt.ddt
class TestIndexView(ModuleStoreTestCase): class TestIndexView(ModuleStoreTestCase):
""" """
Tests of the courseware.index view. Tests of the courseware.views.index view.
""" """
@XBlock.register_temp_plugin(ViewCheckerBlock, 'view_checker') @XBlock.register_temp_plugin(ViewCheckerBlock, 'view_checker')
...@@ -1497,7 +1481,9 @@ class TestIndexView(ModuleStoreTestCase): ...@@ -1497,7 +1481,9 @@ class TestIndexView(ModuleStoreTestCase):
mako_middleware_process_request(request) mako_middleware_process_request(request)
# Trigger the assertions embedded in the ViewCheckerBlocks # Trigger the assertions embedded in the ViewCheckerBlocks
response = views.index(request, unicode(course.id), chapter=chapter.url_name, section=section.url_name) response = CoursewareIndex.as_view()(
request, unicode(course.id), chapter=chapter.url_name, section=section.url_name
)
self.assertEquals(response.content.count("ViewCheckerPassed"), 3) self.assertEquals(response.content.count("ViewCheckerPassed"), 3)
@XBlock.register_temp_plugin(ActivateIDCheckerBlock, 'id_checker') @XBlock.register_temp_plugin(ActivateIDCheckerBlock, 'id_checker')
...@@ -1525,7 +1511,9 @@ class TestIndexView(ModuleStoreTestCase): ...@@ -1525,7 +1511,9 @@ class TestIndexView(ModuleStoreTestCase):
request.user = user request.user = user
mako_middleware_process_request(request) mako_middleware_process_request(request)
response = views.index(request, unicode(course.id), chapter=chapter.url_name, section=section.url_name) response = CoursewareIndex.as_view()(
request, unicode(course.id), chapter=chapter.url_name, section=section.url_name
)
self.assertIn("Activate Block ID: test_block_id", response.content) self.assertIn("Activate Block ID: test_block_id", response.content)
...@@ -1546,7 +1534,9 @@ class TestIndexViewWithGating(ModuleStoreTestCase, MilestonesTestCaseMixin): ...@@ -1546,7 +1534,9 @@ class TestIndexViewWithGating(ModuleStoreTestCase, MilestonesTestCaseMixin):
self.store.update_item(self.course, 0) self.store.update_item(self.course, 0)
self.chapter = ItemFactory.create(parent=self.course, category="chapter", display_name="Chapter") self.chapter = ItemFactory.create(parent=self.course, category="chapter", display_name="Chapter")
self.open_seq = ItemFactory.create(parent=self.chapter, category='sequential', display_name="Open Sequential") self.open_seq = ItemFactory.create(parent=self.chapter, category='sequential', display_name="Open Sequential")
ItemFactory.create(parent=self.open_seq, category='problem', display_name="Problem 1")
self.gated_seq = ItemFactory.create(parent=self.chapter, category='sequential', display_name="Gated Sequential") self.gated_seq = ItemFactory.create(parent=self.chapter, category='sequential', display_name="Gated Sequential")
ItemFactory.create(parent=self.gated_seq, category='problem', display_name="Problem 2")
gating_api.add_prerequisite(self.course.id, self.open_seq.location) gating_api.add_prerequisite(self.course.id, self.open_seq.location)
gating_api.set_required_content(self.course.id, self.gated_seq.location, self.open_seq.location, 100) gating_api.set_required_content(self.course.id, self.gated_seq.location, self.open_seq.location, 100)
...@@ -1570,7 +1560,7 @@ class TestIndexViewWithGating(ModuleStoreTestCase, MilestonesTestCaseMixin): ...@@ -1570,7 +1560,7 @@ class TestIndexViewWithGating(ModuleStoreTestCase, MilestonesTestCaseMixin):
mako_middleware_process_request(request) mako_middleware_process_request(request)
with self.assertRaises(Http404): with self.assertRaises(Http404):
__ = views.index( CoursewareIndex.as_view()(
request, request,
unicode(self.course.id), unicode(self.course.id),
chapter=self.chapter.url_name, chapter=self.chapter.url_name,
......
...@@ -21,7 +21,7 @@ from django.utils.translation import ugettext as _ ...@@ -21,7 +21,7 @@ from django.utils.translation import ugettext as _
from edxnotes.exceptions import EdxNotesParseError, EdxNotesServiceUnavailable from edxnotes.exceptions import EdxNotesParseError, EdxNotesServiceUnavailable
from edxnotes.plugins import EdxNotesTab from edxnotes.plugins import EdxNotesTab
from courseware.views import get_current_child from courseware.views.views import get_current_child
from courseware.access import has_access from courseware.access import has_access
from openedx.core.lib.token_utils import get_id_token from openedx.core.lib.token_utils import get_id_token
from student.models import anonymous_id_for_user from student.models import anonymous_id_for_user
......
...@@ -142,7 +142,7 @@ def render_courseware(request, usage_key): ...@@ -142,7 +142,7 @@ def render_courseware(request, usage_key):
context to render the courseware. context to render the courseware.
""" """
# return an HttpResponse object that contains the template and necessary context to render the courseware. # return an HttpResponse object that contains the template and necessary context to render the courseware.
from courseware.views import render_xblock from courseware.views.views import render_xblock
return render_xblock(request, unicode(usage_key), check_if_enrolled=False) return render_xblock(request, unicode(usage_key), check_if_enrolled=False)
......
...@@ -15,7 +15,8 @@ from opaque_keys import InvalidKeyError ...@@ -15,7 +15,8 @@ from opaque_keys import InvalidKeyError
from courseware.access import is_mobile_available_for_user from courseware.access import is_mobile_available_for_user
from courseware.model_data import FieldDataCache from courseware.model_data import FieldDataCache
from courseware.module_render import get_module_for_descriptor from courseware.module_render import get_module_for_descriptor
from courseware.views import get_current_child, save_positions_recursively_up from courseware.views.index import save_positions_recursively_up
from courseware.views.views import get_current_child
from student.models import CourseEnrollment, User from student.models import CourseEnrollment, User
from xblock.fields import Scope from xblock.fields import Scope
......
...@@ -12,6 +12,7 @@ from microsite_configuration import microsite ...@@ -12,6 +12,7 @@ from microsite_configuration import microsite
import auth_exchange.views import auth_exchange.views
from config_models.views import ConfigurationModelCurrentAPIView from config_models.views import ConfigurationModelCurrentAPIView
from courseware.views.index import CoursewareIndex
from openedx.core.djangoapps.programs.models import ProgramsApiConfig from openedx.core.djangoapps.programs.models import ProgramsApiConfig
from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
...@@ -270,14 +271,14 @@ urlpatterns += ( ...@@ -270,14 +271,14 @@ urlpatterns += (
r'^courses/{}/jump_to/(?P<location>.*)$'.format( r'^courses/{}/jump_to/(?P<location>.*)$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.jump_to', 'courseware.views.views.jump_to',
name='jump_to', name='jump_to',
), ),
url( url(
r'^courses/{}/jump_to_id/(?P<module_id>.*)$'.format( r'^courses/{}/jump_to_id/(?P<module_id>.*)$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.jump_to_id', 'courseware.views.views.jump_to_id',
name='jump_to_id', name='jump_to_id',
), ),
...@@ -317,7 +318,7 @@ urlpatterns += ( ...@@ -317,7 +318,7 @@ urlpatterns += (
# Note: This is not an API. Compare this with the xblock_view API above. # Note: This is not an API. Compare this with the xblock_view API above.
url( url(
r'^xblock/{usage_key_string}$'.format(usage_key_string=settings.USAGE_KEY_PATTERN), r'^xblock/{usage_key_string}$'.format(usage_key_string=settings.USAGE_KEY_PATTERN),
'courseware.views.render_xblock', 'courseware.views.views.render_xblock',
name='render_xblock', name='render_xblock',
), ),
...@@ -361,7 +362,7 @@ urlpatterns += ( ...@@ -361,7 +362,7 @@ urlpatterns += (
r'^courses/{}/about$'.format( r'^courses/{}/about$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.course_about', 'courseware.views.views.course_about',
name='about_course', name='about_course',
), ),
...@@ -370,14 +371,14 @@ urlpatterns += ( ...@@ -370,14 +371,14 @@ urlpatterns += (
r'^courses/{}/$'.format( r'^courses/{}/$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.course_info', 'courseware.views.views.course_info',
name='course_root', name='course_root',
), ),
url( url(
r'^courses/{}/info$'.format( r'^courses/{}/info$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.course_info', 'courseware.views.views.course_info',
name='info', name='info',
), ),
# TODO arjun remove when custom tabs in place, see courseware/courses.py # TODO arjun remove when custom tabs in place, see courseware/courses.py
...@@ -385,7 +386,7 @@ urlpatterns += ( ...@@ -385,7 +386,7 @@ urlpatterns += (
r'^courses/{}/syllabus$'.format( r'^courses/{}/syllabus$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.syllabus', 'courseware.views.views.syllabus',
name='syllabus', name='syllabus',
), ),
...@@ -394,7 +395,7 @@ urlpatterns += ( ...@@ -394,7 +395,7 @@ urlpatterns += (
r'^courses/{}/survey$'.format( r'^courses/{}/survey$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.course_survey', 'courseware.views.views.course_survey',
name='course_survey', name='course_survey',
), ),
...@@ -462,28 +463,28 @@ urlpatterns += ( ...@@ -462,28 +463,28 @@ urlpatterns += (
r'^courses/{}/courseware/?$'.format( r'^courses/{}/courseware/?$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.index', CoursewareIndex.as_view(),
name='courseware', name='courseware',
), ),
url( url(
r'^courses/{}/courseware/(?P<chapter>[^/]*)/$'.format( r'^courses/{}/courseware/(?P<chapter>[^/]*)/$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.index', CoursewareIndex.as_view(),
name='courseware_chapter', name='courseware_chapter',
), ),
url( url(
r'^courses/{}/courseware/(?P<chapter>[^/]*)/(?P<section>[^/]*)/$'.format( r'^courses/{}/courseware/(?P<chapter>[^/]*)/(?P<section>[^/]*)/$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.index', CoursewareIndex.as_view(),
name='courseware_section', name='courseware_section',
), ),
url( url(
r'^courses/{}/courseware/(?P<chapter>[^/]*)/(?P<section>[^/]*)/(?P<position>[^/]*)/?$'.format( r'^courses/{}/courseware/(?P<chapter>[^/]*)/(?P<section>[^/]*)/(?P<position>[^/]*)/?$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.index', CoursewareIndex.as_view(),
name='courseware_position', name='courseware_position',
), ),
...@@ -491,7 +492,7 @@ urlpatterns += ( ...@@ -491,7 +492,7 @@ urlpatterns += (
r'^courses/{}/progress$'.format( r'^courses/{}/progress$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.progress', 'courseware.views.views.progress',
name='progress', name='progress',
), ),
# Takes optional student_id for instructor use--shows profile as that student sees it. # Takes optional student_id for instructor use--shows profile as that student sees it.
...@@ -499,7 +500,7 @@ urlpatterns += ( ...@@ -499,7 +500,7 @@ urlpatterns += (
r'^courses/{}/progress/(?P<student_id>[^/]*)/$'.format( r'^courses/{}/progress/(?P<student_id>[^/]*)/$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.progress', 'courseware.views.views.progress',
name='student_progress', name='student_progress',
), ),
...@@ -637,7 +638,7 @@ urlpatterns += ( ...@@ -637,7 +638,7 @@ urlpatterns += (
r'^courses/{}/lti_rest_endpoints/'.format( r'^courses/{}/lti_rest_endpoints/'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.get_course_lti_endpoints', 'courseware.views.views.get_course_lti_endpoints',
name='lti_rest_endpoints', name='lti_rest_endpoints',
), ),
...@@ -702,7 +703,7 @@ urlpatterns += ( ...@@ -702,7 +703,7 @@ urlpatterns += (
r'^courses/{}/generate_user_cert'.format( r'^courses/{}/generate_user_cert'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.generate_user_cert', 'courseware.views.views.generate_user_cert',
name='generate_user_cert', name='generate_user_cert',
), ),
) )
...@@ -755,7 +756,7 @@ urlpatterns += ( ...@@ -755,7 +756,7 @@ urlpatterns += (
r'^courses/{}/(?P<tab_slug>[^/]+)/$'.format( r'^courses/{}/(?P<tab_slug>[^/]+)/$'.format(
settings.COURSE_ID_PATTERN, settings.COURSE_ID_PATTERN,
), ),
'courseware.views.static_tab', 'courseware.views.views.static_tab',
name='static_tab', name='static_tab',
), ),
) )
...@@ -766,7 +767,7 @@ if settings.FEATURES.get('ENABLE_STUDENT_HISTORY_VIEW'): ...@@ -766,7 +767,7 @@ if settings.FEATURES.get('ENABLE_STUDENT_HISTORY_VIEW'):
r'^courses/{}/submission_history/(?P<student_username>[^/]*)/(?P<location>.*?)$'.format( r'^courses/{}/submission_history/(?P<student_username>[^/]*)/(?P<location>.*?)$'.format(
settings.COURSE_ID_PATTERN settings.COURSE_ID_PATTERN
), ),
'courseware.views.submission_history', 'courseware.views.views.submission_history',
name='submission_history', name='submission_history',
), ),
) )
...@@ -999,17 +1000,17 @@ if settings.FEATURES.get('ENABLE_FINANCIAL_ASSISTANCE_FORM'): ...@@ -999,17 +1000,17 @@ if settings.FEATURES.get('ENABLE_FINANCIAL_ASSISTANCE_FORM'):
urlpatterns += ( urlpatterns += (
url( url(
r'^financial-assistance/$', r'^financial-assistance/$',
'courseware.views.financial_assistance', 'courseware.views.views.financial_assistance',
name='financial_assistance' name='financial_assistance'
), ),
url( url(
r'^financial-assistance/apply/$', r'^financial-assistance/apply/$',
'courseware.views.financial_assistance_form', 'courseware.views.views.financial_assistance_form',
name='financial_assistance_form' name='financial_assistance_form'
), ),
url( url(
r'^financial-assistance/submit/$', r'^financial-assistance/submit/$',
'courseware.views.financial_assistance_request', 'courseware.views.views.financial_assistance_request',
name='submit_financial_assistance_request' name='submit_financial_assistance_request'
) )
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment