コード例 #1
0
ファイル: views.py プロジェクト: andela-ijubril/edx-platform
def users(request, course_id):
    """
    Given a `username` query parameter, find matches for users in the forum for this course.

    Only exact matches are supported here, so the length of the result set will either be 0 or 1.
    """

    course_key = CourseKey.from_string(course_id)
    try:
        get_course_overview_with_access(request.user, 'load', course_key, check_if_enrolled=True)
    except Http404:
        # course didn't exist, or requesting user does not have access to it.
        return JsonError(status=404)

    try:
        username = request.GET['username']
    except KeyError:
        # 400 is default status for JsonError
        return JsonError(["username parameter is required"])

    user_objs = []
    try:
        matched_user = User.objects.get(username=username)
        cc_user = cc.User.from_django_user(matched_user)
        cc_user.course_id = course_key
        cc_user.retrieve(complete=False)
        if (cc_user['threads_count'] + cc_user['comments_count']) > 0:
            user_objs.append({
                'id': matched_user.id,
                'username': matched_user.username,
            })
    except User.DoesNotExist:
        pass
    return JsonResponse({"users": user_objs})
コード例 #2
0
 def _redirect_from_referrer(self, request, wiki_path):
     """
     redirect to course wiki url if the referrer is from a course page
     """
     course_id = course_id_from_url(request.META.get('HTTP_REFERER'))
     if course_id:
         # See if we are able to view the course. If we are, redirect to it
         try:
             get_course_overview_with_access(request.user, 'load', course_id)
             return redirect("/courses/{course_id}/wiki/{path}".format(course_id=course_id.to_deprecated_string(), path=wiki_path))
         except Http404:
             # Even though we came from the course, we can't see it. So don't worry about it.
             pass
コード例 #3
0
    def render_to_fragment(self,
                           request,
                           course_id=None,
                           page_context=None,
                           **kwargs):
        """
        Renders the course outline as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course_overview = get_course_overview_with_access(
            request.user, 'load', course_key, check_if_enrolled=True)

        course_block_tree = get_course_outline_block_tree(request, course_id)
        if not course_block_tree:
            return None

        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course_overview,
            'blocks': course_block_tree,
        }

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

        return Fragment(html)
コード例 #4
0
ファイル: course_outline.py プロジェクト: vdhug/edx-platform
    def render_to_fragment(self, request, course_id=None, **kwargs):  # pylint: disable=arguments-differ
        """
        Renders the course outline as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course_overview = get_course_overview_with_access(
            request.user, 'load', course_key, check_if_enrolled=True)
        course = modulestore().get_course(course_key)

        course_block_tree = get_course_outline_block_tree(request, course_id)
        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
        }

        resume_block = get_resume_block(course_block_tree)
        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

        html = render_to_string(
            'course_experience/course-outline-fragment.html', context)
        return Fragment(html)
コード例 #5
0
ファイル: views.py プロジェクト: DoTamKma/debug-edx-platform
def has_instructor_access_for_class(user, course_id):
    """
    Returns true if the `user` is an instructor for the course.
    """

    course = get_course_overview_with_access(user, 'staff', course_id)
    return bool(has_access(user, 'staff', course))
コード例 #6
0
ファイル: course_outline.py プロジェクト: mitocw/edx-platform
    def render_to_fragment(self, request, course_id=None, **kwargs):  # pylint: disable=arguments-differ
        """
        Renders the course outline as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course_overview = get_course_overview_with_access(request.user, 'load', course_key, check_if_enrolled=True)
        course = modulestore().get_course(course_key)

        course_block_tree = get_course_outline_block_tree(request, course_id)
        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
        }

        resume_block = get_resume_block(course_block_tree)
        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

        html = render_to_string('course_experience/course-outline-fragment.html', context)
        return Fragment(html)
コード例 #7
0
    def render_to_fragment(self,
                           request,
                           course_id=None,
                           page_context=None,
                           **kwargs):
        """
        Renders the course outline as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course_overview = get_course_overview_with_access(
            request.user, 'load', course_key, check_if_enrolled=True)

        course_block_tree = get_course_outline_block_tree(request, course_id)

        context = {
            'csrf':
            csrf(request)['csrf_token'],
            'course':
            course_overview,
            'blocks':
            course_block_tree,
            'upgrade_link':
            check_and_get_upgrade_link(request, request.user, course_key),
            'upgrade_price':
            get_cosmetic_verified_display_price(course_overview),
        }
        html = render_to_string(
            'course_experience/course-outline-fragment.html', context)
        return Fragment(html)
