Commit 1dfe9ed9 by Kyle McCormick

MA-779 Update student dashboard to use CourseOverview

parent 5b630a77
...@@ -23,8 +23,9 @@ VERIFY_STATUS_MISSED_DEADLINE = "verify_missed_deadline" ...@@ -23,8 +23,9 @@ VERIFY_STATUS_MISSED_DEADLINE = "verify_missed_deadline"
VERIFY_STATUS_NEED_TO_REVERIFY = "verify_need_to_reverify" VERIFY_STATUS_NEED_TO_REVERIFY = "verify_need_to_reverify"
def check_verify_status_by_course(user, course_enrollment_pairs, all_course_modes): def check_verify_status_by_course(user, course_enrollments, all_course_modes):
"""Determine the per-course verification statuses for a given user. """
Determine the per-course verification statuses for a given user.
The possible statuses are: The possible statuses are:
* VERIFY_STATUS_NEED_TO_VERIFY: The student has not yet submitted photos for verification. * VERIFY_STATUS_NEED_TO_VERIFY: The student has not yet submitted photos for verification.
...@@ -46,8 +47,7 @@ def check_verify_status_by_course(user, course_enrollment_pairs, all_course_mode ...@@ -46,8 +47,7 @@ def check_verify_status_by_course(user, course_enrollment_pairs, all_course_mode
Arguments: Arguments:
user (User): The currently logged-in user. user (User): The currently logged-in user.
course_enrollment_pairs (list): The courses the user is enrolled in. course_enrollments (list[CourseEnrollment]): The courses the user is enrolled in.
The list should contain tuples of `(Course, CourseEnrollment)`.
all_course_modes (list): List of all course modes for the student's enrolled courses, all_course_modes (list): List of all course modes for the student's enrolled courses,
including modes that have expired. including modes that have expired.
...@@ -75,15 +75,15 @@ def check_verify_status_by_course(user, course_enrollment_pairs, all_course_mode ...@@ -75,15 +75,15 @@ def check_verify_status_by_course(user, course_enrollment_pairs, all_course_mode
recent_verification_datetime = None recent_verification_datetime = None
for course, enrollment in course_enrollment_pairs: for enrollment in course_enrollments:
# Get the verified mode (if any) for this course # Get the verified mode (if any) for this course
# We pass in the course modes we have already loaded to avoid # We pass in the course modes we have already loaded to avoid
# another database hit, as well as to ensure that expired # another database hit, as well as to ensure that expired
# course modes are included in the search. # course modes are included in the search.
verified_mode = CourseMode.verified_mode_for_course( verified_mode = CourseMode.verified_mode_for_course(
course.id, enrollment.course_id,
modes=all_course_modes[course.id] modes=all_course_modes[enrollment.course_id]
) )
# If no verified mode has ever been offered, or the user hasn't enrolled # If no verified mode has ever been offered, or the user hasn't enrolled
...@@ -156,7 +156,7 @@ def check_verify_status_by_course(user, course_enrollment_pairs, all_course_mode ...@@ -156,7 +156,7 @@ def check_verify_status_by_course(user, course_enrollment_pairs, all_course_mode
if deadline is not None and deadline > now: if deadline is not None and deadline > now:
days_until_deadline = (deadline - now).days days_until_deadline = (deadline - now).days
status_by_course[course.id] = { status_by_course[enrollment.course_id] = {
'status': status, 'status': status,
'days_until_deadline': days_until_deadline 'days_until_deadline': days_until_deadline
} }
......
...@@ -850,6 +850,13 @@ class CourseEnrollment(models.Model): ...@@ -850,6 +850,13 @@ class CourseEnrollment(models.Model):
unique_together = (('user', 'course_id'),) unique_together = (('user', 'course_id'),)
ordering = ('user', 'course_id') ordering = ('user', 'course_id')
def __init__(self, *args, **kwargs):
super(CourseEnrollment, self).__init__(*args, **kwargs)
# Private variable for storing course_overview to minimize calls to the database.
# When the property .course_overview is accessed for the first time, this variable will be set.
self._course_overview = None
def __unicode__(self): def __unicode__(self):
return ( return (
"[CourseEnrollment] {}: {} ({}); active: ({})" "[CourseEnrollment] {}: {} ({}); active: ({})"
...@@ -1318,10 +1325,21 @@ class CourseEnrollment(models.Model): ...@@ -1318,10 +1325,21 @@ class CourseEnrollment(models.Model):
@property @property
def course_overview(self): def course_overview(self):
""" """
Return a CourseOverview of this enrollment's course. Returns a CourseOverview of the course to which this enrollment refers.
Returns None if an error occurred while trying to load the course.
Note:
If the course is re-published within the lifetime of this
CourseEnrollment object, then the value of this property will
become stale.
""" """
if not self._course_overview:
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
return CourseOverview.get_from_id(self.course_id) try:
self._course_overview = CourseOverview.get_from_id(self.course_id)
except (CourseOverview.DoesNotExist, IOError):
self._course_overview = None
return self._course_overview
def is_verified_enrollment(self): def is_verified_enrollment(self):
""" """
......
...@@ -14,7 +14,7 @@ from xmodule.modulestore.django import modulestore ...@@ -14,7 +14,7 @@ from xmodule.modulestore.django import modulestore
from xmodule.error_module import ErrorDescriptor from xmodule.error_module import ErrorDescriptor
from django.test.client import Client from django.test.client import Client
from student.models import CourseEnrollment from student.models import CourseEnrollment
from student.views import get_course_enrollment_pairs from student.views import get_course_enrollments
from util.milestones_helpers import ( from util.milestones_helpers import (
get_pre_requisite_courses_not_completed, get_pre_requisite_courses_not_completed,
set_prerequisite_courses, set_prerequisite_courses,
...@@ -73,13 +73,13 @@ class TestCourseListing(ModuleStoreTestCase): ...@@ -73,13 +73,13 @@ class TestCourseListing(ModuleStoreTestCase):
self._create_course_with_access_groups(course_location) self._create_course_with_access_groups(course_location)
# get dashboard # get dashboard
courses_list = list(get_course_enrollment_pairs(self.student, None, [])) courses_list = list(get_course_enrollments(self.student, None, []))
self.assertEqual(len(courses_list), 1) self.assertEqual(len(courses_list), 1)
self.assertEqual(courses_list[0][0].id, course_location) self.assertEqual(courses_list[0].course_id, course_location)
CourseEnrollment.unenroll(self.student, course_location) CourseEnrollment.unenroll(self.student, course_location)
# get dashboard # get dashboard
courses_list = list(get_course_enrollment_pairs(self.student, None, [])) courses_list = list(get_course_enrollments(self.student, None, []))
self.assertEqual(len(courses_list), 0) self.assertEqual(len(courses_list), 0)
def test_errored_course_regular_access(self): def test_errored_course_regular_access(self):
...@@ -95,7 +95,7 @@ class TestCourseListing(ModuleStoreTestCase): ...@@ -95,7 +95,7 @@ class TestCourseListing(ModuleStoreTestCase):
self.assertIsInstance(modulestore().get_course(course_key), ErrorDescriptor) self.assertIsInstance(modulestore().get_course(course_key), ErrorDescriptor)
# get courses through iterating all courses # get courses through iterating all courses
courses_list = list(get_course_enrollment_pairs(self.student, None, [])) courses_list = list(get_course_enrollments(self.student, None, []))
self.assertEqual(courses_list, []) self.assertEqual(courses_list, [])
def test_course_listing_errored_deleted_courses(self): def test_course_listing_errored_deleted_courses(self):
...@@ -112,9 +112,9 @@ class TestCourseListing(ModuleStoreTestCase): ...@@ -112,9 +112,9 @@ class TestCourseListing(ModuleStoreTestCase):
self._create_course_with_access_groups(course_location, default_store=ModuleStoreEnum.Type.mongo) self._create_course_with_access_groups(course_location, default_store=ModuleStoreEnum.Type.mongo)
mongo_store.delete_course(course_location, ModuleStoreEnum.UserID.test) mongo_store.delete_course(course_location, ModuleStoreEnum.UserID.test)
courses_list = list(get_course_enrollment_pairs(self.student, None, [])) courses_list = list(get_course_enrollments(self.student, None, []))
self.assertEqual(len(courses_list), 1, courses_list) self.assertEqual(len(courses_list), 1, courses_list)
self.assertEqual(courses_list[0][0].id, good_location) self.assertEqual(courses_list[0].course_id, good_location)
@mock.patch.dict("django.conf.settings.FEATURES", {'ENABLE_PREREQUISITE_COURSES': True, 'MILESTONES_APP': True}) @mock.patch.dict("django.conf.settings.FEATURES", {'ENABLE_PREREQUISITE_COURSES': True, 'MILESTONES_APP': True})
def test_course_listing_has_pre_requisite_courses(self): def test_course_listing_has_pre_requisite_courses(self):
...@@ -142,9 +142,11 @@ class TestCourseListing(ModuleStoreTestCase): ...@@ -142,9 +142,11 @@ class TestCourseListing(ModuleStoreTestCase):
set_prerequisite_courses(course_location, pre_requisite_courses) set_prerequisite_courses(course_location, pre_requisite_courses)
# get dashboard # get dashboard
course_enrollment_pairs = list(get_course_enrollment_pairs(self.student, None, [])) course_enrollments = list(get_course_enrollments(self.student, None, []))
courses_having_prerequisites = frozenset(course.id for course, _enrollment in course_enrollment_pairs courses_having_prerequisites = frozenset(
if course.pre_requisite_courses) enrollment.course_id for enrollment in course_enrollments
if enrollment.course_overview.pre_requisite_courses
)
courses_requirements_not_met = get_pre_requisite_courses_not_completed( courses_requirements_not_met = get_pre_requisite_courses_not_completed(
self.student, self.student,
courses_having_prerequisites courses_having_prerequisites
......
...@@ -15,7 +15,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase ...@@ -15,7 +15,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from course_modes.tests.factories import CourseModeFactory from course_modes.tests.factories import CourseModeFactory
from student.models import CourseEnrollment, DashboardConfiguration from student.models import CourseEnrollment, DashboardConfiguration
from student.views import get_course_enrollment_pairs, _get_recently_enrolled_courses from student.views import get_course_enrollments, _get_recently_enrolled_courses # pylint: disable=protected-access
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
...@@ -67,7 +67,7 @@ class TestRecentEnrollments(ModuleStoreTestCase): ...@@ -67,7 +67,7 @@ class TestRecentEnrollments(ModuleStoreTestCase):
self._configure_message_timeout(60) self._configure_message_timeout(60)
# get courses through iterating all courses # get courses through iterating all courses
courses_list = list(get_course_enrollment_pairs(self.student, None, [])) courses_list = list(get_course_enrollments(self.student, None, []))
self.assertEqual(len(courses_list), 2) self.assertEqual(len(courses_list), 2)
recent_course_list = _get_recently_enrolled_courses(courses_list) recent_course_list = _get_recently_enrolled_courses(courses_list)
...@@ -78,7 +78,7 @@ class TestRecentEnrollments(ModuleStoreTestCase): ...@@ -78,7 +78,7 @@ class TestRecentEnrollments(ModuleStoreTestCase):
Tests that the recent enrollment list is empty if configured to zero seconds. Tests that the recent enrollment list is empty if configured to zero seconds.
""" """
self._configure_message_timeout(0) self._configure_message_timeout(0)
courses_list = list(get_course_enrollment_pairs(self.student, None, [])) courses_list = list(get_course_enrollments(self.student, None, []))
self.assertEqual(len(courses_list), 2) self.assertEqual(len(courses_list), 2)
recent_course_list = _get_recently_enrolled_courses(courses_list) recent_course_list = _get_recently_enrolled_courses(courses_list)
...@@ -106,16 +106,16 @@ class TestRecentEnrollments(ModuleStoreTestCase): ...@@ -106,16 +106,16 @@ class TestRecentEnrollments(ModuleStoreTestCase):
enrollment.save() enrollment.save()
courses.append(course) courses.append(course)
courses_list = list(get_course_enrollment_pairs(self.student, None, [])) courses_list = list(get_course_enrollments(self.student, None, []))
self.assertEqual(len(courses_list), 6) self.assertEqual(len(courses_list), 6)
recent_course_list = _get_recently_enrolled_courses(courses_list) recent_course_list = _get_recently_enrolled_courses(courses_list)
self.assertEqual(len(recent_course_list), 5) self.assertEqual(len(recent_course_list), 5)
self.assertEqual(recent_course_list[1][0], courses[0]) self.assertEqual(recent_course_list[1].course, courses[0])
self.assertEqual(recent_course_list[2][0], courses[1]) self.assertEqual(recent_course_list[2].course, courses[1])
self.assertEqual(recent_course_list[3][0], courses[2]) self.assertEqual(recent_course_list[3].course, courses[2])
self.assertEqual(recent_course_list[4][0], courses[3]) self.assertEqual(recent_course_list[4].course, courses[3])
def test_dashboard_rendering(self): def test_dashboard_rendering(self):
""" """
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
This file demonstrates writing tests using the unittest module. These will pass Miscellaneous tests for the student app.
when you run "manage.py test".
Replace this with more appropriate tests for your application.
""" """
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging import logging
...@@ -28,8 +25,8 @@ from student.views import (process_survey_link, _cert_info, ...@@ -28,8 +25,8 @@ from student.views import (process_survey_link, _cert_info,
from student.tests.factories import UserFactory, CourseModeFactory from student.tests.factories import UserFactory, CourseModeFactory
from util.testing import EventTestMixin from util.testing import EventTestMixin
from util.model_utils import USER_SETTINGS_CHANGED_EVENT_NAME from util.model_utils import USER_SETTINGS_CHANGED_EVENT_NAME
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, ModuleStoreEnum
# These imports refer to lms djangoapps. # These imports refer to lms djangoapps.
# Their testcases are only run under lms. # Their testcases are only run under lms.
...@@ -193,6 +190,7 @@ class CourseEndingTest(TestCase): ...@@ -193,6 +190,7 @@ class CourseEndingTest(TestCase):
self.assertIsNone(_cert_info(user, course2, cert_status, course_mode)) self.assertIsNone(_cert_info(user, course2, cert_status, course_mode))
@ddt.ddt
class DashboardTest(ModuleStoreTestCase): class DashboardTest(ModuleStoreTestCase):
""" """
Tests for dashboard utility functions Tests for dashboard utility functions
...@@ -487,6 +485,48 @@ class DashboardTest(ModuleStoreTestCase): ...@@ -487,6 +485,48 @@ class DashboardTest(ModuleStoreTestCase):
) )
self.assertContains(response, expected_url) self.assertContains(response, expected_url)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@ddt.data((ModuleStoreEnum.Type.mongo, 1), (ModuleStoreEnum.Type.split, 3))
@ddt.unpack
def test_dashboard_metadata_caching(self, modulestore_type, expected_mongo_calls):
"""
Check that the student dashboard makes use of course metadata caching.
The first time the student dashboard displays a specific course, it will
make a call to the module store. After that first request, though, the
course's metadata should be cached as a CourseOverview.
Arguments:
modulestore_type (ModuleStoreEnum.Type): Type of modulestore to create
test course in.
expected_mongo_calls (int >=0): Number of MongoDB queries expected for
a single call to the module store.
Note to future developers:
If you break this test so that the "check_mongo_calls(0)" fails,
please do NOT change it to "check_mongo_calls(n>1)". Instead, change
your code to not load courses from the module store. This may
involve adding fields to CourseOverview so that loading a full
CourseDescriptor isn't necessary.
"""
# Create a course, log in the user, and enroll them in the course.
test_course = CourseFactory.create(default_store=modulestore_type)
self.client.login(username="jack", password="test")
CourseEnrollment.enroll(self.user, test_course.id)
# The first request will result in a modulestore query.
with check_mongo_calls(expected_mongo_calls):
response_1 = self.client.get(reverse('dashboard'))
self.assertEquals(response_1.status_code, 200)
# Subsequent requests will only result in SQL queries to load the
# CourseOverview object that has been created.
with check_mongo_calls(0):
response_2 = self.client.get(reverse('dashboard'))
self.assertEquals(response_2.status_code, 200)
response_3 = self.client.get(reverse('dashboard'))
self.assertEquals(response_3.status_code, 200)
class UserSettingsEventTestMixin(EventTestMixin): class UserSettingsEventTestMixin(EventTestMixin):
""" """
......
...@@ -12,6 +12,7 @@ from django.core.urlresolvers import reverse ...@@ -12,6 +12,7 @@ from django.core.urlresolvers import reverse
from eventtracking import tracker from eventtracking import tracker
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from certificates.models import ( from certificates.models import (
...@@ -216,13 +217,18 @@ def generate_example_certificates(course_key): ...@@ -216,13 +217,18 @@ def generate_example_certificates(course_key):
def has_html_certificates_enabled(course_key, course=None): def has_html_certificates_enabled(course_key, course=None):
""" """
It determines if course has html certificates enabled Determine if a course has html certificates enabled.
Arguments:
course_key (CourseKey|str): A course key or a string representation
of one.
course (CourseDescriptor|CourseOverview): A course.
""" """
html_certificates_enabled = False html_certificates_enabled = False
try: try:
if not isinstance(course_key, CourseKey): if not isinstance(course_key, CourseKey):
course_key = CourseKey.from_string(course_key) course_key = CourseKey.from_string(course_key)
course = course if course else modulestore().get_course(course_key, depth=0) course = course if course else CourseOverview.get_from_id(course_key)
if settings.FEATURES.get('CERTIFICATES_HTML_VIEW', False) and course.cert_html_view_enabled: if settings.FEATURES.get('CERTIFICATES_HTML_VIEW', False) and course.cert_html_view_enabled:
html_certificates_enabled = True html_certificates_enabled = True
except: # pylint: disable=bare-except except: # pylint: disable=bare-except
......
...@@ -152,6 +152,16 @@ def find_file(filesystem, dirs, filename): ...@@ -152,6 +152,16 @@ def find_file(filesystem, dirs, filename):
raise ResourceNotFoundError(u"Could not find {0}".format(filename)) raise ResourceNotFoundError(u"Could not find {0}".format(filename))
def get_course_university_about_section(course): # pylint: disable=invalid-name
"""
Returns a snippet of HTML displaying the course's university.
Arguments:
course (CourseDescriptor|CourseOverview): A course.
"""
return course.display_org_with_default
def get_course_about_section(course, section_key): def get_course_about_section(course, section_key):
""" """
This returns the snippet of html to be rendered on the course about page, This returns the snippet of html to be rendered on the course about page,
...@@ -227,7 +237,7 @@ def get_course_about_section(course, section_key): ...@@ -227,7 +237,7 @@ def get_course_about_section(course, section_key):
elif section_key == "title": elif section_key == "title":
return course.display_name_with_default return course.display_name_with_default
elif section_key == "university": elif section_key == "university":
return course.display_org_with_default return get_course_university_about_section(course)
elif section_key == "number": elif section_key == "number":
return course.display_number_with_default return course.display_number_with_default
......
<%page args="ccx, membership, course, show_courseware_link, is_course_blocked" /> <%page args="ccx, membership, course_overview, show_courseware_link, is_course_blocked" />
<%! <%!
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
...@@ -7,7 +7,7 @@ from courseware.courses import course_image_url, get_course_about_section ...@@ -7,7 +7,7 @@ from courseware.courses import course_image_url, get_course_about_section
from ccx_keys.locator import CCXLocator from ccx_keys.locator import CCXLocator
%> %>
<% <%
ccx_target = reverse('info', args=[CCXLocator.from_course_locator(course.id, ccx.id)]) ccx_target = reverse('info', args=[CCXLocator.from_course_locator(course_overview.id, ccx.id)])
%> %>
<li class="course-item"> <li class="course-item">
<article class="course"> <article class="course">
...@@ -16,16 +16,16 @@ from ccx_keys.locator import CCXLocator ...@@ -16,16 +16,16 @@ from ccx_keys.locator import CCXLocator
% if show_courseware_link: % if show_courseware_link:
% if not is_course_blocked: % if not is_course_blocked:
<a href="${ccx_target}" class="cover"> <a href="${ccx_target}" class="cover">
<img src="${course_image_url(course)}" class="course-image" alt="${_('{course_number} {ccx_name} Cover Image').format(course_number=course.number, ccx_name=ccx.display_name) |h}" /> <img src="${course_overview.course_image_url}" class="course-image" alt="${_('{course_number} {ccx_name} Cover Image').format(course_number=course_overview.number, ccx_name=ccx.display_name) |h}" />
</a> </a>
% else: % else:
<a class="fade-cover"> <a class="fade-cover">
<img src="${course_image_url(course)}" class="course-image" alt="${_('{course_number} {ccx_name} Cover Image').format(course_number=course.number, ccx_name=ccx.display_name) |h}" /> <img src="${course_overview.course_image_url}" class="course-image" alt="${_('{course_number} {ccx_name} Cover Image').format(course_number=course_overview.number, ccx_name=ccx.display_name) |h}" />
</a> </a>
% endif % endif
% else: % else:
<a class="cover"> <a class="cover">
<img src="${course_image_url(course)}" class="course-image" alt="${_('{course_number} {ccx_name} Cover Image').format(course_number=course.number, ccx_name=ccx.display_name) |h}" /> <img src="${course_overview.course_image_url}" class="course-image" alt="${_('{course_number} {ccx_name} Cover Image').format(course_number=course_overview.number, ccx_name=ccx.display_name) |h}" />
</a> </a>
% endif % endif
</div> </div>
...@@ -43,7 +43,7 @@ from ccx_keys.locator import CCXLocator ...@@ -43,7 +43,7 @@ from ccx_keys.locator import CCXLocator
</h3> </h3>
<div class="course-info"> <div class="course-info">
<span class="info-university">${get_course_about_section(course, 'university')} - </span> <span class="info-university">${get_course_about_section(course, 'university')} - </span>
<span class="info-course-id">${course.display_number_with_default | h}</span> <span class="info-course-id">${course_overview.display_number_with_default | h}</span>
<span class="info-date-block" data-tooltip="Hi"> <span class="info-date-block" data-tooltip="Hi">
% if ccx.has_ended(): % if ccx.has_ended():
${_("Ended - {end_date}").format(end_date=ccx.end_datetime_text("SHORT_DATE"))} ${_("Ended - {end_date}").format(end_date=ccx.end_datetime_text("SHORT_DATE"))}
......
...@@ -70,28 +70,28 @@ from django.core.urlresolvers import reverse ...@@ -70,28 +70,28 @@ from django.core.urlresolvers import reverse
</header> </header>
% if len(course_enrollment_pairs) > 0: % if len(course_enrollments) > 0:
<ul class="listing-courses"> <ul class="listing-courses">
<% share_settings = settings.FEATURES.get('SOCIAL_SHARING_SETTINGS', {}) %> <% share_settings = settings.FEATURES.get('SOCIAL_SHARING_SETTINGS', {}) %>
% for dashboard_index, (course, enrollment) in enumerate(course_enrollment_pairs): % for dashboard_index, enrollment in enumerate(course_enrollments):
<% show_courseware_link = (course.id in show_courseware_links_for) %> <% show_courseware_link = (enrollment.course_id in show_courseware_links_for) %>
<% cert_status = cert_statuses.get(course.id) %> <% cert_status = cert_statuses.get(enrollment.course_id) %>
<% credit_status = credit_statuses.get(course.id) %> <% credit_status = credit_statuses.get(enrollment.course_id) %>
<% show_email_settings = (course.id in show_email_settings_for) %> <% show_email_settings = (enrollment.course_id in show_email_settings_for) %>
<% course_mode_info = all_course_modes.get(course.id) %> <% course_mode_info = all_course_modes.get(enrollment.course_id) %>
<% show_refund_option = (course.id in show_refund_option_for) %> <% show_refund_option = (enrollment.course_id in show_refund_option_for) %>
<% is_paid_course = (course.id in enrolled_courses_either_paid) %> <% is_paid_course = (enrollment.course_id in enrolled_courses_either_paid) %>
<% is_course_blocked = (course.id in block_courses) %> <% is_course_blocked = (enrollment.course_id in block_courses) %>
<% course_verification_status = verification_status_by_course.get(course.id, {}) %> <% course_verification_status = verification_status_by_course.get(enrollment.course_id, {}) %>
<% course_requirements = courses_requirements_not_met.get(course.id) %> <% course_requirements = courses_requirements_not_met.get(enrollment.course_id) %>
<%include file='dashboard/_dashboard_course_listing.html' args="course=course, enrollment=enrollment, show_courseware_link=show_courseware_link, cert_status=cert_status, credit_status=credit_status, show_email_settings=show_email_settings, course_mode_info=course_mode_info, show_refund_option = show_refund_option, is_paid_course = is_paid_course, is_course_blocked = is_course_blocked, verification_status=course_verification_status, course_requirements=course_requirements, dashboard_index=dashboard_index, share_settings=share_settings, user=user" /> <%include file='dashboard/_dashboard_course_listing.html' args="course_overview=enrollment.course_overview, enrollment=enrollment, show_courseware_link=show_courseware_link, cert_status=cert_status, credit_status=credit_status, show_email_settings=show_email_settings, course_mode_info=course_mode_info, show_refund_option=show_refund_option, is_paid_course=is_paid_course, is_course_blocked=is_course_blocked, verification_status=course_verification_status, course_requirements=course_requirements, dashboard_index=dashboard_index, share_settings=share_settings, user=user" />
% endfor % endfor
% if settings.FEATURES.get('CUSTOM_COURSES_EDX', False): % if settings.FEATURES.get('CUSTOM_COURSES_EDX', False):
% for ccx, membership, course in ccx_membership_triplets: % for ccx, membership, course in ccx_membership_triplets:
<% show_courseware_link = ccx.has_started() %> <% show_courseware_link = ccx.has_started() %>
<% is_course_blocked = False %> <% is_course_blocked = False %>
<%include file='ccx/_dashboard_ccx_listing.html' args="ccx=ccx, membership=membership, course=course, show_courseware_link=show_courseware_link, is_course_blocked=is_course_blocked" /> <%include file='ccx/_dashboard_ccx_listing.html' args="ccx=ccx, membership=membership, course_overview=enrollment.course_overview, show_courseware_link=show_courseware_link, is_course_blocked=is_course_blocked" />
% endfor % endfor
% endif % endif
......
<%page args="cert_status, course, enrollment" /> <%page args="cert_status, course_overview, enrollment" />
<%! <%!
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
...@@ -7,11 +7,11 @@ from course_modes.models import CourseMode ...@@ -7,11 +7,11 @@ from course_modes.models import CourseMode
<%namespace name='static' file='../static_content.html'/> <%namespace name='static' file='../static_content.html'/>
<% <%
cert_name_short = course.cert_name_short cert_name_short = course_overview.cert_name_short
if cert_name_short == "": if cert_name_short == "":
cert_name_short = settings.CERT_NAME_SHORT cert_name_short = settings.CERT_NAME_SHORT
cert_name_long = course.cert_name_long cert_name_long = course_overview.cert_name_long
if cert_name_long == "": if cert_name_long == "":
cert_name_long = settings.CERT_NAME_LONG cert_name_long = settings.CERT_NAME_LONG
%> %>
...@@ -35,7 +35,7 @@ else: ...@@ -35,7 +35,7 @@ else:
<span class="grade-value">${"{0:.0f}%".format(float(cert_status['grade'])*100)}</span>. <span class="grade-value">${"{0:.0f}%".format(float(cert_status['grade'])*100)}</span>.
% if cert_status['status'] == 'notpassing' and enrollment.mode != 'audit': % if cert_status['status'] == 'notpassing' and enrollment.mode != 'audit':
${_("Grade required for a {cert_name_short}:").format(cert_name_short=cert_name_short)} <span class="grade-value"> ${_("Grade required for a {cert_name_short}:").format(cert_name_short=cert_name_short)} <span class="grade-value">
${"{0:.0f}%".format(float(course.lowest_passing_grade)*100)}</span>. ${"{0:.0f}%".format(float(course_overview.lowest_passing_grade)*100)}</span>.
% elif cert_status['status'] == 'restricted' and enrollment.mode == 'verified': % elif cert_status['status'] == 'restricted' and enrollment.mode == 'verified':
<p class="message-copy"> <p class="message-copy">
${_("Your verified {cert_name_long} is being held pending confirmation that the issuance of your {cert_name_short} is in compliance with strict U.S. embargoes on Iran, Cuba, Syria and Sudan. If you think our system has mistakenly identified you as being connected with one of those countries, please let us know by contacting {email}. If you would like a refund on your {cert_name_long}, please contact our billing address {billing_email}").format(email='<a class="contact-link" href="mailto:{email}">{email}</a>.'.format(email=settings.CONTACT_EMAIL), billing_email='<a class="contact-link" href="mailto:{email}">{email}</a>'.format(email=settings.PAYMENT_SUPPORT_EMAIL), cert_name_short=cert_name_short, cert_name_long=cert_name_long)} ${_("Your verified {cert_name_long} is being held pending confirmation that the issuance of your {cert_name_short} is in compliance with strict U.S. embargoes on Iran, Cuba, Syria and Sudan. If you think our system has mistakenly identified you as being connected with one of those countries, please let us know by contacting {email}. If you would like a refund on your {cert_name_long}, please contact our billing address {billing_email}").format(email='<a class="contact-link" href="mailto:{email}">{email}</a>.'.format(email=settings.CONTACT_EMAIL), billing_email='<a class="contact-link" href="mailto:{email}">{email}</a>'.format(email=settings.PAYMENT_SUPPORT_EMAIL), cert_name_short=cert_name_short, cert_name_long=cert_name_long)}
...@@ -88,7 +88,7 @@ else: ...@@ -88,7 +88,7 @@ else:
<li class="action action-share"> <li class="action action-share">
<a class="action-linkedin-profile" target="_blank" href="${cert_status['linked_in_url']}" <a class="action-linkedin-profile" target="_blank" href="${cert_status['linked_in_url']}"
title="${_('Add Certificate to LinkedIn Profile')}" title="${_('Add Certificate to LinkedIn Profile')}"
data-course-id="${unicode(course.id)}" data-course-id="${unicode(course_overview.id)}"
data-certificate-mode="${cert_status['mode']}" data-certificate-mode="${cert_status['mode']}"
> >
<img class="action-linkedin-profile-img" <img class="action-linkedin-profile-img"
......
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'CourseOverview.cert_html_view_enabled'
# The default value for the cert_html_view_eanbled column is False.
# However, for courses in the table for which cert_html_view_enabled
# should be True, this would be invalid. So, we must clear the
# table before adding the new column.
db.clear_table('course_overviews_courseoverview')
db.add_column('course_overviews_courseoverview', 'cert_html_view_enabled',
self.gf('django.db.models.fields.BooleanField')(default=False),
keep_default=False)
def backwards(self, orm):
# Deleting field 'CourseOverview.cert_html_view_enabled'
db.delete_column('course_overviews_courseoverview', 'cert_html_view_enabled')
models = {
'course_overviews.courseoverview': {
'Meta': {'object_name': 'CourseOverview'},
'_location': ('xmodule_django.models.UsageKeyField', [], {'max_length': '255'}),
'_pre_requisite_courses_json': ('django.db.models.fields.TextField', [], {}),
'advertised_start': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'cert_html_view_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'cert_name_long': ('django.db.models.fields.TextField', [], {}),
'cert_name_short': ('django.db.models.fields.TextField', [], {}),
'certificates_display_behavior': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'certificates_show_before_end': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'course_image_url': ('django.db.models.fields.TextField', [], {}),
'days_early_for_beta': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
'display_name': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'display_number_with_default': ('django.db.models.fields.TextField', [], {}),
'display_org_with_default': ('django.db.models.fields.TextField', [], {}),
'end': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'end_of_course_survey_url': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'facebook_url': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'has_any_active_web_certificate': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('xmodule_django.models.CourseKeyField', [], {'max_length': '255', 'primary_key': 'True', 'db_index': 'True'}),
'lowest_passing_grade': ('django.db.models.fields.DecimalField', [], {'max_digits': '5', 'decimal_places': '2'}),
'mobile_available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'social_sharing_url': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'start': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'visible_to_staff_only': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
}
}
complete_apps = ['course_overviews']
\ No newline at end of file
...@@ -10,6 +10,8 @@ from django.utils.translation import ugettext ...@@ -10,6 +10,8 @@ from django.utils.translation import ugettext
from util.date_utils import strftime_localized from util.date_utils import strftime_localized
from xmodule import course_metadata_utils from xmodule import course_metadata_utils
from xmodule.course_module import CourseDescriptor
from xmodule.error_module import ErrorDescriptor
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule_django.models import CourseKeyField, UsageKeyField from xmodule_django.models import CourseKeyField, UsageKeyField
...@@ -44,6 +46,7 @@ class CourseOverview(django.db.models.Model): ...@@ -44,6 +46,7 @@ class CourseOverview(django.db.models.Model):
# Certification data # Certification data
certificates_display_behavior = TextField(null=True) certificates_display_behavior = TextField(null=True)
certificates_show_before_end = BooleanField() certificates_show_before_end = BooleanField()
cert_html_view_enabled = BooleanField()
has_any_active_web_certificate = BooleanField() has_any_active_web_certificate = BooleanField()
cert_name_short = TextField() cert_name_short = TextField()
cert_name_long = TextField() cert_name_long = TextField()
...@@ -91,6 +94,7 @@ class CourseOverview(django.db.models.Model): ...@@ -91,6 +94,7 @@ class CourseOverview(django.db.models.Model):
certificates_display_behavior=course.certificates_display_behavior, certificates_display_behavior=course.certificates_display_behavior,
certificates_show_before_end=course.certificates_show_before_end, certificates_show_before_end=course.certificates_show_before_end,
cert_html_view_enabled=course.cert_html_view_enabled,
has_any_active_web_certificate=(get_active_web_certificate(course) is not None), has_any_active_web_certificate=(get_active_web_certificate(course) is not None),
cert_name_short=course.cert_name_short, cert_name_short=course.cert_name_short,
cert_name_long=course.cert_name_long, cert_name_long=course.cert_name_long,
...@@ -114,10 +118,17 @@ class CourseOverview(django.db.models.Model): ...@@ -114,10 +118,17 @@ class CourseOverview(django.db.models.Model):
future use. future use.
Arguments: Arguments:
course_id (CourseKey): the ID of the course overview to be loaded course_id (CourseKey): the ID of the course overview to be loaded.
Returns: Returns:
CourseOverview: overview of the requested course CourseOverview: overview of the requested course. If loading course
from the module store failed, returns None.
Raises:
- CourseOverview.DoesNotExist if the course specified by course_id
was not found.
- IOError if some other error occurs while trying to load the
course from the module store.
""" """
course_overview = None course_overview = None
try: try:
...@@ -126,9 +137,17 @@ class CourseOverview(django.db.models.Model): ...@@ -126,9 +137,17 @@ class CourseOverview(django.db.models.Model):
store = modulestore() store = modulestore()
with store.bulk_operations(course_id): with store.bulk_operations(course_id):
course = store.get_course(course_id) course = store.get_course(course_id)
if course: if isinstance(course, CourseDescriptor):
course_overview = CourseOverview._create_from_course(course) course_overview = CourseOverview._create_from_course(course)
course_overview.save() # Save new overview to the cache course_overview.save()
elif course is not None:
raise IOError(
"Error while loading course {} from the module store: {}",
unicode(course_id),
course.error_msg if isinstance(course, ErrorDescriptor) else unicode(course)
)
else:
raise CourseOverview.DoesNotExist()
return course_overview return course_overview
def clean_id(self, padding_char='='): def clean_id(self, padding_char='='):
......
...@@ -6,13 +6,16 @@ import ddt ...@@ -6,13 +6,16 @@ import ddt
import itertools import itertools
import pytz import pytz
import math import math
import mock
from django.utils import timezone from django.utils import timezone
from lms.djangoapps.certificates.api import get_active_web_certificate from lms.djangoapps.certificates.api import get_active_web_certificate
from lms.djangoapps.courseware.courses import course_image_url from lms.djangoapps.courseware.courses import course_image_url
from xmodule.course_metadata_utils import DEFAULT_START_DATE from xmodule.course_metadata_utils import DEFAULT_START_DATE
from xmodule.error_module import ErrorDescriptor
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls, check_mongo_calls_range from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls, check_mongo_calls_range
...@@ -41,12 +44,18 @@ class CourseOverviewTestCase(ModuleStoreTestCase): ...@@ -41,12 +44,18 @@ class CourseOverviewTestCase(ModuleStoreTestCase):
- the CourseDescriptor itself - the CourseDescriptor itself
- a CourseOverview that was newly constructed from _create_from_course - a CourseOverview that was newly constructed from _create_from_course
- a CourseOverview that was loaded from the MySQL database - a CourseOverview that was loaded from the MySQL database
Arguments:
course (CourseDescriptor): the course to be checked.
""" """
def get_seconds_since_epoch(date_time): def get_seconds_since_epoch(date_time):
""" """
Returns the number of seconds between the Unix Epoch and the given Returns the number of seconds between the Unix Epoch and the given
datetime. If the given datetime is None, return None. datetime. If the given datetime is None, return None.
Arguments:
date_time (datetime): the datetime in question.
""" """
if date_time is None: if date_time is None:
return None return None
...@@ -189,18 +198,14 @@ class CourseOverviewTestCase(ModuleStoreTestCase): ...@@ -189,18 +198,14 @@ class CourseOverviewTestCase(ModuleStoreTestCase):
by comparing pairs of them given a variety of scenarios. by comparing pairs of them given a variety of scenarios.
Arguments: Arguments:
course_kwargs (dict): kwargs to be passed to course constructor course_kwargs (dict): kwargs to be passed to course constructor.
modulestore_type (ModuleStoreEnum.Type) modulestore_type (ModuleStoreEnum.Type): type of store to create the
is_user_enrolled (bool) course in.
""" """
# Note: We specify a value for 'run' here because, for some reason,
course = CourseFactory.create( # .create raises an InvalidKeyError if we don't (even though my
course="TEST101", # other test functions don't specify a run but work fine).
org="edX", course = CourseFactory.create(default_store=modulestore_type, run="TestRun", **course_kwargs)
run="Run1",
default_store=modulestore_type,
**course_kwargs
)
self.check_course_overview_against_course(course) self.check_course_overview_against_course(course)
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split) @ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
...@@ -208,17 +213,15 @@ class CourseOverviewTestCase(ModuleStoreTestCase): ...@@ -208,17 +213,15 @@ class CourseOverviewTestCase(ModuleStoreTestCase):
""" """
Tests that when a course is published, the corresponding Tests that when a course is published, the corresponding
course_overview is removed from the cache. course_overview is removed from the cache.
Arguments:
modulestore_type (ModuleStoreEnum.Type): type of store to create the
course in.
""" """
with self.store.default_store(modulestore_type): with self.store.default_store(modulestore_type):
# Create a course where mobile_available is True. # Create a course where mobile_available is True.
course = CourseFactory.create( course = CourseFactory.create(mobile_available=True, default_store=modulestore_type)
course="TEST101",
org="edX",
run="Run1",
mobile_available=True,
default_store=modulestore_type
)
course_overview_1 = CourseOverview.get_from_id(course.id) course_overview_1 = CourseOverview.get_from_id(course.id)
self.assertTrue(course_overview_1.mobile_available) self.assertTrue(course_overview_1.mobile_available)
...@@ -238,14 +241,16 @@ class CourseOverviewTestCase(ModuleStoreTestCase): ...@@ -238,14 +241,16 @@ class CourseOverviewTestCase(ModuleStoreTestCase):
def test_course_overview_caching(self, modulestore_type, min_mongo_calls, max_mongo_calls): def test_course_overview_caching(self, modulestore_type, min_mongo_calls, max_mongo_calls):
""" """
Tests that CourseOverview structures are actually getting cached. Tests that CourseOverview structures are actually getting cached.
Arguments:
modulestore_type (ModuleStoreEnum.Type): type of store to create the
course in.
min_mongo_calls (int): minimum number of MongoDB queries we expect
to be made.
max_mongo_calls (int): maximum number of MongoDB queries we expect
to be made.
""" """
course = CourseFactory.create( course = CourseFactory.create(default_store=modulestore_type)
course="TEST101",
org="edX",
run="Run1",
mobile_available=True,
default_store=modulestore_type
)
# The first time we load a CourseOverview, it will be a cache miss, so # The first time we load a CourseOverview, it will be a cache miss, so
# we expect the modulestore to be queried. # we expect the modulestore to be queried.
...@@ -256,3 +261,36 @@ class CourseOverviewTestCase(ModuleStoreTestCase): ...@@ -256,3 +261,36 @@ class CourseOverviewTestCase(ModuleStoreTestCase):
# we expect no modulestore queries to be made. # we expect no modulestore queries to be made.
with check_mongo_calls(0): with check_mongo_calls(0):
_course_overview_2 = CourseOverview.get_from_id(course.id) _course_overview_2 = CourseOverview.get_from_id(course.id)
@ddt.data(ModuleStoreEnum.Type.split, ModuleStoreEnum.Type.mongo)
def test_get_non_existent_course(self, modulestore_type):
"""
Tests that requesting a non-existent course from get_from_id raises
CourseOverview.DoesNotExist.
Arguments:
modulestore_type (ModuleStoreEnum.Type): type of store to create the
course in.
"""
store = modulestore()._get_modulestore_by_type(modulestore_type) # pylint: disable=protected-access
with self.assertRaises(CourseOverview.DoesNotExist):
CourseOverview.get_from_id(store.make_course_key('Non', 'Existent', 'Course'))
@ddt.data(ModuleStoreEnum.Type.split, ModuleStoreEnum.Type.mongo)
def test_get_errored_course(self, modulestore_type):
"""
Test that getting an ErrorDescriptor back from the module store causes
get_from_id to raise an IOError.
Arguments:
modulestore_type (ModuleStoreEnum.Type): type of store to create the
course in.
"""
course = CourseFactory.create(default_store=modulestore_type)
mock_get_course = mock.Mock(return_value=ErrorDescriptor)
with mock.patch('xmodule.modulestore.mixed.MixedModuleStore.get_course', mock_get_course):
# This mock makes it so when the module store tries to load course data,
# an exception is thrown, which causes get_course to return an ErrorDescriptor,
# which causes get_from_id to raise an IOError.
with self.assertRaises(IOError):
CourseOverview.get_from_id(course.id)
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