Ejemplo n.º 1
0
 def test_pre_requisite_course(self):
     pre_requisite_course = CourseFactory.create(org='edX', course='900', display_name='pre requisite course')
     course = CourseFactory.create(pre_requisite_courses=[text_type(pre_requisite_course.id)])
     self.setup_user()
     url = reverse('about_course', args=[text_type(course.id)])
     resp = self.client.get(url)
     self.assertEqual(resp.status_code, 200)
     pre_requisite_courses = get_prerequisite_courses_display(course)
     pre_requisite_course_about_url = reverse('about_course', args=[text_type(pre_requisite_courses[0]['key'])])
     self.assertIn("<span class=\"important-dates-item-text pre-requisite\"><a href=\"{}\">{}</a></span>"
                   .format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']),
                   resp.content.strip('\n'))
Ejemplo n.º 2
0
 def test_pre_requisite_course(self):
     pre_requisite_course = CourseFactory.create(org='edX', course='900', display_name='pre requisite course')
     course = CourseFactory.create(pre_requisite_courses=[text_type(pre_requisite_course.id)])
     self.setup_user()
     url = reverse('about_course', args=[text_type(course.id)])
     resp = self.client.get(url)
     self.assertEqual(resp.status_code, 200)
     pre_requisite_courses = get_prerequisite_courses_display(course)
     pre_requisite_course_about_url = reverse('about_course', args=[text_type(pre_requisite_courses[0]['key'])])
     self.assertIn(u"<span class=\"important-dates-item-text pre-requisite\"><a href=\"{}\">{}</a></span>"
                   .format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']),
                   resp.content.decode(resp.charset).strip('\n'))
Ejemplo n.º 3
0
 def test_pre_requisite_course(self):
     pre_requisite_course = CourseFactory.create(org="edX", course="900", display_name="pre requisite course")
     course = CourseFactory.create(pre_requisite_courses=[unicode(pre_requisite_course.id)])
     self.setup_user()
     url = reverse("about_course", args=[unicode(course.id)])
     resp = self.client.get(url)
     self.assertEqual(resp.status_code, 200)
     pre_requisite_courses = get_prerequisite_courses_display(course)
     pre_requisite_course_about_url = reverse("about_course", args=[unicode(pre_requisite_courses[0]["key"])])
     self.assertIn(
         '<span class="important-dates-item-text pre-requisite"><a href="{}">{}</a></span>'.format(
             pre_requisite_course_about_url, pre_requisite_courses[0]["display"]
         ),
         resp.content.strip("\n"),
     )
Ejemplo n.º 4
0
    def test_about_page_unfulfilled_prereqs(self):
        pre_requisite_course = CourseFactory.create(
            org='edX',
            course='901',
            display_name='pre requisite course',
        )

        pre_requisite_courses = [text_type(pre_requisite_course.id)]

        # for this failure to occur, the enrollment window needs to be in the past
        course = CourseFactory.create(
            org='edX',
            course='1000',
            # closed enrollment
            enrollment_start=datetime.datetime(2013, 1, 1),
            enrollment_end=datetime.datetime(2014, 1, 1),
            start=datetime.datetime(2013, 1, 1),
            end=datetime.datetime(2030, 1, 1),
            pre_requisite_courses=pre_requisite_courses,
        )
        set_prerequisite_courses(course.id, pre_requisite_courses)

        self.setup_user()
        self.enroll(self.course, True)
        self.enroll(pre_requisite_course, True)

        url = reverse('about_course', args=[text_type(course.id)])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        pre_requisite_courses = get_prerequisite_courses_display(course)
        pre_requisite_course_about_url = reverse(
            'about_course', args=[text_type(pre_requisite_courses[0]['key'])])
        self.assertIn(
            u"<span class=\"important-dates-item-text pre-requisite\"><a href=\"{}\">{}</a></span>"
            .format(pre_requisite_course_about_url,
                    pre_requisite_courses[0]['display']),
            resp.content.decode(resp.charset).strip('\n'))

        url = reverse('about_course',
                      args=[six.text_type(pre_requisite_course.id)])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