コード例 #8
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_overview_with_access(request.user,
                                                 'load',
                                                 course_key,
                                                 check_if_enrolled=True)
        course_url_name = default_course_url_name(course.id)
        course_url = reverse(course_url_name,
                             kwargs={'course_id': unicode(course.id)})

        # Render the course home fragment
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'course_key': course_key,
            'course_url': course_url,
            'query': request.GET.get('query', ''),
            'disable_courseware_js': True,
            'uses_pattern_library': True,
        }
        html = render_to_string('course_search/course-search-fragment.html',
                                context)
        return Fragment(html)
コード例 #9
0
ファイル: views.py プロジェクト: Stanford-Online/edx-platform
def has_instructor_access_for_class(user, course_id):
    """
    Returns true if the `user` is an instructor for the course.
    """

    course = get_course_overview_with_access(user, 'staff', course_id)
    return bool(has_access(user, 'staff', course))
コード例 #10
0
    def render_to_fragment(self,
                           request,
                           course_id=None,
                           page_context=None,
                           **kwargs):
        """
        Renders the course outline as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course_overview = get_course_overview_with_access(
            request.user, 'load', course_key, check_if_enrolled=True)

        course_block_tree = get_course_outline_block_tree(request, course_id)
        if not course_block_tree:
            return None

        # TODO: EDUCATOR-2283 Remove 'show_visual_progress' from context
        # and remove the check for it in the HTML file
        show_visual_progress = (
            completion_waffle.visual_progress_enabled(course_key)
            and self.user_enrolled_after_completion_collection(
                request.user, course_key))
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course_overview,
            'blocks': course_block_tree,
            'show_visual_progress': show_visual_progress
        }

        # TODO: EDUCATOR-2283 Remove this check when the waffle flag is turned on in production
        if course_experience_waffle.new_course_outline_enabled(
                course_key=course_key):
            resume_block = get_resume_block(course_block_tree)
            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

            # TODO: EDUCATOR-2283 Rename this file to course-outline-fragment.html
            html = render_to_string(
                'course_experience/course-outline-fragment-new.html', context)
            return Fragment(html)
        else:
            content_milestones = self.get_content_milestones_old(
                request, course_key)

            context['gated_content'] = content_milestones

            # TODO: EDUCATOR-2283 Remove this file
            html = render_to_string(
                'course_experience/course-outline-fragment-old.html', context)
            return Fragment(html)
コード例 #11
0
def users(request, course_id):
    """
    Given a `username` query parameter, find matches for users in the forum for this course.

    Only exact matches are supported here, so the length of the result set will either be 0 or 1.
    """

    course_key = CourseKey.from_string(course_id)
    try:
        get_course_overview_with_access(request.user,
                                        'load',
                                        course_key,
                                        check_if_enrolled=True)
    except Http404:
        # course didn't exist, or requesting user does not have access to it.
        return JsonError(status=404)
    except CourseAccessRedirect:
        # user does not have access to the course.
        return JsonError(status=404)

    try:
        username = request.GET['username']
    except KeyError:
        # 400 is default status for JsonError
        return JsonError(["username parameter is required"])

    user_objs = []
    try:
        matched_user = User.objects.get(username=username)
        cc_user = cc.User.from_django_user(matched_user)
        cc_user.course_id = course_key
        cc_user.retrieve(complete=False)
        if (cc_user['threads_count'] + cc_user['comments_count']) > 0:
            user_objs.append({
                'id': matched_user.id,
                'username': matched_user.username,
            })
    except User.DoesNotExist:
        pass
    return JsonResponse({"users": user_objs})
コード例 #12
0
 def _get_ordered_certificates_for_user(self, request, username):
     """
     Returns a user's certificates sorted by course name.
     """
     course_certificates = certificate_api.get_certificates_for_user(
         username)
     for course_certificate in course_certificates:
         course_key = course_certificate['course_key']
         course_overview = get_course_overview_with_access(
             request.user, 'load', course_key)
         course_certificate['course'] = course_overview
     course_certificates.sort(key=lambda certificate: certificate['course'].
                              display_name_with_default)
     return course_certificates
コード例 #13
0
ファイル: course_outline.py プロジェクト: xenops/edx-platform
    def render_to_fragment(self,
                           request,
                           course_id=None,
                           page_context=None,
                           **kwargs):
        """
        Renders the course outline as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course_overview = get_course_overview_with_access(
            request.user, 'load', course_key, check_if_enrolled=True)

        course_block_tree = get_course_outline_block_tree(request, course_id)
        if not course_block_tree:
            return None

        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course_overview,
            'blocks': course_block_tree
        }

        # TODO: EDUCATOR-2283 Remove this check when the waffle flag is turned on in production
        if waffle.new_course_outline_enabled(course_key=course_key):
            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

            # TODO: EDUCATOR-2283 Rename this file to course-outline-fragment.html
            html = render_to_string(
                'course_experience/course-outline-fragment-new.html', context)
            return Fragment(html)
        else:
            content_milestones = self.get_content_milestones_old(
                request, course_key)

            context['gated_content'] = content_milestones

            # TODO: EDUCATOR-2283 Remove this file
            html = render_to_string(
                'course_experience/course-outline-fragment-old.html', context)
            return Fragment(html)
