Exemple #1
0
    def init_template_values(self, environ, prefs=None):
        """Initializes template variables with common values."""
        self.template_value[COURSE_INFO_KEY] = environ
        self.template_value[
            'page_locale'] = self.app_context.get_current_locale()
        self.template_value['html_hooks'] = HtmlHooks(
            self.get_course(), prefs=prefs)
        self.template_value['is_course_admin'] = Roles.is_course_admin(
            self.app_context)
        self.template_value['can_see_drafts'] = (
            custom_modules.can_see_drafts(self.app_context))
        self.template_value[
            'is_read_write_course'] = self.app_context.fs.is_read_write()
        self.template_value['is_super_admin'] = Roles.is_super_admin()
        self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
        self.template_value['left_links'] = []
        for func in self.LEFT_LINKS:
            self.template_value['left_links'].extend(func(self.app_context))
        self.template_value['right_links'] = []
        for func in self.RIGHT_LINKS:
            self.template_value['right_links'].extend(func(self.app_context))

        if not prefs:
            prefs = models.StudentPreferencesDAO.load_or_create()
        self.template_value['student_preferences'] = prefs

        if (Roles.is_course_admin(self.app_context) and
            not appengine_config.PRODUCTION_MODE and
            prefs and prefs.show_jinja_context):

            @jinja2.contextfunction
            def get_context(context):
                return context
            self.template_value['context'] = get_context

        if CAN_PUT_DEBUG_INFO_INTO_PAGES.value:
            self.template_value['debug_info'] = self.debug_info()

        self.template_value[
            'extra_global_css_urls'] = self.EXTRA_GLOBAL_CSS_URLS
        self.template_value[
            'extra_global_js_urls'] = self.EXTRA_GLOBAL_JS_URLS

        # Common template information for the locale picker (only shown for
        # user in session)
        can_student_change_locale = (
            self.get_course().get_course_setting('can_student_change_locale')
            or self.get_course().app_context.can_pick_all_locales())
        if can_student_change_locale:
            self.template_value['available_locales'] = [
                {
                    'name': locales.get_locale_display_name(loc),
                    'value': loc
                } for loc in self.app_context.get_allowed_locales()]
            self.template_value['locale_xsrf_token'] = (
                XsrfTokenManager.create_xsrf_token(
                    StudentLocaleRESTHandler.XSRF_TOKEN_NAME))
            self.template_value['selected_locale'] = self.get_locale_for(
                self.request, self.app_context, prefs=prefs)
Exemple #2
0
 def _default_lesson_title_provider(
         self, app_context, unused_unit, lesson, unused_student):
     return safe_dom.Template(
         self.get_template('lesson_title.html'),
         lesson=lesson,
         can_see_drafts=custom_modules.can_see_drafts(app_context),
         is_course_admin=roles.Roles.is_course_admin(app_context),
         is_read_write_course=app_context.fs.is_read_write())
Exemple #3
0
def can_display_guide_to_current_user(course, config):
    user, student = (
        utils.CourseHandler.get_user_and_student_or_transient())
    course_avail = course.get_course_availability()
    self_avail = config.get(GUIDE_AVAILABILITY)
    displayability = courses.Course.get_element_displayability(
        course_avail, student.is_transient,
        custom_modules.can_see_drafts(course.app_context),
        GuideDisplayableElement(self_avail))
    return student, displayability.is_link_displayed, displayability
    def get(self):
        """Handles GET requests."""
        models.MemcacheManager.begin_readonly()
        try:
            student = self.personalize_page_and_get_enrolled(
                supports_transient_student=True)
            if not student:
                return

            # Extract incoming args
            unit, lesson, assessment = extract_unit_and_lesson_or_assessment(
                self)
            unit_id = unit.unit_id

            # If the unit is not currently available, and the user does not have
            # the permission to see drafts, redirect to the main page.
            available_units = self.get_track_matching_student(student)
            if ((not unit.now_available or unit not in available_units) and
                not custom_modules.can_see_drafts(self.app_context)):
                self.redirect('/')
                return

            # Set template values for nav bar and page type.
            self.template_value['navbar'] = {'course': True}

            # Set template values for a unit and its lesson entities
            self.template_value['unit'] = unit
            self.template_value['unit_id'] = unit.unit_id

            # These attributes are needed in order to render questions (with
            # progress indicators) in the lesson body. They are used by the
            # custom component renderers in the assessment_tags module.
            self.student = student
            self.unit_id = unit_id

            add_course_outline_to_template(self, student)
            self.template_value['is_progress_recorded'] = is_progress_recorded(
                self, student)

            if (unit.show_contents_on_one_page and
                'confirmation' not in self.request.params):
                self._show_all_contents(student, unit)
            else:
                self._show_single_element(student, unit, lesson, assessment)

            for extra_content_hook in self.EXTRA_CONTENT:
                extra_content = extra_content_hook(self.app_context)
                if extra_content is not None:
                    self.template_value['display_content'].append(extra_content)

            self._set_gcb_html_element_class()
        finally:
            models.MemcacheManager.end_readonly()
        self.render('unit.html')
