add expiration banner
This commit is contained in:
committed by
Matthew Piatetsky
parent
644cf1e60a
commit
6cc4fb34be
@@ -12,9 +12,12 @@ from django.utils.translation import ugettext as _
|
||||
from util.date_utils import DEFAULT_SHORT_DATE_FORMAT, strftime_localized
|
||||
from lms.djangoapps.courseware.access_response import AccessError
|
||||
from lms.djangoapps.courseware.access_utils import ACCESS_GRANTED
|
||||
from lms.djangoapps.courseware.date_summary import verified_upgrade_deadline_link
|
||||
from openedx.core.djangoapps.catalog.utils import get_course_run_details
|
||||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
||||
|
||||
from openedx.core.djangoapps.util.user_messages import PageLevelMessages
|
||||
from openedx.core.djangolib.markup import HTML
|
||||
from openedx.features.course_duration_limits.config import CONTENT_TYPE_GATING_FLAG
|
||||
|
||||
MIN_DURATION = timedelta(weeks=4)
|
||||
MAX_DURATION = timedelta(weeks=12)
|
||||
@@ -91,3 +94,21 @@ def check_course_expired(user, course):
|
||||
return AuditExpiredError(user, course, expiration_date)
|
||||
|
||||
return ACCESS_GRANTED
|
||||
|
||||
|
||||
def register_course_expired_message(request, course):
|
||||
"""
|
||||
Add a banner notifying the user of the user course expiration date if it exists.
|
||||
"""
|
||||
if CONTENT_TYPE_GATING_FLAG.is_enabled():
|
||||
expiration_date = get_user_course_expiration_date(request.user, course)
|
||||
if expiration_date:
|
||||
upgrade_message = _('Your access to this course expires on {expiration_date}. \
|
||||
<a href="{upgrade_link}">Upgrade now</a> for unlimited access.')
|
||||
PageLevelMessages.register_info_message(
|
||||
request,
|
||||
HTML(upgrade_message).format(
|
||||
expiration_date=expiration_date.strftime('%b %-d'),
|
||||
upgrade_link=verified_upgrade_deadline_link(user=request.user, course=course)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user