Ejemplo n.º 1
0
 def url(cls, course_key):
     """
     Returns the URL for this tool for the specified course key.
     """
     request = get_current_request()
     return verified_upgrade_deadline_link(request.user,
                                           course_id=course_key)
Ejemplo n.º 2
0
    def test_first_purchase_offer_banner_display(self,
                                                 applicability,
                                                 percentage,
                                                 can_receive_discount_mock,
                                                 discount_percentage_mock):
        """
        Ensure first purchase offer banner displays correctly
        """
        can_receive_discount_mock.return_value = applicability
        discount_percentage_mock.return_value = percentage
        user = self.create_user_for_course(self.course, CourseUserType.ENROLLED)
        now_time = datetime.now(tz=UTC).strftime(u"%Y-%m-%d %H:%M:%S%z")
        ExperimentData.objects.create(
            user=user, experiment_id=REV1008_EXPERIMENT_ID, key=str(self.course), value=now_time
        )
        self.client.login(username=user.username, password=self.TEST_PASSWORD)
        url = course_home_url(self.course)
        response = self.client.get(url)
        discount_expiration_date = get_discount_expiration_date(user, self.course).strftime(u'%B %d')
        upgrade_link = verified_upgrade_deadline_link(user=user, course=self.course)
        bannerText = u'''<div class="first-purchase-offer-banner" role="note">
             <span class="first-purchase-offer-banner-bold">
             Upgrade by {discount_expiration_date} and save {percentage}% [{strikeout_price}]</span>
             <br>Use code <b>EDXWELCOME</b> at checkout! <a href="{upgrade_link}">Upgrade Now</a>
             </div>'''.format(
            discount_expiration_date=discount_expiration_date,
            percentage=percentage,
            strikeout_price=HTML(format_strikeout_price(user, self.course, check_for_discount=False)[0]),
            upgrade_link=upgrade_link
        )

        if applicability:
            self.assertContains(response, bannerText, html=True)
        else:
            self.assertNotContains(response, bannerText, html=True)
Ejemplo n.º 3
0
    def test_first_purchase_offer_banner_display(self,
                                                 applicability,
                                                 percentage,
                                                 can_receive_discount_mock,
                                                 discount_percentage_mock):
        """
        Ensure first purchase offer banner displays correctly
        """
        can_receive_discount_mock.return_value = applicability
        discount_percentage_mock.return_value = percentage
        user = self.create_user_for_course(self.course, CourseUserType.ENROLLED)
        self.client.login(username=user.username, password=self.TEST_PASSWORD)
        url = course_home_url(self.course)
        response = self.client.get(url)
        discount_expiration_date = get_discount_expiration_date(user, self.course).strftime(u'%B %d')
        upgrade_link = verified_upgrade_deadline_link(user=user, course=self.course)
        bannerText = u'''<div class="first-purchase-offer-banner" role="note">
             <span class="first-purchase-offer-banner-bold">
             Upgrade by {discount_expiration_date} and save {percentage}% [{strikeout_price}]</span>
             <br>Discount will be automatically applied at checkout. <a href="{upgrade_link}">Upgrade Now</a>
             </div>'''.format(
            discount_expiration_date=discount_expiration_date,
            percentage=percentage,
            strikeout_price=HTML(format_strikeout_price(user, self.course, check_for_discount=False)[0]),
            upgrade_link=upgrade_link
        )

        if applicability:
            self.assertContains(response, bannerText, html=True)
        else:
            self.assertNotContains(response, bannerText, html=True)
Ejemplo n.º 4
0
 def get_dates_banner_info(self, _):
     """
     Serializer mixin for returning date banner info.  Gets its input from
     the views course_key_string url parameter and the request's user object.
     """
     info = {
         'missed_deadlines': False,
         'content_type_gating_enabled': False,
     }
     course_key_string = self.context['view'].kwargs.get(
         'course_key_string')
     if course_key_string:
         course_key = CourseKey.from_string(course_key_string)
         request = self.context['request']
         missed_deadlines, missed_gated_content = dates_banner_should_display(
             course_key, request.user)
         info['missed_deadlines'] = missed_deadlines
         info['missed_gated_content'] = missed_gated_content
         info[
             'content_type_gating_enabled'] = ContentTypeGatingConfig.enabled_for_enrollment(
                 user=request.user,
                 course_key=course_key,
             )
         info['verified_upgrade_link'] = verified_upgrade_deadline_link(
             request.user, course_id=course_key)
     return info
Ejemplo n.º 5
0
def register_course_expired_message(request, course):
    """
    Add a banner notifying the user of the user course expiration date if it exists.
    """
    if not CourseDurationLimitConfig.enabled_for_enrollment(user=request.user, course_key=course.id):
        return

    expiration_date = get_user_course_expiration_date(request.user, course)
    if not expiration_date:
        return

    if is_masquerading_as_student(request.user, course.id) and timezone.now() > expiration_date:
        upgrade_message = _('This learner does not have access to this course. '
                            'Their access expired on {expiration_date}.')
        PageLevelMessages.register_warning_message(
            request,
            HTML(upgrade_message).format(
                expiration_date=expiration_date.strftime('%b %-d')
            )
        )
    else:
        enrollment = CourseEnrollment.get_enrollment(request.user, course.id)
        if enrollment is None:
            return

        upgrade_deadline = enrollment.upgrade_deadline
        if upgrade_deadline is None:
            return
        now = timezone.now()
        course_upgrade_deadline = enrollment.course_upgrade_deadline
        if now > upgrade_deadline:
            upgrade_deadline = course_upgrade_deadline

        expiration_message = _('{strong_open}Audit Access Expires {expiration_date}{strong_close}'
                               '{line_break}You lose all access to this course, including your progress, on '
                               '{expiration_date}.')
        upgrade_deadline_message = _('{line_break}Upgrade by {upgrade_deadline} to get unlimited access to the course '
                                     'as long as it exists on the site. {a_open}Upgrade now{sronly_span_open} to '
                                     'retain access past {expiration_date}{span_close}{a_close}')
        full_message = expiration_message
        if now < course_upgrade_deadline:
            full_message += upgrade_deadline_message

        PageLevelMessages.register_info_message(
            request,
            Text(full_message).format(
                a_open=HTML('<a href="{upgrade_link}">').format(
                    upgrade_link=verified_upgrade_deadline_link(user=request.user, course=course)
                ),
                sronly_span_open=HTML('<span class="sr-only">'),
                sighted_only_span_open=HTML('<span aria-hidden="true">'),
                span_close=HTML('</span>'),
                a_close=HTML('</a>'),
                expiration_date=expiration_date.strftime('%b. %-d, %Y'),
                strong_open=HTML('<strong>'),
                strong_close=HTML('</strong>'),
                line_break=HTML('<br>'),
                upgrade_deadline=upgrade_deadline.strftime('%b. %-d, %Y')
            )
        )