Ejemplo n.º 5
0
    def test_about_page_unfulfilled_prereqs(self):
        seed_milestone_relationship_types()
        pre_requisite_course = CourseFactory.create(
            org='edX',
            course='900',
            display_name='pre requisite course',
        )

        pre_requisite_courses = [unicode(pre_requisite_course.id)]

        # for this failure to occur, the enrollment window needs to be in the past
        course = CourseFactory.create(
            org='edX',
            course='1000',
            # closed enrollment
            enrollment_start=datetime.datetime(2013, 1, 1),
            enrollment_end=datetime.datetime(2014, 1, 1),
            start=datetime.datetime(2013, 1, 1),
            end=datetime.datetime(2030, 1, 1),
            pre_requisite_courses=pre_requisite_courses,
        )
        set_prerequisite_courses(course.id, pre_requisite_courses)

        self.setup_user()
        self.enroll(self.course, True)
        self.enroll(pre_requisite_course, True)

        url = reverse('about_course', args=[unicode(course.id)])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        pre_requisite_courses = get_prerequisite_courses_display(course)
        pre_requisite_course_about_url = reverse('about_course', args=[unicode(pre_requisite_courses[0]['key'])])
        self.assertIn("<span class=\"important-dates-item-text pre-requisite\"><a href=\"{}\">{}</a></span>"
                      .format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']),
                      resp.content.strip('\n'))

        url = reverse('about_course', args=[unicode(pre_requisite_course.id)])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
Ejemplo n.º 6
0
    def test_about_page_unfulfilled_prereqs(self):
        pre_requisite_course = CourseFactory.create(org="edX", course="901", display_name="pre requisite course")

        pre_requisite_courses = [unicode(pre_requisite_course.id)]

        # for this failure to occur, the enrollment window needs to be in the past
        course = CourseFactory.create(
            org="edX",
            course="1000",
            # closed enrollment
            enrollment_start=datetime.datetime(2013, 1, 1),
            enrollment_end=datetime.datetime(2014, 1, 1),
            start=datetime.datetime(2013, 1, 1),
            end=datetime.datetime(2030, 1, 1),
            pre_requisite_courses=pre_requisite_courses,
        )
        set_prerequisite_courses(course.id, pre_requisite_courses)

        self.setup_user()
        self.enroll(self.course, True)
        self.enroll(pre_requisite_course, True)

        url = reverse("about_course", args=[unicode(course.id)])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        pre_requisite_courses = get_prerequisite_courses_display(course)
        pre_requisite_course_about_url = reverse("about_course", args=[unicode(pre_requisite_courses[0]["key"])])
        self.assertIn(
            '<span class="important-dates-item-text pre-requisite"><a href="{}">{}</a></span>'.format(
                pre_requisite_course_about_url, pre_requisite_courses[0]["display"]
            ),
            resp.content.strip("\n"),
        )

        url = reverse("about_course", args=[unicode(pre_requisite_course.id)])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
Ejemplo n.º 7
0
def course_about(request, course_id):
    """
    Display the course's about page.

    Assumes the course_id is in a valid format.
    """

    course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)

    with modulestore().bulk_operations(course_key):
        permission_name = microsite.get_value(
            'COURSE_ABOUT_VISIBILITY_PERMISSION',
            settings.COURSE_ABOUT_VISIBILITY_PERMISSION
        )
        course = get_course_with_access(request.user, permission_name, course_key)

        if microsite.get_value('ENABLE_MKTG_SITE', settings.FEATURES.get('ENABLE_MKTG_SITE', False)):
            return redirect(reverse('info', args=[course.id.to_deprecated_string()]))

        registered = registered_for_course(course, request.user)

        staff_access = has_access(request.user, 'staff', course)
        studio_url = get_studio_url(course, 'settings/details')

        if has_access(request.user, 'load', course):
            course_target = reverse('info', args=[course.id.to_deprecated_string()])
        else:
            course_target = reverse('about_course', args=[course.id.to_deprecated_string()])

        show_courseware_link = (
            (
                has_access(request.user, 'load', course)
                and has_access(request.user, 'view_courseware_with_prerequisites', course)
            )
            or settings.FEATURES.get('ENABLE_LMS_MIGRATION')
        )

        # Note: this is a flow for payment for course registration, not the Verified Certificate flow.
        registration_price = 0
        in_cart = False
        reg_then_add_to_cart_link = ""

        _is_shopping_cart_enabled = is_shopping_cart_enabled()
        if _is_shopping_cart_enabled:
            registration_price = CourseMode.min_course_price_for_currency(course_key,
                                                                          settings.PAID_COURSE_REGISTRATION_CURRENCY[0])
            if request.user.is_authenticated():
                cart = shoppingcart.models.Order.get_cart_for_user(request.user)
                in_cart = shoppingcart.models.PaidCourseRegistration.contained_in_order(cart, course_key) or \
                    shoppingcart.models.CourseRegCodeItem.contained_in_order(cart, course_key)

            reg_then_add_to_cart_link = "{reg_url}?course_id={course_id}&enrollment_action=add_to_cart".format(
                reg_url=reverse('register_user'), course_id=course.id.to_deprecated_string())

        course_price = get_cosmetic_display_price(course, registration_price)
        can_add_course_to_cart = _is_shopping_cart_enabled and registration_price

        # Used to provide context to message to student if enrollment not allowed
        can_enroll = has_access(request.user, 'enroll', course)
        invitation_only = course.invitation_only
        is_course_full = CourseEnrollment.is_course_full(course)

        # Register button should be disabled if one of the following is true:
        # - Student is already registered for course
        # - Course is already full
        # - Student cannot enroll in course
        active_reg_button = not(registered or is_course_full or not can_enroll)

        is_shib_course = uses_shib(course)

        # get prerequisite courses display names
        pre_requisite_courses = get_prerequisite_courses_display(course)

        return render_to_response('courseware/course_about.html', {
            'course': course,
            'staff_access': staff_access,
            'studio_url': studio_url,
            'registered': registered,
            'course_target': course_target,
            'is_cosmetic_price_enabled': settings.FEATURES.get('ENABLE_COSMETIC_DISPLAY_PRICE'),
            'course_price': course_price,
            'in_cart': in_cart,
            'reg_then_add_to_cart_link': reg_then_add_to_cart_link,
            'show_courseware_link': show_courseware_link,
            'is_course_full': is_course_full,
            'can_enroll': can_enroll,
            'invitation_only': invitation_only,
            'active_reg_button': active_reg_button,
            'is_shib_course': is_shib_course,
            # We do not want to display the internal courseware header, which is used when the course is found in the
            # context. This value is therefor explicitly set to render the appropriate header.
            'disable_courseware_header': True,
            'can_add_course_to_cart': can_add_course_to_cart,
            'cart_link': reverse('shoppingcart.views.show_cart'),
            'pre_requisite_courses': pre_requisite_courses
        })