コード例 #14
0
    def render_to_fragment(self, request, course_id=None, page_context=None, **kwargs):
        """
        Renders the course outline as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course_overview = get_course_overview_with_access(request.user, 'load', course_key, check_if_enrolled=True)

        course_block_tree = get_course_outline_block_tree(request, course_id)
        if not course_block_tree:
            return None

        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course_overview,
            'blocks': course_block_tree,
        }
        html = render_to_string('course_experience/course-outline-fragment.html', context)
        return Fragment(html)
コード例 #15
0
    def render_to_fragment(self, request, course_id=None, page_context=None, **kwargs):
        """
        Renders the course outline as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course_overview = get_course_overview_with_access(request.user, 'load', course_key, check_if_enrolled=True)

        course_block_tree = get_course_outline_block_tree(request, course_id)
        if not course_block_tree:
            return None

        # TODO: EDUCATOR-2283 Remove 'show_visual_progress' from context
        # and remove the check for it in the HTML file
        show_visual_progress = (
            completion_waffle.visual_progress_enabled(course_key) and
            self.user_enrolled_after_completion_collection(request.user, course_key)
        )
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course_overview,
            'blocks': course_block_tree,
            'show_visual_progress': show_visual_progress
        }

        # TODO: EDUCATOR-2283 Remove this check when the waffle flag is turned on in production
        if course_experience_waffle.new_course_outline_enabled(course_key=course_key):
            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

            # TODO: EDUCATOR-2283 Rename this file to course-outline-fragment.html
            html = render_to_string('course_experience/course-outline-fragment-new.html', context)
            return Fragment(html)
        else:
            content_milestones = self.get_content_milestones_old(request, course_key)

            context['gated_content'] = content_milestones

            # TODO: EDUCATOR-2283 Remove this file
            html = render_to_string('course_experience/course-outline-fragment-old.html', context)
            return Fragment(html)
コード例 #16
0
ファイル: course_outline.py プロジェクト: edx/edx-platform
    def render_to_fragment(self, request, course_id, user_is_enrolled=True, **kwargs):  # pylint: disable=arguments-differ
        """
        Renders the course outline as a fragment.
        """
        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,
        }

        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'

        html = render_to_string('course_experience/course-outline-fragment.html', context)
        return Fragment(html)
コード例 #17
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_overview_with_access(request.user, 'load', course_key, check_if_enrolled=True)
        course_url_name = default_course_url_name(course.id)
        course_url = reverse(course_url_name, kwargs={'course_id': six.text_type(course.id)})

        # Render the course home fragment
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'course_key': course_key,
            'course_url': course_url,
            'query': request.GET.get('query', ''),
            'disable_courseware_js': True,
            'uses_pattern_library': True,
        }
        html = render_to_string('course_search/course-search-fragment.html', context)
        return Fragment(html)