Exemple #5
0
    def __init__(
            self, course, student=None, selected_ids=None,
            list_lessons_with_visible_names=False):
        self._course = course
        self._reviews_processor = self._course.get_reviews_processor()
        self._app_context = self._course.app_context
        self._student = student or models.TransientStudent()
        self._student_preferences = (
            models.StudentPreferencesDAO.load_or_default())
        self._settings = self._app_context.get_environ()
        self._list_lessons_with_visible_names = list_lessons_with_visible_names

        # Find out course availability policy.  Mostly this is for
        # distinguishing whether we are in 'registration_required' versus
        # 'registration_optional' or 'public'; in the former case, unit and
        # lesson policy governs visibility/linkability; in the latter, every
        # item is available.
        self._course_availability = (
            self._course.get_course_availability())

        # Whether current user is permitted to see drafts.  This is a
        # permission granted to lesser admins who still need to see course
        # content in pages showing student views.
        self._can_see_drafts = custom_modules.can_see_drafts(self._app_context)

        # Sometimes we do want to show progress, sometimes not.  Use common
        # function also referenced elsewhere to decide this.  Note that
        # assessment progress is always recorded due to saving answers/scores;
        # is_progress_recorded refers to event-based progress items.
        units, lessons = self._course.get_track_matching_student(self._student)
        self._is_progress_recorded = self._get_is_progress_recorded(units)
        if not self._student.is_transient:
            self._tracker = self._course.get_progress_tracker()
            self._progress = self._tracker.get_or_create_progress(student)
        else:
            self._tracker = None
            self._progress = None

        self._contents = []
        self._accessible_units = []
        self._active_elements = []
        self._accessible_lessons = collections.defaultdict(list)
        self._traverse_course(units, lessons)
        self._identify_active_items(selected_ids)
    def webserv_get(self, config, relname):
        course_avail = self.get_course().get_course_availability()
        self_avail = config.get(WEBSERV_AVAILABILITY)

        # get user, student
        user, student, profile = self.get_user_student_profile()
        self.prepare_metadata(course_avail, student)

        # check rights
        displayability = courses.Course.get_element_displayability(
            course_avail, student.is_transient,
            custom_modules.can_see_drafts(self.app_context),
            WebServerDisplayableElement(self_avail))
        if not displayability.is_link_displayed:
            self.error(404, 'Negative displayability: %s' % str(displayability))
            return

        # render content
        return self.serve_resource(config, relname)
    def get(self):
        """Handles GET requests."""
        embedded = bool(self.request.get('embedded'))

        student = self.personalize_page_and_get_enrolled(
            supports_transient_student=True)
        if not student:
            return

        # Extract incoming args, binding to self if needed.
        assessment_name = self.request.get('name')
        self.unit_id = assessment_name
        course = self.get_course()
        unit = course.find_unit_by_id(self.unit_id)
        if not unit:
            self.error(404)
            return

        # If assessment is used as a pre/post within a unit, go see that view.
        parent_unit = course.get_parent_unit(self.unit_id)
        if parent_unit:
            self.redirect('/unit?unit=%s&assessment=%s' %
                          (parent_unit.unit_id, self.unit_id))
            return

        # If the assessment is not currently available, and the user does not
        # have the permission to see drafts redirect to the main page.
        if (not unit.now_available and
            not custom_modules.can_see_drafts(self.app_context)):
            self.redirect('/')
            return

        self.template_value['main_content'] = self.get_assessment_content(
            student, course, unit, as_lesson=False, embedded=embedded)
        self.template_value['assessment_name'] = assessment_name
        self.template_value['unit_id'] = self.unit_id
        self.template_value['navbar'] = {'course': True}
        if embedded:
            self.template_value['embed_child_js_url'] = embed.EMBED_CHILD_JS_URL
            self.template_value['gcb_html_element_class'] = 'hide-controls'

        self.render('assessment_page.html')
Exemple #8
0
    def webserv_get(self, config, relname):
        course_avail = self.get_course().get_course_availability()
        self_avail = config.get(WEBSERV_AVAILABILITY)

        # get user, student
        user, student, profile = self.get_user_student_profile()
        self.prepare_metadata(course_avail, student)

        # check rights
        displayability = courses.Course.get_element_displayability(
            course_avail, student.is_transient,
            custom_modules.can_see_drafts(self.app_context),
            WebServerDisplayableElement(self_avail))
        if not displayability.is_link_displayed:
            self.error(404,
                       'Negative displayability: %s' % str(displayability))
            return

        # render content
        return self.serve_resource(config, relname)