Ejemplo n.º 8
0
def course_about(request, course_id):
    """
    Display the course's about page.

    Assumes the course_id is in a valid format.
    """

    course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)

    with modulestore().bulk_operations(course_key):
        permission_name = microsite.get_value(
            'COURSE_ABOUT_VISIBILITY_PERMISSION',
            settings.COURSE_ABOUT_VISIBILITY_PERMISSION
        )
        course = get_course_with_access(request.user, permission_name, course_key)

        if microsite.get_value('ENABLE_MKTG_SITE', settings.FEATURES.get('ENABLE_MKTG_SITE', False)):
            return redirect(reverse('info', args=[course.id.to_deprecated_string()]))

        registered = registered_for_course(course, request.user)

        staff_access = has_access(request.user, 'staff', course)
        studio_url = get_studio_url(course, 'settings/details')

        if has_access(request.user, 'load', course):
            course_target = reverse('info', args=[course.id.to_deprecated_string()])
        else:
            course_target = reverse('about_course', args=[course.id.to_deprecated_string()])

        show_courseware_link = (
            (
                has_access(request.user, 'load', course)
                and has_access(request.user, 'view_courseware_with_prerequisites', course)
            )
            or settings.FEATURES.get('ENABLE_LMS_MIGRATION')
        )

        # Note: this is a flow for payment for course registration, not the Verified Certificate flow.
        registration_price = 0
        in_cart = False
        reg_then_add_to_cart_link = ""

        _is_shopping_cart_enabled = is_shopping_cart_enabled()
        if _is_shopping_cart_enabled:
            registration_price = CourseMode.min_course_price_for_currency(course_key,
                                                                          settings.PAID_COURSE_REGISTRATION_CURRENCY[0])
            if request.user.is_authenticated():
                cart = shoppingcart.models.Order.get_cart_for_user(request.user)
                in_cart = shoppingcart.models.PaidCourseRegistration.contained_in_order(cart, course_key) or \
                    shoppingcart.models.CourseRegCodeItem.contained_in_order(cart, course_key)

            reg_then_add_to_cart_link = "{reg_url}?course_id={course_id}&enrollment_action=add_to_cart".format(
                reg_url=reverse('register_user'), course_id=course.id.to_deprecated_string())

        # Used to provide context to message to student if enrollment not allowed
        can_enroll = has_access(request.user, 'enroll', course)
        invitation_only = course.invitation_only
        is_course_full = CourseEnrollment.is_course_full(course)

        # Register button should be disabled if one of the following is true:
        # - Student is already registered for course
        # - Course is already full
        # - Student cannot enroll in course
        active_reg_button = not(registered or is_course_full or not can_enroll)

        is_shib_course = uses_shib(course)

        # get prerequisite courses display names
        pre_requisite_courses = get_prerequisite_courses_display(course)

        return render_to_response('courseware/course_about.html', {
            'course': course,
            'staff_access': staff_access,
            'studio_url': studio_url,
            'registered': registered,
            'course_target': course_target,
            'registration_price': registration_price,
            'currency_symbol': settings.PAID_COURSE_REGISTRATION_CURRENCY[1],
            'in_cart': in_cart,
            'reg_then_add_to_cart_link': reg_then_add_to_cart_link,
            'show_courseware_link': show_courseware_link,
            'is_course_full': is_course_full,
            'can_enroll': can_enroll,
            'invitation_only': invitation_only,
            'active_reg_button': active_reg_button,
            'is_shib_course': is_shib_course,
            # We do not want to display the internal courseware header, which is used when the course is found in the
            # context. This value is therefor explicitly set to render the appropriate header.
            'disable_courseware_header': True,
            'is_shopping_cart_enabled': _is_shopping_cart_enabled,
            'cart_link': reverse('shoppingcart.views.show_cart'),
            'pre_requisite_courses': pre_requisite_courses
        })
