Files
edx-platform/openedx/features/course_experience/views/course_sock.py
Harry Rein bdf38ae00e Implemented an upgrade verification sock.
This sock sits at the bottom of both the home and the course content pages. It allows the user to click a 'Learn More' button to open a panel that allows the user to navigate to the upgrade checkout page. The sock is only shown for users that have not yet upgraded in a course that has a verification upgrade date that has not yet passed. Python tests cover the various course mode and upgrade dates.
2017-06-15 13:10:34 -04:00

57 lines
2.1 KiB
Python

"""
Fragment for rendering the course's sock and associated toggle button.
"""
from datetime import datetime
from django.conf import settings
from django.template.loader import render_to_string
from opaque_keys.edx.keys import CourseKey
from web_fragments.fragment import Fragment
from student.models import CourseEnrollment
from course_modes.models import CourseMode
from courseware.date_summary import VerifiedUpgradeDeadlineDate
from courseware.courses import get_course_with_access
from courseware.views.views import get_course_prices
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
class CourseSockFragmentView(EdxFragmentView):
"""
A fragment to provide extra functionality in a dropdown sock.
"""
def render_to_fragment(self, request, course, **kwargs):
"""
Render the course's sock fragment.
"""
context = self.get_verification_context(request, course)
html = render_to_string('course_experience/course-sock-fragment.html', context)
return Fragment(html)
def get_verification_context(self, request, course):
course_key = CourseKey.from_string(unicode(course.id))
# Establish whether the course has a verified mode
available_modes = CourseMode.modes_for_course_dict(unicode(course.id))
has_verified_mode = CourseMode.has_verified_mode(available_modes)
# Establish whether the user is already enrolled
is_already_verified = CourseEnrollment.is_enrolled_as_verified(request.user.id, course_key)
# Establish whether the verification deadline has already passed
verification_deadline = VerifiedUpgradeDeadlineDate(course, request.user)
deadline_has_passed = verification_deadline.deadline_has_passed()
show_course_sock = has_verified_mode and not is_already_verified and not deadline_has_passed
# Get the price of the course and format correctly
course_prices = get_course_prices(course)
context = {
'show_course_sock': show_course_sock,
'course_price': course_prices[1],
'course_id': course.id
}
return context