Ejemplo n.º 6
0
def get_first_purchase_offer_banner_fragment(user, course):
    """
    Return an HTML Fragment with First Purcahse Discount message,
    which has the discount_expiration_date, price,
    discount percentage and a link to upgrade.
    """
    if user and course:
        discount_expiration_date = get_discount_expiration_date(user, course)
        if (discount_expiration_date and
                can_receive_discount(user=user, course=course, discount_expiration_date=discount_expiration_date)):
            # Translator: xgettext:no-python-format
            offer_message = _(u'{banner_open} Upgrade by {discount_expiration_date} and save {percentage}% '
                              u'[{strikeout_price}]{span_close}{br}Discount will be automatically applied at checkout. '
                              u'{a_open}Upgrade Now{a_close}{div_close}')
            return Fragment(HTML(offer_message).format(
                a_open=HTML(u'<a href="{upgrade_link}">').format(
                    upgrade_link=verified_upgrade_deadline_link(user=user, course=course)
                ),
                a_close=HTML('</a>'),
                br=HTML('<br>'),
                banner_open=HTML(
                    '<div class="first-purchase-offer-banner"><span class="first-purchase-offer-banner-bold">'
                ),
                discount_expiration_date=discount_expiration_date.strftime(u'%B %d'),
                percentage=discount_percentage(course),
                span_close=HTML('</span>'),
                div_close=HTML('</div>'),
                strikeout_price=HTML(format_strikeout_price(user, course, check_for_discount=False)[0])
            ))
    return None
    def render_to_fragment(self, request, course_id, user_is_enrolled=True, **kwargs):  # pylint: disable=arguments-differ
        """
        Renders the course outline as a fragment.
        """
        from lms.urls import RESET_COURSE_DEADLINES_NAME

        course_key = CourseKey.from_string(course_id)
        course_overview = get_course_overview_with_access(
            request.user, 'load', course_key, check_if_enrolled=user_is_enrolled
        )
        course = modulestore().get_course(course_key)

        course_block_tree = get_course_outline_block_tree(
            request, course_id, request.user if user_is_enrolled else None
        )
        if not course_block_tree:
            return None

        resume_block = get_resume_block(course_block_tree) if user_is_enrolled else None

        if not resume_block:
            self.mark_first_unit_to_resume(course_block_tree)

        xblock_display_names = self.create_xblock_id_and_name_dict(course_block_tree)
        gated_content = self.get_content_milestones(request, course_key)

        missed_deadlines, missed_gated_content = dates_banner_should_display(course_key, request.user)

        reset_deadlines_url = reverse(RESET_COURSE_DEADLINES_NAME)

        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course_overview,
            'due_date_display_format': course.due_date_display_format,
            'blocks': course_block_tree,
            'enable_links': user_is_enrolled or course.course_visibility == COURSE_VISIBILITY_PUBLIC,
            'course_key': course_key,
            'gated_content': gated_content,
            'xblock_display_names': xblock_display_names,
            'self_paced': course.self_paced,

            # We're using this flag to prevent old self-paced dates from leaking out on courses not
            # managed by edx-when.
            'in_edx_when': edx_when_api.is_enabled_for_course(course_key),
            'reset_deadlines_url': reset_deadlines_url,
            'verified_upgrade_link': verified_upgrade_deadline_link(request.user, course=course),
            'on_course_outline_page': True,
            'missed_deadlines': missed_deadlines,
            'missed_gated_content': missed_gated_content,
            'has_ended': course.has_ended(),
        }

        html = render_to_string('course_experience/course-outline-fragment.html', context)
        return Fragment(html)
Ejemplo n.º 8
0
    def get(self, request, *args, **kwargs):
        course_key_string = kwargs.get('course_key_string')
        course_key = CourseKey.from_string(course_key_string)

        if not course_home_mfe_dates_tab_is_active(course_key):
            return Response(status=status.HTTP_404_NOT_FOUND)

        # Enable NR tracing for this view based on course
        monitoring_utils.set_custom_metric('course_id', course_key_string)
        monitoring_utils.set_custom_metric('user_id', request.user.id)
        monitoring_utils.set_custom_metric('is_staff', request.user.is_staff)

        course = get_course_with_access(request.user,
                                        'load',
                                        course_key,
                                        check_if_enrolled=False)
        blocks = get_course_date_blocks(course,
                                        request.user,
                                        request,
                                        include_access=True,
                                        include_past_dates=True)
        missed_deadlines, missed_gated_content = dates_banner_should_display(
            course_key, request.user)

        learner_is_full_access = not ContentTypeGatingConfig.enabled_for_enrollment(
            user=request.user,
            course_key=course_key,
        )

        # User locale settings
        user_timezone_locale = user_timezone_locale_prefs(request)
        user_timezone = user_timezone_locale['user_timezone']

        data = {
            'has_ended':
            course.has_ended(),
            'course_date_blocks':
            [block for block in blocks if not isinstance(block, TodaysDate)],
            'missed_deadlines':
            missed_deadlines,
            'missed_gated_content':
            missed_gated_content,
            'learner_is_full_access':
            learner_is_full_access,
            'user_timezone':
            user_timezone,
            'verified_upgrade_link':
            verified_upgrade_deadline_link(request.user, course=course),
        }
        context = self.get_serializer_context()
        context['learner_is_full_access'] = learner_is_full_access
        serializer = self.get_serializer_class()(data, context=context)

        return Response(serializer.data)
