Exemple #1
0
    def render_to_fragment(self, request, course_id=None, **kwargs):
        """
        Fragment to render the course reviews fragment.

        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user,
                                        'load',
                                        course_key,
                                        check_if_enrolled=False)
        course_url_name = default_course_url_name(course.id)
        course_url = reverse(course_url_name,
                             kwargs={'course_id': unicode(course.id)})

        is_enrolled = CourseEnrollment.is_enrolled(request.user, course.id)

        # Create the fragment
        course_reviews_fragment = CourseReviewsModuleFragmentView(
        ).render_to_fragment(request, course=course, **kwargs)

        context = {
            'course': course,
            'course_url': course_url,
            'course_reviews_fragment': course_reviews_fragment,
            'is_enrolled': is_enrolled,
        }

        html = render_to_string(
            'course_experience/course-reviews-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)
        course_url_name = default_course_url_name(course.id)
        course_url = reverse(course_url_name, kwargs={'course_id': unicode(course.id)})

        ordered_updates = get_ordered_updates(request, course)
        plain_html_updates = ''
        if ordered_updates:
            plain_html_updates = self.get_plain_html_updates(request, course)

        # Render the course home fragment
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'course_url': course_url,
            'updates': ordered_updates,
            'plain_html_updates': plain_html_updates,
            '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):
        """
        Fragment to render the course reviews fragment.

        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=False)
        course_url_name = default_course_url_name(course.id)
        course_url = reverse(course_url_name, kwargs={'course_id': unicode(course.id)})

        is_enrolled = CourseEnrollment.is_enrolled(request.user, course.id)

        # Create the fragment
        course_reviews_fragment = CourseReviewsModuleFragmentView().render_to_fragment(
            request,
            course=course,
            **kwargs
        )

        context = {
            'course': course,
            'course_url': course_url,
            'course_reviews_fragment': course_reviews_fragment,
            'is_enrolled': is_enrolled,
        }

        html = render_to_string('course_experience/course-reviews-fragment.html', context)
        return Fragment(html)
    def get(self, request, course_id):
        """
        Displays the user's bookmarks for the specified course.

        Arguments:
            request: HTTP request
            course_id (unicode): course id
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_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 bookmarks list as a fragment
        bookmarks_fragment = CourseBookmarksFragmentView().render_to_fragment(request, course_id=course_id)

        # Render the course bookmarks page
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'supports_preview_menu': True,
            'course_url': course_url,
            'bookmarks_fragment': bookmarks_fragment,
            'disable_courseware_js': True,
            'uses_pattern_library': True,
        }
        return render_to_response('course_bookmarks/course-bookmarks.html', context)
Exemple #5
0
 def link_func(self):
     """
     Returns a function that takes a course and reverse function and will
     compute the course URL for this tab.
     """
     reverse_name_func = lambda course: default_course_url_name(course.id)
     return course_reverse_func_from_name_func(reverse_name_func)
Exemple #6
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 = default_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)
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_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_bootstrap': True,
        }
        html = render_to_string('course_search/course-search-fragment.html',
                                context)
        return Fragment(html)
Exemple #8
0
    def get(self, request, course_id):
        """
        Displays the user's bookmarks for the specified course.

        Arguments:
            request: HTTP request
            course_id (unicode): course id
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_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': str(course.id)})

        # Render the bookmarks list as a fragment
        bookmarks_fragment = CourseBookmarksFragmentView().render_to_fragment(
            request, course_id=course_id)

        # Render the course bookmarks page
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'supports_preview_menu': True,
            'course_url': course_url,
            'bookmarks_fragment': bookmarks_fragment,
            'disable_courseware_js': True,
            'uses_bootstrap': True,
        }
        return render_to_response('course_bookmarks/course-bookmarks.html',
                                  context)
Exemple #9
0
 def link_func(self):
     """
     Returns a function that computes the URL for this tab.
     """
     request = RequestCache.get_current_request()
     url_name = default_course_url_name(request)
     return link_reverse_func(url_name)
