Exemple #1
0
def mobi_course_action(request, course_id, action):
    try:
        course_id_bak = course_id.replace('.', '/')
        if action in ["updates", "handouts", "structure"]:
            course = get_course_with_access(request.user, course_id_bak, 'see_exists')
            user = request.user
            if not user:
                user = AnonymousUser()

            registered = registered_for_course(course, user)

            if action == "updates" and registered:
                course_updates = get_course_info_section(request, course, action)
                return JsonResponse(parse_updates_html_str(course_updates))
            elif action == "handouts" and registered:
                course_handouts = get_course_info_section(request, course, action)
                return JsonResponse({"handouts": course_handouts})
            elif action == "structure":
                return JsonResponse(_course_json(course, course.location.course_id))
            else:
                raise Exception
        else:
            course = get_course_with_access(request.user, course_id_bak, 'see_exists')
            return JsonResponse(mobi_course_info(request, course))
    except:
        return JsonResponse({"success": False, "errmsg": "access denied!"})
Exemple #2
0
def mobi_course_action(request, course_id, action):
    try:
        course_id_bak = course_id.replace('.', '/')
        if action in ["updates", "handouts", "structure"]:
            course = get_course_with_access(request.user, course_id_bak, 'see_exists')
            user = request.user
            if not user:
                user = AnonymousUser()

            registered = registered_for_course(course, user)

            if action == "updates" and registered:
                course_updates = get_course_info_section(request, course, action)
                return JsonResponse(parse_updates_html_str(course_updates))
            elif action == "handouts" and registered:
                course_handouts = get_course_info_section(request, course, action)
                return JsonResponse({"handouts": course_handouts})
            elif action == "structure":
                return JsonResponse(_course_json(course, course.location.course_id))
            else:
                raise Exception
        else:
            course = get_course_with_access(request.user, course_id_bak, 'see_exists')
            return JsonResponse(mobi_course_info(request, course))
    except:
        return JsonResponse({"success": False, "errmsg": "access denied!"})
Exemple #3
0
    def test_get_course_info_section_render(self):
        # Test render works okay
        course_info = get_course_info_section(self.request, self.request.user, self.course, "handouts")
        self.assertEqual(course_info, u"<a href='/c4x/edX/toy/asset/handouts_sample_handout.txt'>Sample</a>")

        # Test when render raises an exception
        with mock.patch("courseware.courses.get_module") as mock_module_render:
            mock_module_render.return_value = mock.MagicMock(render=mock.Mock(side_effect=Exception("Render failed!")))
            course_info = get_course_info_section(self.request, self.request.user, self.course, "handouts")
            self.assertIn("this module is temporarily unavailable", course_info)
Exemple #4
0
    def test_get_course_info_section_render(self):
        # Test render works okay
        course_info = get_course_info_section(self.request, self.request.user, self.course, 'handouts')
        self.assertEqual(course_info, u"<a href='/c4x/edX/toy/asset/handouts_sample_handout.txt'>Sample</a>")

        # Test when render raises an exception
        with mock.patch('courseware.courses.get_module') as mock_module_render:
            mock_module_render.return_value = mock.MagicMock(
                render=mock.Mock(side_effect=Exception('Render failed!'))
            )
            course_info = get_course_info_section(self.request, self.request.user, self.course, 'handouts')
            self.assertIn("this module is temporarily unavailable", course_info)
Exemple #5
0
    def test_get_course_info_section_render(self):
        course = get_course_by_id(self.toy_course_key)
        request = get_request_for_user(UserFactory.create())

        # Test render works okay
        course_info = get_course_info_section(request, course, 'handouts')
        self.assertEqual(course_info, "<a href='/static/toy/handouts/sample_handout.txt'>Sample</a>")

        # Test when render raises an exception
        with mock.patch('courseware.courses.get_module') as mock_module_render:
            mock_module_render.return_value = mock.MagicMock(
                render=mock.Mock(side_effect=Exception('Render failed!'))
            )
            course_info = get_course_info_section(request, course, 'handouts')
            self.assertIn("this module is temporarily unavailable", course_info)
    def test_get_course_info_section_render(self):
        course = get_course_by_id(self.toy_course_key)
        request = get_request_for_user(UserFactory.create())

        # Test render works okay. Note the href is different in XML courses.
        course_info = get_course_info_section(request, course, 'handouts')
        self.assertEqual(course_info, "<a href='/static/toy/handouts/sample_handout.txt'>Sample</a>")

        # Test when render raises an exception
        with mock.patch('courseware.courses.get_module') as mock_module_render:
            mock_module_render.return_value = mock.MagicMock(
                render=mock.Mock(side_effect=Exception('Render failed!'))
            )
            course_info = get_course_info_section(request, course, 'handouts')
            self.assertIn("this module is temporarily unavailable", course_info)