Ejemplo n.º 9
0
def get_expiration_banner_text(user, course):
    """
    Get text for banner that messages user course expiration date
    for different tests that depend on it.
    """
    expiration_date = (now() + timedelta(weeks=4)).strftime('%b %-d')
    upgrade_link = verified_upgrade_deadline_link(user=user, course=course)
    bannerText = 'Your access to this course expires on {expiration_date}. \
        <a href="{upgrade_link}">Upgrade now <span class="sr-only">to retain access past {expiration_date}.\
        </span></a><span aria-hidden="true">for unlimited access.</span>'.format(
        expiration_date=expiration_date, upgrade_link=upgrade_link)
    return bannerText
Ejemplo n.º 10
0
def generate_offer_html(user, course):
    """
    Create the actual HTML object with the offer text in it.

    Returns a openedx.core.djangolib.markup.HTML object, or None if the user
    should not be shown an offer message.
    """
    if user and not user.is_anonymous and course:
        now = datetime.now(tz=pytz.UTC).strftime(u"%Y-%m-%d %H:%M:%S%z")
        saw_banner = ExperimentData.objects.filter(
            user=user, experiment_id=REV1008_EXPERIMENT_ID, key=str(course))
        if not saw_banner:
            ExperimentData.objects.create(user=user,
                                          experiment_id=REV1008_EXPERIMENT_ID,
                                          key=str(course),
                                          value=now)
        discount_expiration_date = get_discount_expiration_date(user, course)
        if (discount_expiration_date and can_receive_discount(
                user=user,
                course=course,
                discount_expiration_date=discount_expiration_date)):
            # Translator: xgettext:no-python-format
            offer_message = _(
                u'{banner_open} Upgrade by {discount_expiration_date} and save {percentage}% '
                u'[{strikeout_price}]{span_close}{br}Use code {b_open}{code}{b_close} at checkout! '
                u'{a_open}Upgrade Now{a_close}{div_close}')

            message_html = HTML(offer_message).format(
                a_open=HTML(u'<a href="{upgrade_link}">').format(
                    upgrade_link=verified_upgrade_deadline_link(
                        user=user, course=course)),
                a_close=HTML('</a>'),
                b_open=HTML('<b>'),
                code=Text('BIENVENIDOAEDX')
                if get_language() == 'es-419' else Text('EDXWELCOME'),
                b_close=HTML('</b>'),
                br=HTML('<br>'),
                banner_open=HTML(
                    '<div class="first-purchase-offer-banner" role="note">'
                    '<span class="first-purchase-offer-banner-bold">'),
                discount_expiration_date=discount_expiration_date.strftime(
                    u'%B %d'),
                percentage=discount_percentage(course),
                span_close=HTML('</span>'),
                div_close=HTML('</div>'),
                strikeout_price=HTML(
                    format_strikeout_price(user,
                                           course,
                                           check_for_discount=False)[0]))
            return message_html
    return None
Ejemplo n.º 11
0
def check_and_get_upgrade_link_and_date(user, enrollment=None, course=None):
    """
    For an authenticated user, return a link to allow them to upgrade
    in the specified course.

    Returns the upgrade link and upgrade deadline for a user in a given course given
    that the user is within the window to upgrade defined by our dynamic pacing feature;
    otherwise, returns None for both the link and date.
    """
    if enrollment is None and course is None:
        logger.warn(u'Must specify either an enrollment or a course')
        return (None, None, None)

    if enrollment:
        if course is None:
            course = enrollment.course
        elif enrollment.course_id != course.id:
            logger.warn(
                u'{} refers to a different course than {} which was supplied. Enrollment course id={}, '
                u'repr={!r}, deprecated={}. Course id={}, repr={!r}, deprecated={}.'
                .format(enrollment, course, enrollment.course_id,
                        enrollment.course_id, enrollment.course_id.deprecated,
                        course.id, course.id, course.id.deprecated))
            return (None, None, None)

        if enrollment.user_id != user.id:
            logger.warn(
                u'{} refers to a different user than {} which was supplied. Enrollment user id={}, repr={!r}. '
                u'User id={}, repr={!r}.'.format(
                    enrollment,
                    user,
                    enrollment.user_id,
                    enrollment.user_id,
                    user.id,
                    user.id,
                ))
            return (None, None, None)

    if enrollment is None:
        enrollment = CourseEnrollment.get_enrollment(user, course.id)
        if enrollment is None:
            return (None, None, None)

    if user.is_authenticated and verified_upgrade_link_is_valid(enrollment):
        return (
            verified_upgrade_deadline_link(user, course),
            enrollment.upgrade_deadline,
            enrollment.course_upgrade_deadline,
        )

    return (None, None, enrollment.course_upgrade_deadline)