Exemple #10
0
    def get(self, request, course_id, **kwargs):
        """
        Displays the user's badges for the specified course.

        Arguments:
            request: HTTP request
            course_id (unicode): course id
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_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)})

        # Award badges to course chapters if they haven't already been done.
        award_section_badges(course_id, request)

        # Render the badges list as a fragment
        badges_fragment = CourseBadgesProgressFragmentView(
        ).render_to_fragment(request, course_id=course_id)

        # Render the course badges page
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'supports_preview_menu': True,
            'course_url': course_url,
            'badges_fragment': badges_fragment,
            'disable_courseware_js': True,
            'uses_pattern_library': True,
        }
        return render_to_response('course_badges/course-badges.html', context)
Exemple #11
0
 def link_func(self):
     """
     Returns a function that takes a course and reverse function and will
     compute the course URL for this tab.
     """
     reverse_name_func = lambda course: default_course_url_name(course.id)
     return course_reverse_func_from_name_func(reverse_name_func)
Exemple #12
0
 def link_func(course, reverse_func):
     if course_home_legacy_is_active(course.id):
         reverse_name_func = lambda course: default_course_url_name(
             course.id)
         url_func = course_reverse_func_from_name_func(
             reverse_name_func)
         return url_func(course, reverse_func)
     else:
         return get_learning_mfe_home_url(course_key=course.id,
                                          url_fragment='home')
Exemple #13
0
 def link_func(course, reverse_func):
     if course_home_mfe_outline_tab_is_active(course.id):
         return get_microfrontend_url(course_key=course.id,
                                      view_name=self.view_name)
     else:
         reverse_name_func = lambda course_test: default_course_url_name(
             course_test.id)
         url_func = course_reverse_func_from_name_func(
             reverse_name_func)
         return url_func(course, reverse_func)
    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)
Exemple #15
0
    def _create_courseware_context(self, request):
        """
        Returns and creates the rendering context for the courseware.
        Also returns the table of contents for the courseware.
        """
        course_url_name = default_course_url_name(self.course.id)
        course_url = reverse(course_url_name, kwargs={'course_id': unicode(self.course.id)})

        courseware_context = {
            'csrf': csrf(self.request)['csrf_token'],
            'course': self.course,
            'course_url': course_url,
            'chapter': self.chapter,
            'section': self.section,
            'init': '',
            'fragment': Fragment(),
            'staff_access': self.is_staff,
            'masquerade': self.masquerade,
            'supports_preview_menu': True,
            'studio_url': get_studio_url(self.course, 'course'),
            'xqa_server': settings.FEATURES.get('XQA_SERVER', "http://your_xqa_server.com"),
            'bookmarks_api_url': reverse('bookmarks'),
            'language_preference': self._get_language_preference(),
            'disable_optimizely': not WaffleSwitchNamespace('RET').is_enabled('enable_optimizely_in_courseware'),
            'section_title': None,
            'sequence_title': None,
            'disable_accordion': COURSE_OUTLINE_PAGE_FLAG.is_enabled(self.course.id),
        }
        courseware_context.update(
            get_experiment_user_metadata_context(
                self.course,
                self.effective_user,
            )
        )
        table_of_contents = toc_for_course(
            self.effective_user,
            self.request,
            self.course,
            self.chapter_url_name,
            self.section_url_name,
            self.field_data_cache,
        )
        courseware_context['accordion'] = render_accordion(
            self.request,
            self.course,
            table_of_contents['chapters'],
        )

        courseware_context['course_sock_fragment'] = CourseSockFragmentView().render_to_fragment(
            request, course=self.course)

        # entrance exam data
        self._add_entrance_exam_to_context(courseware_context)

        if self.section:
            # chromeless data
            if self.section.chrome:
                chrome = [s.strip() for s in self.section.chrome.lower().split(",")]
                if 'accordion' not in chrome:
                    courseware_context['disable_accordion'] = True
                if 'tabs' not in chrome:
                    courseware_context['disable_tabs'] = True

            # default tab
            if self.section.default_tab:
                courseware_context['default_tab'] = self.section.default_tab

            # section data
            courseware_context['section_title'] = self.section.display_name_with_default
            section_context = self._create_section_context(
                table_of_contents['previous_of_active_section'],
                table_of_contents['next_of_active_section'],
            )

            courseware_context['fragment'] = self.section.render(self.view, section_context)

            if self.section.position and self.section.has_children:
                self._add_sequence_title_to_context(courseware_context)

        return courseware_context
Exemple #16
0
    def _create_courseware_context(self, request):
        """
        Returns and creates the rendering context for the courseware.
        Also returns the table of contents for the courseware.
        """
        course_url_name = default_course_url_name(self.course.id)
        course_url = reverse(
            course_url_name,
            kwargs={'course_id': six.text_type(self.course.id)})
        show_search = (
            settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH') or
            (settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH_FOR_COURSE_STAFF')
             and self.is_staff))
        staff_access = self.is_staff

        courseware_context = {
            'csrf':
            csrf(self.request)['csrf_token'],
            'course':
            self.course,
            'course_url':
            course_url,
            'chapter':
            self.chapter,
            'section':
            self.section,
            'init':
            '',
            'fragment':
            Fragment(),
            'staff_access':
            staff_access,
            'can_masquerade':
            self.can_masquerade,
            'masquerade':
            self.masquerade,
            'supports_preview_menu':
            True,
            'studio_url':
            get_studio_url(self.course, 'course'),
            'xqa_server':
            settings.FEATURES.get('XQA_SERVER', "http://your_xqa_server.com"),
            'bookmarks_api_url':
            reverse('bookmarks'),
            'language_preference':
            self._get_language_preference(),
            'disable_optimizely':
            not WaffleSwitchNamespace('RET').is_enabled(
                'enable_optimizely_in_courseware'),
            'section_title':
            None,
            'sequence_title':
            None,
            'disable_accordion':
            COURSE_OUTLINE_PAGE_FLAG.is_enabled(self.course.id),
            'show_search':
            show_search,
        }
        courseware_context.update(
            get_experiment_user_metadata_context(
                self.course,
                self.effective_user,
            ))
        table_of_contents = toc_for_course(
            self.effective_user,
            self.request,
            self.course,
            self.chapter_url_name,
            self.section_url_name,
            self.field_data_cache,
        )
        courseware_context['accordion'] = render_accordion(
            self.request,
            self.course,
            table_of_contents['chapters'],
        )

        courseware_context['course_sock_fragment'] = CourseSockFragmentView(
        ).render_to_fragment(request, course=self.course_overview)

        # entrance exam data
        self._add_entrance_exam_to_context(courseware_context)

        if self.section:
            # chromeless data
            if self.section.chrome:
                chrome = [
                    s.strip() for s in self.section.chrome.lower().split(",")
                ]
                if 'accordion' not in chrome:
                    courseware_context['disable_accordion'] = True
                if 'tabs' not in chrome:
                    courseware_context['disable_tabs'] = True

            # default tab
            if self.section.default_tab:
                courseware_context['default_tab'] = self.section.default_tab

            # section data
            courseware_context[
                'section_title'] = self.section.display_name_with_default
            section_context = self._create_section_context(
                table_of_contents['previous_of_active_section'],
                table_of_contents['next_of_active_section'],
            )
            courseware_context['fragment'] = self.section.render(
                self.view, section_context)

            if self.section.position and self.section.has_children:
                self._add_sequence_title_to_context(courseware_context)

        # Courseware MFE link
        if show_courseware_mfe_link(request.user, staff_access,
                                    self.course.id):
            if self.section:
                try:
                    unit_key = UsageKey.from_string(
                        request.GET.get('activate_block_id', ''))
                    # `activate_block_id` is typically a Unit (a.k.a. Vertical),
                    # but it can technically be any block type. Do a check to
                    # make sure it's really a Unit before we use it for the MFE.
                    if unit_key.block_type != 'vertical':
                        unit_key = None
                except InvalidKeyError:
                    unit_key = None

                courseware_context[
                    'microfrontend_link'] = get_microfrontend_url(
                        self.course.id, self.section.location, unit_key)
            else:
                courseware_context[
                    'microfrontend_link'] = get_microfrontend_url(
                        self.course.id)
        else:
            courseware_context['microfrontend_link'] = None

        return courseware_context
Exemple #17
0
    def get(self, request, course_id):
        """
        Displays the user's Learner Analytics for the specified course.

        Arguments:
            request: HTTP request
            course_id (unicode): course id
        """
        course_key = CourseKey.from_string(course_id)
        if not ENABLE_DASHBOARD_TAB.is_enabled(course_key):
            raise Http404

        course = get_course_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)})

        is_verified = CourseEnrollment.is_enrolled_as_verified(request.user, course_key)
        has_access = is_verified or request.user.is_staff

        enrollment = CourseEnrollment.get_enrollment(request.user, course_key)

        upgrade_price = None
        upgrade_url = None

        if enrollment and enrollment.upgrade_deadline:
            upgrade_url = EcommerceService().upgrade_url(request.user, course_key)
            upgrade_price = get_cosmetic_verified_display_price(course)

        context = {
            'upgrade_price': upgrade_price,
            'upgrade_link': upgrade_url,
            'course': course,
            'course_url': course_url,
            'disable_courseware_js': True,
            'uses_pattern_library': True,
            'is_self_paced': course.self_paced,
            'is_verified': is_verified,
            'has_access': has_access,
        }

        if (has_access):
            grading_policy = course.grading_policy

            (raw_grade_data, answered_percent, percent_grade) = self.get_grade_data(request.user, course_key, grading_policy['GRADE_CUTOFFS'])
            raw_schedule_data = self.get_assignments_with_due_date(request, course_key)

            grade_data, schedule_data = self.sort_grade_and_schedule_data(raw_grade_data, raw_schedule_data)

            # TODO: LEARNER-3854: Fix hacked defaults with real error handling if implementing Learner Analytics.
            try:
                weekly_active_users = self.get_weekly_course_activity_count(course_key)
                week_streak = self.consecutive_weeks_of_course_activity_for_user(
                    request.user.username, course_key
                )
            except Exception as e:
                logging.exception(e)
                weekly_active_users = 134
                week_streak = 1

            context.update({
                'grading_policy': grading_policy,
                'assignment_grades': grade_data,
                'answered_percent': answered_percent,
                'assignment_schedule': schedule_data,
                'assignment_schedule_raw': raw_schedule_data,
                'profile_image_urls': get_profile_image_urls_for_user(request.user, request),
                'discussion_info': self.get_discussion_data(request, course_key),
                'passing_grade': math.ceil(100 * course.lowest_passing_grade),
                'percent_grade': math.ceil(100 * percent_grade),
                'weekly_active_users': weekly_active_users,
                'week_streak': week_streak,
            })

        return render_to_response('learner_analytics/dashboard.html', context)
Exemple #18
0
    def _create_courseware_context(self, request):
        """
        Returns and creates the rendering context for the courseware.
        Also returns the table of contents for the courseware.
        """
        course_url_name = default_course_url_name(self.course.id)
        course_url = reverse(
            course_url_name,
            kwargs={'course_id': six.text_type(self.course.id)})
        show_search = (
            settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH') or
            (settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH_FOR_COURSE_STAFF')
             and self.is_staff))
        staff_access = self.is_staff

        reset_deadlines_url = reverse(
            'openedx.course_experience.reset_course_deadlines',
            kwargs={'course_id': six.text_type(self.course.id)})

        allow_anonymous = allow_public_access(self.course,
                                              [COURSE_VISIBILITY_PUBLIC])
        display_reset_dates_banner = False
        if not allow_anonymous and RELATIVE_DATES_FLAG.is_enabled(
                self.course.id):  # pylint: disable=too-many-nested-blocks
            course_overview = CourseOverview.objects.get(
                id=str(self.course_key))
            end_date = getattr(course_overview, 'end_date')
            if course_overview.self_paced and (not end_date
                                               or timezone.now() < end_date):
                if (CourseEnrollment.objects.filter(
                        course=course_overview,
                        user=request.user,
                        mode=CourseMode.VERIFIED).exists()):
                    course_block_tree = get_course_outline_block_tree(
                        request, str(self.course_key), request.user)
                    course_sections = course_block_tree.get('children', [])
                    for section in course_sections:
                        if display_reset_dates_banner:
                            break
                        for subsection in section.get('children', []):
                            if (not subsection.get('complete', True)
                                    and subsection.get(
                                        'due',
                                        timezone.now() + timedelta(1)) <
                                    timezone.now()):
                                display_reset_dates_banner = True
                                break

        courseware_context = {
            'csrf':
            csrf(self.request)['csrf_token'],
            'course':
            self.course,
            'course_url':
            course_url,
            'chapter':
            self.chapter,
            'section':
            self.section,
            'init':
            '',
            'fragment':
            Fragment(),
            'staff_access':
            staff_access,
            'can_masquerade':
            self.can_masquerade,
            'masquerade':
            self.masquerade,
            'supports_preview_menu':
            True,
            'studio_url':
            get_studio_url(self.course, 'course'),
            'xqa_server':
            settings.FEATURES.get('XQA_SERVER', "http://your_xqa_server.com"),
            'bookmarks_api_url':
            reverse('bookmarks'),
            'language_preference':
            self._get_language_preference(),
            'disable_optimizely':
            not WaffleSwitchNamespace('RET').is_enabled(
                'enable_optimizely_in_courseware'),
            'section_title':
            None,
            'sequence_title':
            None,
            'disable_accordion':
            COURSE_OUTLINE_PAGE_FLAG.is_enabled(self.course.id),
            'show_search':
            show_search,
            'relative_dates_is_enabled':
            RELATIVE_DATES_FLAG.is_enabled(self.course.id),
            'reset_deadlines_url':
            reset_deadlines_url,
            'display_reset_dates_banner':
            display_reset_dates_banner,
        }
        courseware_context.update(
            get_experiment_user_metadata_context(
                self.course,
                self.effective_user,
            ))
        table_of_contents = toc_for_course(
            self.effective_user,
            self.request,
            self.course,
            self.chapter_url_name,
            self.section_url_name,
            self.field_data_cache,
        )
        courseware_context['accordion'] = render_accordion(
            self.request,
            self.course,
            table_of_contents['chapters'],
        )

        courseware_context['course_sock_fragment'] = CourseSockFragmentView(
        ).render_to_fragment(request, course=self.course_overview)

        # entrance exam data
        self._add_entrance_exam_to_context(courseware_context)

        if self.section:
            # chromeless data
            if self.section.chrome:
                chrome = [
                    s.strip() for s in self.section.chrome.lower().split(",")
                ]
                if 'accordion' not in chrome:
                    courseware_context['disable_accordion'] = True
                if 'tabs' not in chrome:
                    courseware_context['disable_tabs'] = True

            # default tab
            if self.section.default_tab:
                courseware_context['default_tab'] = self.section.default_tab

            # section data
            courseware_context[
                'section_title'] = self.section.display_name_with_default
            section_context = self._create_section_context(
                table_of_contents['previous_of_active_section'],
                table_of_contents['next_of_active_section'],
            )
            courseware_context['fragment'] = self.section.render(
                self.view, section_context)

            if self.section.position and self.section.has_children:
                self._add_sequence_title_to_context(courseware_context)

        # Courseware MFE link
        if show_courseware_mfe_link(request.user, staff_access,
                                    self.course.id):
            if self.section:
                try:
                    unit_key = UsageKey.from_string(
                        request.GET.get('activate_block_id', ''))
                    # `activate_block_id` is typically a Unit (a.k.a. Vertical),
                    # but it can technically be any block type. Do a check to
                    # make sure it's really a Unit before we use it for the MFE.
                    if unit_key.block_type != 'vertical':
                        unit_key = None
                except InvalidKeyError:
                    unit_key = None

                courseware_context[
                    'microfrontend_link'] = get_microfrontend_url(
                        self.course.id, self.section.location, unit_key)
            else:
                courseware_context[
                    'microfrontend_link'] = get_microfrontend_url(
                        self.course.id)
        else:
            courseware_context['microfrontend_link'] = None

        return courseware_context
Exemple #19
0
def _create_courseware_api_test(self, request):
    """
    Returns and creates the rendering context for the courseware.
    Also returns the table of contents for the courseware.
    """
    course_url_name = default_course_url_name(self.course.id)
    course_url = reverse(course_url_name,
                         kwargs={'course_id': unicode(self.course.id)})
    courseware_context = {
        'course_url': course_url,
        'init': '',
        'content': '',
        'bookmarks_api_url': reverse('bookmarks'),
        'language_preference': self._get_language_preference(),
        'section_title': None,
        'sequence_title': None,
    }
    table_of_contents = toc_for_course(
        self.effective_user,
        self.request,
        self.course,
        self.chapter_url_name,
        self.section_url_name,
        self.field_data_cache,
    )

    courseware_context['accordion_json'] = table_of_contents

    if self.section:
        # default tab
        if self.section.default_tab:
            courseware_context['default_tab'] = self.section.default_tab

        # section data
        courseware_context[
            'section_title'] = self.section.display_name_with_default
        section_context = self._create_section_context(
            table_of_contents['previous_of_active_section'],
            table_of_contents['next_of_active_section'],
        )
        courseware_context['content'] = self.section.render(
            STUDENT_VIEW, section_context).to_dict()['content']
        if self.section.position and self.section.has_children:
            display_items = self.section.get_display_items()
            if display_items:
                try:
                    courseware_context['sequence_title'] = display_items[self.section.position - 1] \
                        .display_name_with_default
                except IndexError:
                    log.exception(
                        "IndexError loading courseware for user %s, course %s, section %s, position %d. Total items: %d. URL: %s",
                        self.real_user.username,
                        self.course.id,
                        self.section.display_name_with_default,
                        self.section.position,
                        len(display_items),
                        self.url,
                    )
                    raise

    return json.dumps(courseware_context)
Exemple #20
0
    def _create_courseware_context(self, request):
        """
        Returns and creates the rendering context for the courseware.
        Also returns the table of contents for the courseware.
        """
        course_url_name = default_course_url_name(self.course.id)
        course_url = reverse(course_url_name, kwargs={'course_id': unicode(self.course.id)})

        courseware_context = {
            'csrf': csrf(self.request)['csrf_token'],
            'course': self.course,
            'course_url': course_url,
            'chapter': self.chapter,
            'section': self.section,
            'init': '',
            'fragment': Fragment(),
            'staff_access': self.is_staff,
            'masquerade': self.masquerade,
            'supports_preview_menu': True,
            'studio_url': get_studio_url(self.course, 'course'),
            'xqa_server': settings.FEATURES.get('XQA_SERVER', "http://your_xqa_server.com"),
            'bookmarks_api_url': reverse('bookmarks'),
            'language_preference': self._get_language_preference(),
            'disable_optimizely': not WaffleSwitchNamespace('RET').is_enabled('enable_optimizely_in_courseware'),
            'section_title': None,
            'sequence_title': None,
            'disable_accordion': COURSE_OUTLINE_PAGE_FLAG.is_enabled(self.course.id),
        }
        courseware_context.update(
            get_experiment_user_metadata_context(
                self.course,
                self.effective_user,
            )
        )
        table_of_contents = toc_for_course(
            self.effective_user,
            self.request,
            self.course,
            self.chapter_url_name,
            self.section_url_name,
            self.field_data_cache,
        )
        courseware_context['accordion'] = render_accordion(
            self.request,
            self.course,
            table_of_contents['chapters'],
        )

        courseware_context['course_sock_fragment'] = CourseSockFragmentView().render_to_fragment(
            request, course=self.course)

        # entrance exam data
        self._add_entrance_exam_to_context(courseware_context)

        # staff masquerading data
        if not check_course_open_for_learner(self.effective_user, self.course):
            # Disable student view button if user is staff and
            # course is not yet visible to students.
            courseware_context['disable_student_access'] = True
            courseware_context['supports_preview_menu'] = False

        if self.section:
            # chromeless data
            if self.section.chrome:
                chrome = [s.strip() for s in self.section.chrome.lower().split(",")]
                if 'accordion' not in chrome:
                    courseware_context['disable_accordion'] = True
                if 'tabs' not in chrome:
                    courseware_context['disable_tabs'] = True

            # default tab
            if self.section.default_tab:
                courseware_context['default_tab'] = self.section.default_tab

            # section data
            courseware_context['section_title'] = self.section.display_name_with_default
            section_context = self._create_section_context(
                table_of_contents['previous_of_active_section'],
                table_of_contents['next_of_active_section'],
            )
            courseware_context['fragment'] = self.section.render(STUDENT_VIEW, section_context)
            if self.section.position and self.section.has_children:
                display_items = self.section.get_display_items()
                if display_items:
                    try:
                        courseware_context['sequence_title'] = display_items[self.section.position - 1] \
                            .display_name_with_default
                    except IndexError:
                        log.exception(
                            "IndexError loading courseware for user %s, course %s, section %s, position %d. Total items: %d. URL: %s",
                            self.real_user.username,
                            self.course.id,
                            self.section.display_name_with_default,
                            self.section.position,
                            len(display_items),
                            self.url,
                        )
                        raise
        return courseware_context
Exemple #21
0
    def _create_courseware_context(self, request):
        """
        Returns and creates the rendering context for the courseware.
        Also returns the table of contents for the courseware.
        """
        from lms.urls import RESET_COURSE_DEADLINES_NAME

        course_url_name = default_course_url_name(self.course.id)
        course_url = reverse(
            course_url_name,
            kwargs={'course_id': six.text_type(self.course.id)})
        show_search = (
            settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH') or
            (settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH_FOR_COURSE_STAFF')
             and self.is_staff))
        staff_access = self.is_staff

        allow_anonymous = check_public_access(self.course,
                                              [COURSE_VISIBILITY_PUBLIC])
        display_reset_dates_banner = False
        if not allow_anonymous and RELATIVE_DATES_FLAG.is_enabled(
                self.course.id):
            display_reset_dates_banner = reset_deadlines_banner_should_display(
                self.course_key, request)

        reset_deadlines_url = reverse(RESET_COURSE_DEADLINES_NAME
                                      ) if display_reset_dates_banner else None

        reset_deadlines_redirect_url_base = COURSE_HOME_VIEW_NAME if reset_deadlines_url else None

        courseware_context = {
            'csrf':
            csrf(self.request)['csrf_token'],
            'course':
            self.course,
            'course_url':
            course_url,
            'chapter':
            self.chapter,
            'section':
            self.section,
            'init':
            '',
            'fragment':
            Fragment(),
            'staff_access':
            staff_access,
            'can_masquerade':
            self.can_masquerade,
            'masquerade':
            self.masquerade,
            'supports_preview_menu':
            True,
            'studio_url':
            get_studio_url(self.course, 'course'),
            'xqa_server':
            settings.FEATURES.get('XQA_SERVER', "http://your_xqa_server.com"),
            'bookmarks_api_url':
            reverse('bookmarks'),
            'language_preference':
            self._get_language_preference(),
            'disable_optimizely':
            not WaffleSwitchNamespace('RET').is_enabled(
                'enable_optimizely_in_courseware'),
            'section_title':
            None,
            'sequence_title':
            None,
            'disable_accordion':
            COURSE_OUTLINE_PAGE_FLAG.is_enabled(self.course.id),
            'show_search':
            show_search,
            'relative_dates_is_enabled':
            RELATIVE_DATES_FLAG.is_enabled(self.course.id),
            'display_reset_dates_banner':
            display_reset_dates_banner,
            'reset_deadlines_url':
            reset_deadlines_url,
            'reset_deadlines_redirect_url_base':
            reset_deadlines_redirect_url_base,
            'reset_deadlines_redirect_url_id_dict': {
                'course_id': str(self.course.id)
            },
        }
        courseware_context.update(
            get_experiment_user_metadata_context(
                self.course,
                self.effective_user,
            ))
        table_of_contents = toc_for_course(
            self.effective_user,
            self.request,
            self.course,
            self.chapter_url_name,
            self.section_url_name,
            self.field_data_cache,
        )
        courseware_context['accordion'] = render_accordion(
            self.request,
            self.course,
            table_of_contents['chapters'],
        )

        courseware_context['course_sock_fragment'] = CourseSockFragmentView(
        ).render_to_fragment(request, course=self.course)

        # entrance exam data
        self._add_entrance_exam_to_context(courseware_context)

        if self.section:
            # chromeless data
            if self.section.chrome:
                chrome = [
                    s.strip() for s in self.section.chrome.lower().split(",")
                ]
                if 'accordion' not in chrome:
                    courseware_context['disable_accordion'] = True
                if 'tabs' not in chrome:
                    courseware_context['disable_tabs'] = True

            # default tab
            if self.section.default_tab:
                courseware_context['default_tab'] = self.section.default_tab

            # section data
            courseware_context[
                'section_title'] = self.section.display_name_with_default
            section_context = self._create_section_context(
                table_of_contents['previous_of_active_section'],
                table_of_contents['next_of_active_section'],
            )
            courseware_context['fragment'] = self.section.render(
                self.view, section_context)

            if self.section.position and self.section.has_children:
                self._add_sequence_title_to_context(courseware_context)

        # Courseware MFE link
        if show_courseware_mfe_link(request.user, staff_access,
                                    self.course.id):
            courseware_context['microfrontend_link'] = self.microfrontend_url
        else:
            courseware_context['microfrontend_link'] = None

        return courseware_context
Exemple #22
0
 def get_course_url(self, obj):
     course_url_name = default_course_url_name(obj.course_key)
     return reverse(course_url_name, kwargs={'course_id': obj.course_key})
Exemple #23
0
    def _create_courseware_context(self, request):
        """
        Returns and creates the rendering context for the courseware.
        Also returns the table of contents for the courseware.
        """
        course_url_name = default_course_url_name(request)
        course_url = reverse(course_url_name,
                             kwargs={'course_id': unicode(self.course.id)})
        courseware_context = {
            'csrf':
            csrf(self.request)['csrf_token'],
            'course':
            self.course,
            'course_url':
            course_url,
            'chapter':
            self.chapter,
            'section':
            self.section,
            'init':
            '',
            'fragment':
            Fragment(),
            'staff_access':
            self.is_staff,
            'masquerade':
            self.masquerade,
            'supports_preview_menu':
            True,
            'studio_url':
            get_studio_url(self.course, 'course'),
            'xqa_server':
            settings.FEATURES.get('XQA_SERVER', "http://your_xqa_server.com"),
            'bookmarks_api_url':
            reverse('bookmarks'),
            'language_preference':
            self._get_language_preference(),
            'disable_optimizely':
            not WaffleSwitchNamespace('RET').is_enabled(
                'enable_optimizely_in_courseware'),
            'section_title':
            None,
            'sequence_title':
            None,
            'disable_accordion':
            waffle.flag_is_active(request, UNIFIED_COURSE_VIEW_FLAG),
            # TODO: (Experimental Code). See https://openedx.atlassian.net/wiki/display/RET/2.+In-course+Verification+Prompts
            'upgrade_link':
            check_and_get_upgrade_link(request, self.effective_user,
                                       self.course.id),
            'upgrade_price':
            get_cosmetic_verified_display_price(self.course),
            # ENDTODO
        }
        table_of_contents = toc_for_course(
            self.effective_user,
            self.request,
            self.course,
            self.chapter_url_name,
            self.section_url_name,
            self.field_data_cache,
        )
        courseware_context['accordion'] = render_accordion(
            self.request,
            self.course,
            table_of_contents['chapters'],
        )

        courseware_context['course_sock_fragment'] = CourseSockFragmentView(
        ).render_to_fragment(request, course=self.course)

        # entrance exam data
        self._add_entrance_exam_to_context(courseware_context)

        # staff masquerading data
        if not is_course_open_for_learner(self.effective_user, self.course):
            # Disable student view button if user is staff and
            # course is not yet visible to students.
            courseware_context['disable_student_access'] = True
            courseware_context['supports_preview_menu'] = False

        if self.section:
            # chromeless data
            if self.section.chrome:
                chrome = [
                    s.strip() for s in self.section.chrome.lower().split(",")
                ]
                if 'accordion' not in chrome:
                    courseware_context['disable_accordion'] = True
                if 'tabs' not in chrome:
                    courseware_context['disable_tabs'] = True

            # default tab
            if self.section.default_tab:
                courseware_context['default_tab'] = self.section.default_tab

            # section data
            courseware_context[
                'section_title'] = self.section.display_name_with_default
            section_context = self._create_section_context(
                table_of_contents['previous_of_active_section'],
                table_of_contents['next_of_active_section'],
            )
            courseware_context['fragment'] = self.section.render(
                STUDENT_VIEW, section_context)
            if self.section.position and self.section.has_children:
                display_items = self.section.get_display_items()
                if display_items:
                    try:
                        courseware_context['sequence_title'] = display_items[self.section.position - 1] \
                            .display_name_with_default
                    except IndexError:
                        log.exception(
                            "IndexError loading courseware for user %s, course %s, section %s, position %d. Total items: %d. URL: %s",
                            self.real_user.username,
                            self.course.id,
                            self.section.display_name_with_default,
                            self.section.position,
                            len(display_items),
                            self.url,
                        )
                        raise
        return courseware_context
Exemple #24
0
    def get(self, request, course_id):
        """
        Displays the user's Learner Analytics for the specified course.

        Arguments:
            request: HTTP request
            course_id (unicode): course id
        """
        course_key = CourseKey.from_string(course_id)
        if not ENABLE_DASHBOARD_TAB.is_enabled(course_key):
            raise Http404

        course = get_course_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)})

        grading_policy = course.grading_policy

        (grade_data, answered_percent) = self.get_grade_data(
            request.user, course_key, grading_policy['GRADE_CUTOFFS'])
        schedule_data = self.get_assignments_with_due_date(request, course_key)
        (grade_data, schedule_data) = self.sort_grade_and_schedule_data(
            grade_data, schedule_data)

        context = {
            'course':
            course,
            'course_url':
            course_url,
            'disable_courseware_js':
            True,
            'uses_pattern_library':
            True,
            'is_self_paced':
            course.self_paced,
            'is_verified':
            CourseEnrollment.is_enrolled_as_verified(request.user, course_key),
            'grading_policy':
            grading_policy,
            'assignment_grades':
            grade_data,
            'answered_percent':
            answered_percent,
            'assignment_schedule':
            schedule_data,
            'profile_image_urls':
            get_profile_image_urls_for_user(request.user, request),
            'discussion_info':
            self.get_discussion_data(request, course_key),
            'weekly_active_users':
            self.get_weekly_course_activity_count(course_key),
            'week_streak':
            self.consecutive_weeks_of_course_activity_for_user(
                request.user.username, course_key)
        }

        return render_to_response('learner_analytics/dashboard.html', context)
Exemple #25
0
    def get(self, request, course_id):
        """
        Displays the user's Learner Analytics for the specified course.

        Arguments:
            request: HTTP request
            course_id (unicode): course id
        """
        course_key = CourseKey.from_string(course_id)
        if not ENABLE_DASHBOARD_TAB.is_enabled(course_key):
            raise Http404

        course = get_course_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)})

        is_verified = CourseEnrollment.is_enrolled_as_verified(
            request.user, course_key)
        has_access = is_verified or request.user.is_staff

        enrollment = CourseEnrollment.get_enrollment(request.user, course_key)

        upgrade_price = None
        upgrade_url = None

        if enrollment and enrollment.upgrade_deadline:
            upgrade_url = EcommerceService().upgrade_url(
                request.user, course_key)
            upgrade_price = get_cosmetic_verified_display_price(course)

        context = {
            'upgrade_price': upgrade_price,
            'upgrade_link': upgrade_url,
            'course': course,
            'course_url': course_url,
            'disable_courseware_js': True,
            'uses_pattern_library': True,
            'is_self_paced': course.self_paced,
            'is_verified': is_verified,
            'has_access': has_access,
        }

        if (has_access):
            grading_policy = course.grading_policy

            (raw_grade_data, answered_percent,
             percent_grade) = self.get_grade_data(
                 request.user, course_key, grading_policy['GRADE_CUTOFFS'])
            raw_schedule_data = self.get_assignments_with_due_date(
                request, course_key)

            grade_data, schedule_data = self.sort_grade_and_schedule_data(
                raw_grade_data, raw_schedule_data)

            # TODO: LEARNER-3854: Fix hacked defaults with real error handling if implementing Learner Analytics.
            try:
                weekly_active_users = self.get_weekly_course_activity_count(
                    course_key)
                week_streak = self.consecutive_weeks_of_course_activity_for_user(
                    request.user.username, course_key)
            except Exception as e:
                logging.exception(e)
                weekly_active_users = 134
                week_streak = 1

            context.update({
                'grading_policy':
                grading_policy,
                'assignment_grades':
                grade_data,
                'answered_percent':
                answered_percent,
                'assignment_schedule':
                schedule_data,
                'assignment_schedule_raw':
                raw_schedule_data,
                'profile_image_urls':
                get_profile_image_urls_for_user(request.user, request),
                'discussion_info':
                self.get_discussion_data(request, course_key),
                'passing_grade':
                math.ceil(100 * course.lowest_passing_grade),
                'percent_grade':
                math.ceil(100 * percent_grade),
                'weekly_active_users':
                weekly_active_users,
                'week_streak':
                week_streak,
            })

        return render_to_response('learner_analytics/dashboard.html', context)
Exemple #26
0
    def _create_courseware_context(self, request):
        """
        Returns and creates the rendering context for the courseware.
        Also returns the table of contents for the courseware.
        """

        course_url_name = default_course_url_name(self.course.id)
        course_url = reverse(course_url_name, kwargs={'course_id': six.text_type(self.course.id)})
        show_search = (
            settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH') or
            (settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH_FOR_COURSE_STAFF') and self.is_staff)
        )
        staff_access = self.is_staff

        #Added by Mahendra
        try:
            course_extra = course_extrainfo.objects.get(course_id=self.course.id)
        except Exception as e:
            course_extra, created = course_extrainfo.objects.get_or_create(course_id=self.course.id)

        try:
            user_data = extrafields.objects.get(user_id=request.user)
        except Exception as e:
            user_data, created = extrafields.objects.get_or_create(user_id=request.user)

        courseware_context = {
            'csrf': csrf(self.request)['csrf_token'],
            'course': self.course,
            'course_url': course_url,
            'chapter': self.chapter,
            'section': self.section,
            'init': '',
            'fragment': Fragment(),
            'staff_access': staff_access,
            'can_masquerade': self.can_masquerade,
            'masquerade': self.masquerade,
            'supports_preview_menu': True,
            'studio_url': get_studio_url(self.course, 'course'),
            'xqa_server': settings.FEATURES.get('XQA_SERVER', "http://your_xqa_server.com"),
            'bookmarks_api_url': reverse('bookmarks'),
            'language_preference': self._get_language_preference(),
            'disable_optimizely': not WaffleSwitchNamespace('RET').is_enabled('enable_optimizely_in_courseware'),
            'section_title': None,
            'sequence_title': None,
            'disable_accordion': not DISABLE_COURSE_OUTLINE_PAGE_FLAG.is_enabled(self.course.id),
            'show_search': show_search,
            'course_extra': course_extra,
            'user_data': user_data
        }
        courseware_context.update(
            get_experiment_user_metadata_context(
                self.course,
                self.effective_user,
            )
        )
        table_of_contents = toc_for_course(
            self.effective_user,
            self.request,
            self.course,
            self.chapter_url_name,
            self.section_url_name,
            self.field_data_cache,
        )
        courseware_context['accordion'] = render_accordion(
            self.request,
            self.course,
            table_of_contents['chapters'],
        )

        courseware_context['course_sock_fragment'] = CourseSockFragmentView().render_to_fragment(
            request, course=self.course)

        # entrance exam data
        self._add_entrance_exam_to_context(courseware_context)

        if self.section:
            # chromeless data
            if self.section.chrome:
                chrome = [s.strip() for s in self.section.chrome.lower().split(",")]
                if 'accordion' not in chrome:
                    courseware_context['disable_accordion'] = True
                if 'tabs' not in chrome:
                    courseware_context['disable_tabs'] = True

            # default tab
            if self.section.default_tab:
                courseware_context['default_tab'] = self.section.default_tab

            # section data
            courseware_context['section_title'] = self.section.display_name_with_default
            section_context = self._create_section_context(
                table_of_contents['previous_of_active_section'],
                table_of_contents['next_of_active_section'],
            )
            courseware_context['fragment'] = self.section.render(self.view, section_context)

            if self.section.position and self.section.has_children:
                self._add_sequence_title_to_context(courseware_context)

        # Courseware MFE link
        if show_courseware_mfe_link(request.user, staff_access, self.course.id):
            courseware_context['microfrontend_link'] = self.microfrontend_url
        else:
            courseware_context['microfrontend_link'] = None

        return courseware_context