Exemple #7
0
    def render_to_fragment(self, request, course_id=None, **kwargs):
        """
        Renders the course's home page as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user,
                                        'load',
                                        course_key,
                                        check_if_enrolled=True)
        course_url_name = defaut_course_url_name(request)
        course_url = reverse(course_url_name,
                             kwargs={'course_id': unicode(course.id)})

        # Fetch the updates as HTML
        updates_html = get_course_info_section(request, request.user, course,
                                               'updates')

        # Render the course home fragment
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'course_url': course_url,
            'updates_html': updates_html,
            'disable_courseware_js': True,
            'uses_pattern_library': True,
        }
        html = render_to_string(
            'course_experience/course-updates-fragment.html', context)
        return Fragment(html)
    def render_to_fragment(self, request, course_id=None, **kwargs):
        """
        Renders the course's home page as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user,
                                        'load',
                                        course_key,
                                        check_if_enrolled=True)

        # Render the outline as a fragment
        outline_fragment = CourseOutlineFragmentView().render_to_fragment(
            request, course_id=course_id, **kwargs)

        # Get the last accessed courseware
        last_accessed_url, __ = get_last_accessed_courseware(
            course, request, request.user)

        # Get the handouts
        handouts_html = get_course_info_section(request, request.user, course,
                                                'handouts')

        # Render the course home fragment
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'outline_fragment': outline_fragment,
            'handouts_html': handouts_html,
            'has_visited_course': last_accessed_url is not None,
            'disable_courseware_js': True,
            'uses_pattern_library': True,
        }
        html = render_to_string('course_experience/course-home-fragment.html',
                                context)
        return Fragment(html)
 def _get_course_handouts(self, request, course):
     """
     Returns the handouts for the specified course.
     """
     handouts = get_course_info_section(request, request.user, course, 'handouts')
     if not handouts or handouts == EMPTY_HANDOUTS_HTML:
         return None
     return handouts
Exemple #10
0
 def _get_course_handouts(self, request, course):
     """
     Returns the handouts for the specified course.
     """
     handouts = get_course_info_section(request, request.user, course, 'handouts')
     if not handouts or handouts == EMPTY_HANDOUTS_HTML:
         return None
     return handouts
Exemple #11
0
    def render_to_fragment(self, request, course_id=None, **kwargs):
        """
        Renders the course's home page as a fragment.
        """
        course_key = CourseKey.from_string(course_id)

        # Render the outline as a fragment
        outline_fragment = CourseOutlineFragmentView().render_to_fragment(
            request, course_id=course_id, **kwargs)

        # Get resume course information
        has_visited_course, resume_course_url = self._get_resume_course_info(
            request, course_id)

        # Render the welcome message as a fragment
        welcome_message_fragment = WelcomeMessageFragmentView(
        ).render_to_fragment(request, course_id=course_id, **kwargs)

        # Render the course dates as a fragment
        dates_fragment = CourseDatesFragmentView().render_to_fragment(
            request, course_id=course_id, **kwargs)

        # TODO: Use get_course_overview_with_access and blocks api
        course = get_course_with_access(request.user,
                                        'load',
                                        course_key,
                                        check_if_enrolled=True)

        # Render the verification sock as a fragment
        course_sock_fragment = CourseSockFragmentView().render_to_fragment(
            request, course=course, **kwargs)

        # Get the handouts
        handouts_html = get_course_info_section(request, request.user, course,
                                                'handouts')

        # Only show the reviews button if configured
        show_reviews_link = CourseReviewsModuleFragmentView.is_configured()

        # Render the course home fragment
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'course_key': course_key,
            'outline_fragment': outline_fragment,
            'handouts_html': handouts_html,
            'has_visited_course': has_visited_course,
            'resume_course_url': resume_course_url,
            'dates_fragment': dates_fragment,
            'welcome_message_fragment': welcome_message_fragment,
            'course_sock_fragment': course_sock_fragment,
            'disable_courseware_js': True,
            'uses_pattern_library': True,
            'show_reviews_link': show_reviews_link,
        }
        html = render_to_string('course_experience/course-home-fragment.html',
                                context)
        return Fragment(html)