Ejemplo n.º 12
0
def get_expiration_banner_text(user, course):
    """
    Get text for banner that messages user course expiration date
    for different tests that depend on it.
    """
    expiration_date = (now() + timedelta(weeks=4)).strftime('%b %-d')
    upgrade_link = verified_upgrade_deadline_link(user=user, course=course)
    bannerText = 'Your access to this course expires on {expiration_date}. \
        <a href="{upgrade_link}">Upgrade now <span class="sr-only">to retain access past {expiration_date}.\
        </span></a><span aria-hidden="true">for unlimited access.</span>'.format(
        expiration_date=expiration_date,
        upgrade_link=upgrade_link
    )
    return bannerText
Ejemplo n.º 13
0
def get_first_purchase_offer_banner_fragment(user, course):
    """
    Return an HTML Fragment with First Purcahse Discount message,
    which has the discount_expiration_date, price,
    discount percentage and a link to upgrade.
    """
    if user and not user.is_anonymous and course:
        now = datetime.now(tz=pytz.UTC)
        stop_bucketing_into_discount_experiment = datetime(
            2019, 11, 22, 0, 0, 0, 0, pytz.UTC)
        saw_banner = ExperimentData.objects.filter(
            user=user, experiment_id=REV1008_EXPERIMENT_ID, key=str(course))
        if not saw_banner and not now > stop_bucketing_into_discount_experiment:
            ExperimentData.objects.create(
                user=user,
                experiment_id=REV1008_EXPERIMENT_ID,
                key=str(course),
                value=now.strftime(u"%Y-%m-%d %H:%M:%S%z"))
        discount_expiration_date = get_discount_expiration_date(user, course)
        if (discount_expiration_date and can_receive_discount(
                user=user,
                course=course,
                discount_expiration_date=discount_expiration_date)):
            # Translator: xgettext:no-python-format
            offer_message = _(
                u'{banner_open} Upgrade by {discount_expiration_date} and save {percentage}% '
                u'[{strikeout_price}]{span_close}{br}Discount will be automatically applied at checkout. '
                u'{a_open}Upgrade Now{a_close}{div_close}')
            return Fragment(
                HTML(offer_message).format(
                    a_open=HTML(u'<a href="{upgrade_link}">').format(
                        upgrade_link=verified_upgrade_deadline_link(
                            user=user, course=course)),
                    a_close=HTML('</a>'),
                    br=HTML('<br>'),
                    banner_open=HTML(
                        '<div class="first-purchase-offer-banner" role="note">'
                        '<span class="first-purchase-offer-banner-bold">'),
                    discount_expiration_date=discount_expiration_date.strftime(
                        u'%B %d'),
                    percentage=discount_percentage(course),
                    span_close=HTML('</span>'),
                    div_close=HTML('</div>'),
                    strikeout_price=HTML(
                        format_strikeout_price(user,
                                               course,
                                               check_for_discount=False)[0])))
    return None
Ejemplo n.º 14
0
def register_course_expired_message(request, course):
    """
    Add a banner notifying the user of the user course expiration date if it exists.
    """
    if CourseDurationLimitConfig.enabled_for_enrollment(user=request.user, course_key=course.id):
        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)
                )
            )
Ejemplo n.º 15
0
    def get(self, request, *args, **kwargs):
        course_key_string = kwargs.get('course_key_string')

        # Enable NR tracing for this view based on course
        monitoring_utils.set_custom_metric('course_id', course_key_string)
        monitoring_utils.set_custom_metric('user_id', request.user.id)
        monitoring_utils.set_custom_metric('is_staff', request.user.is_staff)

        course_key = CourseKey.from_string(course_key_string)
        course = get_course_with_access(request.user,
                                        'load',
                                        course_key,
                                        check_if_enrolled=False)
        blocks = get_course_date_blocks(course,
                                        request.user,
                                        request,
                                        include_access=True,
                                        include_past_dates=True)
        display_reset_dates_text, _ = dates_banner_should_display(
            course_key, request)

        learner_is_verified = False
        enrollment = get_enrollment(request.user.username, course_key_string)
        if enrollment:
            learner_is_verified = enrollment.get('mode') == 'verified'

        # User locale settings
        user_timezone_locale = user_timezone_locale_prefs(request)
        user_timezone = user_timezone_locale['user_timezone']

        data = {
            'course_date_blocks':
            [block for block in blocks if not isinstance(block, TodaysDate)],
            'display_reset_dates_text':
            display_reset_dates_text,
            'learner_is_verified':
            learner_is_verified,
            'user_timezone':
            user_timezone,
            'verified_upgrade_link':
            verified_upgrade_deadline_link(request.user, course=course),
        }
        context = self.get_serializer_context()
        context['learner_is_verified'] = learner_is_verified
        serializer = self.get_serializer_class()(data, context=context)

        return Response(serializer.data)
Ejemplo n.º 16
0
    def get_verification_context(request, course):
        enrollment = CourseEnrollment.get_enrollment(request.user, course.id)
        show_course_sock = verified_upgrade_link_is_valid(enrollment)
        if show_course_sock:
            upgrade_url = verified_upgrade_deadline_link(request.user,
                                                         course=course)
            course_price, _ = format_strikeout_price(request.user, course)
        else:
            upgrade_url = ''
            course_price = ''

        context = {
            'show_course_sock': show_course_sock,
            'course_price': course_price,
            'course_id': course.id,
            'upgrade_url': upgrade_url,
        }

        return context