Ejemplo n.º 9
0
def course_about(request, course_id):
    """
    Display the course's about page.

    Assumes the course_id is in a valid format.
    """

    course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)

    with modulestore().bulk_operations(course_key):
        permission_name = microsite.get_value(
            "COURSE_ABOUT_VISIBILITY_PERMISSION", settings.COURSE_ABOUT_VISIBILITY_PERMISSION
        )
        course = get_course_with_access(request.user, permission_name, course_key)

        if microsite.get_value("ENABLE_MKTG_SITE", settings.FEATURES.get("ENABLE_MKTG_SITE", False)):
            return redirect(reverse("info", args=[course.id.to_deprecated_string()]))

        registered = registered_for_course(course, request.user)

        staff_access = has_access(request.user, "staff", course)
        studio_url = get_studio_url(course, "settings/details")

        if has_access(request.user, "load", course):
            course_target = reverse("info", args=[course.id.to_deprecated_string()])
        else:
            course_target = reverse("about_course", args=[course.id.to_deprecated_string()])

        show_courseware_link = (
            has_access(request.user, "load", course)
            and has_access(request.user, "view_courseware_with_prerequisites", course)
        ) or settings.FEATURES.get("ENABLE_LMS_MIGRATION")

        # Note: this is a flow for payment for course registration, not the Verified Certificate flow.
        registration_price = 0
        in_cart = False
        reg_then_add_to_cart_link = ""

        _is_shopping_cart_enabled = is_shopping_cart_enabled()
        if _is_shopping_cart_enabled:
            registration_price = CourseMode.min_course_price_for_currency(
                course_key, settings.PAID_COURSE_REGISTRATION_CURRENCY[0]
            )
            if request.user.is_authenticated():
                cart = shoppingcart.models.Order.get_cart_for_user(request.user)
                in_cart = shoppingcart.models.PaidCourseRegistration.contained_in_order(
                    cart, course_key
                ) or shoppingcart.models.CourseRegCodeItem.contained_in_order(cart, course_key)

            reg_then_add_to_cart_link = "{reg_url}?course_id={course_id}&enrollment_action=add_to_cart".format(
                reg_url=reverse("register_user"), course_id=course.id.to_deprecated_string()
            )

        course_price = get_cosmetic_display_price(course, registration_price)

        # Used to provide context to message to student if enrollment not allowed
        can_enroll = has_access(request.user, "enroll", course)
        invitation_only = course.invitation_only
        is_course_full = CourseEnrollment.is_course_full(course)

        # Register button should be disabled if one of the following is true:
        # - Student is already registered for course
        # - Course is already full
        # - Student cannot enroll in course
        active_reg_button = not (registered or is_course_full or not can_enroll)

        is_shib_course = uses_shib(course)

        # get prerequisite courses display names
        pre_requisite_courses = get_prerequisite_courses_display(course)

        return render_to_response(
            "courseware/course_about.html",
            {
                "course": course,
                "staff_access": staff_access,
                "studio_url": studio_url,
                "registered": registered,
                "course_target": course_target,
                "is_cosmetic_price_enabled": settings.FEATURES.get("ENABLE_COSMETIC_DISPLAY_PRICE"),
                "course_price": course_price,
                "in_cart": in_cart,
                "reg_then_add_to_cart_link": reg_then_add_to_cart_link,
                "show_courseware_link": show_courseware_link,
                "is_course_full": is_course_full,
                "can_enroll": can_enroll,
                "invitation_only": invitation_only,
                "active_reg_button": active_reg_button,
                "is_shib_course": is_shib_course,
                # We do not want to display the internal courseware header, which is used when the course is found in the
                # context. This value is therefor explicitly set to render the appropriate header.
                "disable_courseware_header": True,
                "is_shopping_cart_enabled": _is_shopping_cart_enabled,
                "cart_link": reverse("shoppingcart.views.show_cart"),
                "pre_requisite_courses": pre_requisite_courses,
            },
        )