Exemple #12
0
def mobi_course_action(request, course_id, action):
    try:
        course_id_bak = course_id.replace('.', '/')
        if action in ["updates", "handouts", "structure"]:
            user = request.user
            if not user:
                user = AnonymousUser()

            course = get_course_with_access(user, course_id_bak, 'load')
            registered = registered_for_course(course, user)

            if action == "updates" and registered:
                # course_updates = get_course_info_section(request, course, action)
                loc = Location(course.location.tag, course.location.org,
                               course.location.course, 'course_info', action)
                field_data_cache = FieldDataCache([], course.id, request.user)
                course_module = get_module(
                    user,
                    request,
                    loc,
                    field_data_cache,
                    course.id,
                    wrap_xmodule_display=False,
                    static_asset_path=course.static_asset_path)
                return JsonResponse({
                    'updates': [
                        item for item in course_module.items
                        if item["status"] != "deleted"
                    ]
                })
            elif action == "handouts" and registered:
                course_handouts = get_course_info_section(
                    request, course, action)
                return JsonResponse({"handouts": course_handouts})
            elif action == "structure":
                url_name = request.get_host(
                ) + '/m/courses/' + course_id_bak + '/courseware'
                return JsonResponse(
                    _course_json(course=course,
                                 course_id=course.location.course_id,
                                 url_name=url_name))
            else:
                raise Exception
        else:
            course = get_course_with_access(request.user, course_id_bak,
                                            'see_exists')
            return JsonResponse(mobi_course_info(request, course))
    except:
        return JsonResponse({"success": False, "errmsg": "access denied!"})
    def render_to_fragment(self, request, course_id=None, **kwargs):
        """
        Renders the course's home page as a fragment.
        """
        course_key = CourseKey.from_string(course_id)

        # Render the outline as a fragment
        outline_fragment = CourseOutlineFragmentView().render_to_fragment(request, course_id=course_id, **kwargs)

        # Get resume course information
        has_visited_course, resume_course_url = self._get_resume_course_info(request, course_id)

        # Render the welcome message as a fragment
        welcome_message_fragment = WelcomeMessageFragmentView().render_to_fragment(
            request, course_id=course_id, **kwargs
        )

        # Render the course dates as a fragment
        dates_fragment = CourseDatesFragmentView().render_to_fragment(request, course_id=course_id, **kwargs)

        # TODO: Use get_course_overview_with_access and blocks api
        course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)

        # Render the verification sock as a fragment
        course_sock_fragment = CourseSockFragmentView().render_to_fragment(request, course=course, **kwargs)

        # Get the handouts
        handouts_html = get_course_info_section(request, request.user, course, 'handouts')

        # Render the course home fragment
        context = {
            'request': request,
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'course_key': course_key,
            'outline_fragment': outline_fragment,
            'handouts_html': handouts_html,
            'has_visited_course': has_visited_course,
            'resume_course_url': resume_course_url,
            'dates_fragment': dates_fragment,
            'welcome_message_fragment': welcome_message_fragment,
            'course_sock_fragment': course_sock_fragment,
            'disable_courseware_js': True,
            'uses_pattern_library': True,
        }
        html = render_to_string('course_experience/course-home-fragment.html', context)
        return Fragment(html)
Exemple #14
0
def mobi_course_action(request, course_id, action):
    try:
        course_id_bak = course_id.replace('.', '/')
        if action in ["updates", "handouts", "structure"]:
            user = request.user
            if not user:
                user = AnonymousUser()

            course = get_course_with_access(user, course_id_bak, 'load')
            registered = registered_for_course(course, user)

            if action == "updates" and registered:
                # course_updates = get_course_info_section(request, course, action)
                loc = Location(course.location.tag, course.location.org, course.location.course, 'course_info', action)
                field_data_cache = FieldDataCache([], course.id, request.user)
                # course_module = get_module(
                #     user,
                #     request,
                #     loc,
                #     field_data_cache,
                #     course.id,
                #     wrap_xmodule_display=False,
                #     static_asset_path=course.static_asset_path
                # )
                print "======================= " * 4
                course_module_des = get_module_for_descriptor(user, request, course, field_data_cache, course.id)
                print "----------------------- " * 4
                print course_module_des["get_module"]
                return JsonResponse({'updates': course_module_des.items})
            elif action == "handouts" and registered:
                course_handouts = get_course_info_section(request, course, action)
                return JsonResponse({"handouts": course_handouts})
            elif action == "structure":
                url_name = request.get_host() + '/m/courses/' + course_id_bak + '/courseware'
                return JsonResponse(_course_json(course=course, course_id=course.location.course_id, url_name=url_name))
            else:
                raise Exception
        else:
            course = get_course_with_access(request.user, course_id_bak, 'see_exists')
            return JsonResponse(mobi_course_info(request, course))
    except:
        return JsonResponse({"success": False, "errmsg": "access denied!"})
 def test_get_course_info_section(self):
     self.course.static_asset_path = "toy_course_dir"
     get_course_info_section(self.request, self.course, "handouts")
 def test_get_course_info_section(self):
     self.course.static_asset_path = "toy_course_dir"
     get_course_info_section(self.request, self.course, "handouts")