Ejemplo n.º 17
0
def get_expiration_banner_text(user, course, language='en'):
    """
    Get text for banner that messages user course expiration date
    for different tests that depend on it.
    """
    expiration_date = now() + timedelta(weeks=4)
    upgrade_link = verified_upgrade_deadline_link(user=user, course=course)
    enrollment = CourseEnrollment.get_enrollment(user, course.id)
    upgrade_deadline = enrollment.upgrade_deadline
    if upgrade_deadline is None or now() < upgrade_deadline:
        upgrade_deadline = enrollment.course_upgrade_deadline

    date_string = u'<span class="localized-datetime" data-format="shortDate" \
        data-datetime="{formatted_date}" data-language="{language}">{formatted_date_localized}</span>'
    formatted_expiration_date = date_string.format(
        language=language,
        formatted_date=expiration_date.strftime("%Y-%m-%d"),
        formatted_date_localized=strftime_localized(expiration_date, EXPIRATION_DATE_FORMAT_STR)
    )
    if upgrade_deadline:
        formatted_upgrade_deadline = date_string.format(
            language=language,
            formatted_date=upgrade_deadline.strftime("%Y-%m-%d"),
            formatted_date_localized=strftime_localized(upgrade_deadline, EXPIRATION_DATE_FORMAT_STR)
        )

        bannerText = u'<strong>Audit Access Expires {expiration_date}</strong><br>\
                     You lose all access to this course, including your progress, on {expiration_date}.\
                     <br>Upgrade by {upgrade_deadline} to get unlimited access to the course as long as it exists\
                     on the site. <a href="{upgrade_link}">Upgrade now<span class="sr-only"> to retain access past\
                     {expiration_date}</span></a>'.format(
            expiration_date=formatted_expiration_date,
            upgrade_link=upgrade_link,
            upgrade_deadline=formatted_upgrade_deadline
        )
    else:
        bannerText = u'<strong>Audit Access Expires {expiration_date}</strong><br>\
                     You lose all access to this course, including your progress, on {expiration_date}.\
                     '.format(
            expiration_date=formatted_expiration_date
        )
    return bannerText
Ejemplo n.º 18
0
def get_expiration_banner_text(user, course):
    """
    Get text for banner that messages user course expiration date
    for different tests that depend on it.
    """
    expiration_date = now() + timedelta(weeks=4)
    upgrade_link = verified_upgrade_deadline_link(user=user, course=course)
    enrollment = CourseEnrollment.get_enrollment(user, course.id)
    upgrade_deadline = enrollment.upgrade_deadline
    if upgrade_deadline is None or now() < upgrade_deadline:
        upgrade_deadline = enrollment.course_upgrade_deadline

    language = get_language()
    language_is_es = language and language.split('-')[0].lower() == 'es'
    if language_is_es:
        formatted_expiration_date = strftime_localized(
            expiration_date, '%-d de %b. de %Y').lower()
    else:
        formatted_expiration_date = strftime_localized(expiration_date,
                                                       '%b. %-d, %Y')

    if upgrade_deadline:
        if language_is_es:
            formatted_upgrade_deadline = strftime_localized(
                upgrade_deadline, '%-d de %b. de %Y').lower()
        else:
            formatted_upgrade_deadline = strftime_localized(
                upgrade_deadline, '%b. %-d, %Y')

        bannerText = '<strong>Audit Access Expires {expiration_date}</strong><br>\
                     You lose all access to this course, including your progress, on {expiration_date}.\
                     <br>Upgrade by {upgrade_deadline} to get unlimited access to the course as long as it exists\
                     on the site. <a href="{upgrade_link}">Upgrade now<span class="sr-only"> to retain access past\
                     {expiration_date}</span></a>'.format(
            expiration_date=formatted_expiration_date,
            upgrade_link=upgrade_link,
            upgrade_deadline=formatted_upgrade_deadline)
    else:
        bannerText = '<strong>Audit Access Expires {expiration_date}</strong><br>\
                     You lose all access to this course, including your progress, on {expiration_date}.\
                     '.format(expiration_date=formatted_expiration_date)
    return bannerText
Ejemplo n.º 19
0
def get_expiration_banner_text(user, course, language='en'):
    """
    Get text for banner that messages user course expiration date
    for different tests that depend on it.
    """
    expiration_date = now() + timedelta(weeks=4)
    upgrade_link = verified_upgrade_deadline_link(user=user, course=course)
    enrollment = CourseEnrollment.get_enrollment(user, course.id)
    upgrade_deadline = enrollment.upgrade_deadline
    if upgrade_deadline is None or now() < upgrade_deadline:
        upgrade_deadline = enrollment.course_upgrade_deadline

    date_string = u'<span class="localized-datetime" data-format="shortDate" \
        data-datetime="{formatted_date}" data-language="{language}">{formatted_date_localized}</span>'

    formatted_expiration_date = date_string.format(
        language=language,
        formatted_date=expiration_date.strftime(EXPIRATION_DATE_FORMAT_STR),
        formatted_date_localized=strftime_localized(
            expiration_date, EXPIRATION_DATE_FORMAT_STR))
    if upgrade_deadline:
        formatted_upgrade_deadline = date_string.format(
            language=language,
            formatted_date=upgrade_deadline.strftime(
                EXPIRATION_DATE_FORMAT_STR),
            formatted_date_localized=strftime_localized(
                upgrade_deadline, EXPIRATION_DATE_FORMAT_STR))

        bannerText = u'<strong>Audit Access Expires {expiration_date}</strong><br>\
                     You lose all access to this course, including your progress, on {expiration_date}.\
                     <br>Upgrade by {upgrade_deadline} to get unlimited access to the course as long as it exists\
                     on the site. <a href="{upgrade_link}">Upgrade now<span class="sr-only"> to retain access past\
                     {expiration_date}</span></a>'.format(
            expiration_date=formatted_expiration_date,
            upgrade_link=upgrade_link,
            upgrade_deadline=formatted_upgrade_deadline)
    else:
        bannerText = u'<strong>Audit Access Expires {expiration_date}</strong><br>\
                     You lose all access to this course, including your progress, on {expiration_date}.\
                     '.format(expiration_date=formatted_expiration_date)
    return bannerText
Ejemplo n.º 20
0
def get_expiration_banner_text(user, course):
    """
    Get text for banner that messages user course expiration date
    for different tests that depend on it.
    """
    expiration_date = (now() + timedelta(weeks=4)).strftime('%b. %-d, %Y')
    upgrade_link = verified_upgrade_deadline_link(user=user, course=course)
    enrollment = CourseEnrollment.get_enrollment(user, course.id)
    upgrade_deadline = enrollment.upgrade_deadline
    if upgrade_deadline is None:
        return
    if now() < upgrade_deadline:
        upgrade_deadline = enrollment.course_upgrade_deadline
    bannerText = '<strong>Audit Access Expires {expiration_date}</strong><br>\
                 You lose all access to this course, including your progress, on {expiration_date}.<br>\
                 Upgrade by {upgrade_deadline} to get unlimited access to the course as long as it exists on the site.\
                  <a href="{upgrade_link}">Upgrade now<span class="sr-only"> to retain access past {expiration_date}\
                 </span></a>'.format(
        expiration_date=expiration_date,
        upgrade_link=upgrade_link,
        upgrade_deadline=upgrade_deadline.strftime('%b. %-d, %Y'))
    return bannerText
Ejemplo n.º 21
0
def register_course_expired_message(request, course):
    """
    Add a banner notifying the user of the user course expiration date if it exists.
    """
    if not CourseDurationLimitConfig.enabled_for_enrollment(
            user=request.user, course_key=course.id):
        return

    expiration_date = get_user_course_expiration_date(request.user, course)
    if not expiration_date:
        return

    if is_masquerading_as_student(
            request.user, course.id) and timezone.now() > expiration_date:
        upgrade_message = _(
            'This learner would not have access to this course. '
            'Their access expired on {expiration_date}.')
        PageLevelMessages.register_warning_message(
            request,
            HTML(upgrade_message).format(
                expiration_date=expiration_date.strftime('%b %-d')))
    else:
        upgrade_message = _(
            'Your access to this course expires on {expiration_date}. \
                    {a_open}Upgrade now {sronly_span_open}to retain access past {expiration_date}.\
                    {span_close}{a_close}{sighted_only_span_open}for unlimited access.{span_close}'
        )
        PageLevelMessages.register_info_message(
            request,
            Text(upgrade_message).format(
                a_open=HTML('<a href="{upgrade_link}">').format(
                    upgrade_link=verified_upgrade_deadline_link(
                        user=request.user, course=course)),
                sronly_span_open=HTML('<span class="sr-only">'),
                sighted_only_span_open=HTML('<span aria-hidden="true">'),
                span_close=HTML('</span>'),
                a_close=HTML('</a>'),
                expiration_date=expiration_date.strftime('%b %-d'),
            ))
Ejemplo n.º 22
0
def register_course_expired_message(request, course):
    """
    Add a banner notifying the user of the user course expiration date if it exists.
    """
    if not CourseDurationLimitConfig.enabled_for_enrollment(user=request.user, course_key=course.id):
        return

    expiration_date = get_user_course_expiration_date(request.user, course)
    if not expiration_date:
        return

    if is_masquerading_as_student(request.user, course.id) and timezone.now() > expiration_date:
        upgrade_message = _('This learner would not have access to this course. '
                            'Their access expired on {expiration_date}.')
        PageLevelMessages.register_warning_message(
            request,
            HTML(upgrade_message).format(
                expiration_date=expiration_date.strftime('%b %-d')
            )
        )
    else:
        upgrade_message = _('Your access to this course expires on {expiration_date}. \
                    {a_open}Upgrade now {sronly_span_open}to retain access past {expiration_date}.\
                    {span_close}{a_close}{sighted_only_span_open}for unlimited access.{span_close}')
        PageLevelMessages.register_info_message(
            request,
            Text(upgrade_message).format(
                a_open=HTML('<a href="{upgrade_link}">').format(
                    upgrade_link=verified_upgrade_deadline_link(user=request.user, course=course)
                ),
                sronly_span_open=HTML('<span class="sr-only">'),
                sighted_only_span_open=HTML('<span aria-hidden="true">'),
                span_close=HTML('</span>'),
                a_close=HTML('</a>'),
                expiration_date=expiration_date.strftime('%b %-d'),
            )
        )
Ejemplo n.º 23
0
def generate_course_expired_message(user, course):
    """
    Generate the message for the user course expiration date if it exists.
    """
    if not CourseDurationLimitConfig.enabled_for_enrollment(user=user, course_key=course.id):
        return

    expiration_date = get_user_course_expiration_date(user, course)
    if not expiration_date:
        return

    if is_masquerading_as_specific_student(user, course.id) and timezone.now() > expiration_date:
        upgrade_message = _('This learner does not have access to this course. '
                            u'Their access expired on {expiration_date}.')
        return HTML(upgrade_message).format(
            expiration_date=strftime_localized(expiration_date, u'%b. %-d, %Y')
        )
    else:
        enrollment = CourseEnrollment.get_enrollment(user, course.id)
        if enrollment is None:
            return

        upgrade_deadline = enrollment.upgrade_deadline
        now = timezone.now()
        course_upgrade_deadline = enrollment.course_upgrade_deadline
        if (not upgrade_deadline) or (upgrade_deadline < now):
            upgrade_deadline = course_upgrade_deadline

        expiration_message = _(u'{strong_open}Audit Access Expires {expiration_date}{strong_close}'
                               u'{line_break}You lose all access to this course, including your progress, on '
                               u'{expiration_date}.')
        upgrade_deadline_message = _(u'{line_break}Upgrade by {upgrade_deadline} to get unlimited access to the course '
                                     u'as long as it exists on the site. {a_open}Upgrade now{sronly_span_open} to '
                                     u'retain access past {expiration_date}{span_close}{a_close}')
        full_message = expiration_message
        if upgrade_deadline and now < upgrade_deadline:
            full_message += upgrade_deadline_message
            using_upgrade_messaging = True
        else:
            using_upgrade_messaging = False

        language = get_language()
        date_string = get_date_string()
        formatted_expiration_date = date_string.format(
            language=language,
            formatted_date=expiration_date.strftime(u'%b %-d, %Y'),
            formatted_date_localized=strftime_localized(expiration_date, u'%b %-d, %Y')
        )
        if using_upgrade_messaging:
            formatted_upgrade_deadline = date_string.format(
                language=language,
                formatted_date=upgrade_deadline.strftime(u'%b %-d, %Y'),
                formatted_date_localized=strftime_localized(upgrade_deadline, u'%b %-d, %Y')
            )

            return HTML(full_message).format(
                a_open=HTML(u'<a href="{upgrade_link}">').format(
                    upgrade_link=verified_upgrade_deadline_link(user=user, course=course)
                ),
                sronly_span_open=HTML('<span class="sr-only">'),
                span_close=HTML('</span>'),
                a_close=HTML('</a>'),
                expiration_date=HTML(formatted_expiration_date),
                strong_open=HTML('<strong>'),
                strong_close=HTML('</strong>'),
                line_break=HTML('<br>'),
                upgrade_deadline=HTML(formatted_upgrade_deadline)
            )

        else:
            return HTML(full_message).format(
                span_close=HTML('</span>'),
                expiration_date=HTML(formatted_expiration_date),
                strong_open=HTML('<strong>'),
                strong_close=HTML('</strong>'),
                line_break=HTML('<br>'),
            )
Ejemplo n.º 24
0
def _get_verified_upgrade_link(user, schedule):
    enrollment = schedule.enrollment
    if enrollment.dynamic_upgrade_deadline is not None and verified_upgrade_link_is_valid(
            enrollment):
        return verified_upgrade_deadline_link(user, enrollment.course)
Ejemplo n.º 25
0
def register_course_expired_message(request, course):
    """
    Add a banner notifying the user of the user course expiration date if it exists.
    """
    if not CourseDurationLimitConfig.enabled_for_enrollment(
            user=request.user, course_key=course.id):
        return

    expiration_date = get_user_course_expiration_date(request.user, course)
    if not expiration_date:
        return

    if is_masquerading_as_specific_student(
            request.user, course.id) and timezone.now() > expiration_date:
        upgrade_message = _(
            'This learner does not have access to this course. '
            'Their access expired on {expiration_date}.')
        PageLevelMessages.register_warning_message(
            request,
            HTML(upgrade_message).format(expiration_date=strftime_localized(
                expiration_date, '%b. %-d, %Y')))
    else:
        enrollment = CourseEnrollment.get_enrollment(request.user, course.id)
        if enrollment is None:
            return

        upgrade_deadline = enrollment.upgrade_deadline
        now = timezone.now()
        course_upgrade_deadline = enrollment.course_upgrade_deadline
        if (not upgrade_deadline) or (upgrade_deadline < now):
            upgrade_deadline = course_upgrade_deadline

        expiration_message = _(
            '{strong_open}Audit Access Expires {expiration_date}{strong_close}'
            '{line_break}You lose all access to this course, including your progress, on '
            '{expiration_date}.')
        upgrade_deadline_message = _(
            '{line_break}Upgrade by {upgrade_deadline} to get unlimited access to the course '
            'as long as it exists on the site. {a_open}Upgrade now{sronly_span_open} to '
            'retain access past {expiration_date}{span_close}{a_close}')
        full_message = expiration_message
        if upgrade_deadline and now < upgrade_deadline:
            full_message += upgrade_deadline_message
            using_upgrade_messaging = True
        else:
            using_upgrade_messaging = False

        language = get_language()
        language_is_es = language and language.split('-')[0].lower() == 'es'
        if language_is_es:
            formatted_expiration_date = strftime_localized(
                expiration_date, '%-d de %b. de %Y').lower()
        else:
            formatted_expiration_date = strftime_localized(
                expiration_date, '%b. %-d, %Y')

        if using_upgrade_messaging:
            if language_is_es:
                formatted_upgrade_deadline = strftime_localized(
                    upgrade_deadline, '%-d de %b. de %Y').lower()
            else:
                formatted_upgrade_deadline = strftime_localized(
                    upgrade_deadline, '%b. %-d, %Y')

            PageLevelMessages.register_info_message(
                request,
                Text(full_message).format(
                    a_open=HTML('<a href="{upgrade_link}">').format(
                        upgrade_link=verified_upgrade_deadline_link(
                            user=request.user, course=course)),
                    sronly_span_open=HTML('<span class="sr-only">'),
                    span_close=HTML('</span>'),
                    a_close=HTML('</a>'),
                    expiration_date=formatted_expiration_date,
                    strong_open=HTML('<strong>'),
                    strong_close=HTML('</strong>'),
                    line_break=HTML('<br>'),
                    upgrade_deadline=formatted_upgrade_deadline))
        else:
            PageLevelMessages.register_info_message(
                request,
                Text(full_message).format(
                    span_close=HTML('</span>'),
                    expiration_date=formatted_expiration_date,
                    strong_open=HTML('<strong>'),
                    strong_close=HTML('</strong>'),
                    line_break=HTML('<br>'),
                ))
Ejemplo n.º 26
0
def generate_course_expired_message(user, course):
    """
    Generate the message for the user course expiration date if it exists.
    """
    if not CourseDurationLimitConfig.enabled_for_enrollment(user=user, course_key=course.id):
        return

    expiration_date = get_user_course_expiration_date(user, course)
    if not expiration_date:
        return

    if is_masquerading_as_specific_student(user, course.id) and timezone.now() > expiration_date:
        upgrade_message = _('This learner does not have access to this course. '
                            u'Their access expired on {expiration_date}.')
        return HTML(upgrade_message).format(
            expiration_date=strftime_localized(expiration_date, EXPIRATION_DATE_FORMAT_STR)
        )
    else:
        enrollment = CourseEnrollment.get_enrollment(user, course.id)
        if enrollment is None:
            return

        upgrade_deadline = enrollment.upgrade_deadline
        now = timezone.now()
        course_upgrade_deadline = enrollment.course_upgrade_deadline
        if (not upgrade_deadline) or (upgrade_deadline < now):
            upgrade_deadline = course_upgrade_deadline

        expiration_message = _(u'{strong_open}Audit Access Expires {expiration_date}{strong_close}'
                               u'{line_break}You lose all access to this course, including your progress, on '
                               u'{expiration_date}.')
        upgrade_deadline_message = _(u'{line_break}Upgrade by {upgrade_deadline} to get unlimited access to the course '
                                     u'as long as it exists on the site. {a_open}Upgrade now{sronly_span_open} to '
                                     u'retain access past {expiration_date}{span_close}{a_close}')
        full_message = expiration_message
        if upgrade_deadline and now < upgrade_deadline:
            full_message += upgrade_deadline_message
            using_upgrade_messaging = True
        else:
            using_upgrade_messaging = False

        language = get_language()
        date_string = get_date_string()
        formatted_expiration_date = date_string.format(
            language=language,
            formatted_date=expiration_date.strftime("%Y-%m-%d"),
            formatted_date_localized=strftime_localized(expiration_date, EXPIRATION_DATE_FORMAT_STR)
        )
        if using_upgrade_messaging:
            formatted_upgrade_deadline = date_string.format(
                language=language,
                formatted_date=upgrade_deadline.strftime("%Y-%m-%d"),
                formatted_date_localized=strftime_localized(upgrade_deadline, EXPIRATION_DATE_FORMAT_STR)
            )

            return HTML(full_message).format(
                a_open=HTML(u'<a href="{upgrade_link}">').format(
                    upgrade_link=verified_upgrade_deadline_link(user=user, course=course)
                ),
                sronly_span_open=HTML('<span class="sr-only">'),
                span_close=HTML('</span>'),
                a_close=HTML('</a>'),
                expiration_date=HTML(formatted_expiration_date),
                strong_open=HTML('<strong>'),
                strong_close=HTML('</strong>'),
                line_break=HTML('<br>'),
                upgrade_deadline=HTML(formatted_upgrade_deadline)
            )

        else:
            return HTML(full_message).format(
                span_close=HTML('</span>'),
                expiration_date=HTML(formatted_expiration_date),
                strong_open=HTML('<strong>'),
                strong_close=HTML('</strong>'),
                line_break=HTML('<br>'),
            )
Ejemplo n.º 27
0
def _get_verified_upgrade_link(user, schedule):
    enrollment = schedule.enrollment
    if enrollment.is_active:
        return verified_upgrade_deadline_link(user, enrollment.course)
    def render_to_fragment(self,
                           request,
                           course_id,
                           user_is_enrolled=True,
                           **kwargs):  # pylint: disable=arguments-differ
        """
        Renders the course outline as a fragment.
        """
        from lms.urls import RESET_COURSE_DEADLINES_NAME
        from openedx.features.course_experience.urls import COURSE_HOME_VIEW_NAME

        course_key = CourseKey.from_string(course_id)
        course_overview = get_course_overview_with_access(
            request.user,
            'load',
            course_key,
            check_if_enrolled=user_is_enrolled)
        course = modulestore().get_course(course_key)

        course_block_tree = get_course_outline_block_tree(
            request, course_id, request.user if user_is_enrolled else None)
        if not course_block_tree:
            return None

        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course_overview,
            'due_date_display_format': course.due_date_display_format,
            'blocks': course_block_tree,
            'enable_links': user_is_enrolled
            or course.course_visibility == COURSE_VISIBILITY_PUBLIC,
            'course_key': course_key,
        }

        resume_block = get_resume_block(
            course_block_tree) if user_is_enrolled else None

        if not resume_block:
            self.mark_first_unit_to_resume(course_block_tree)

        xblock_display_names = self.create_xblock_id_and_name_dict(
            course_block_tree)
        gated_content = self.get_content_milestones(request, course_key)

        context['gated_content'] = gated_content
        context['xblock_display_names'] = xblock_display_names

        page_context = kwargs.get('page_context', None)
        if page_context:
            context['self_paced'] = page_context.get(
                'pacing_type', 'instructor_paced') == 'self_paced'

        # We're using this flag to prevent old self-paced dates from leaking out on courses not
        # managed by edx-when.
        context['in_edx_when'] = edx_when_api.is_enabled_for_course(course_key)

        reset_deadlines_url = reverse(RESET_COURSE_DEADLINES_NAME)
        reset_deadlines_redirect_url_base = COURSE_HOME_VIEW_NAME

        course_enrollment = None
        if not request.user.is_anonymous:
            course_enrollment = CourseEnrollment.objects.filter(
                course=course_overview, user=request.user).filter(
                    Q(mode=CourseMode.AUDIT)
                    | Q(mode=CourseMode.VERIFIED)).first()

        context['reset_deadlines_url'] = reset_deadlines_url
        context[
            'reset_deadlines_redirect_url_base'] = reset_deadlines_redirect_url_base
        context['reset_deadlines_redirect_url_id_dict'] = {
            'course_id': str(course.id)
        }
        context['enrollment_mode'] = getattr(course_enrollment, 'mode', None)
        context['verified_upgrade_link'] = verified_upgrade_deadline_link(
            request.user, course=course),
        context['on_course_outline_page'] = True,

        html = render_to_string(
            'course_experience/course-outline-fragment.html', context)
        return Fragment(html)