Exemplo n.º 1
0
    def get(self):
        """Handles GET requests."""
        embedded = bool(self.request.get('embedded'))

        student = None
        user = self.personalize_page_and_get_user()
        if user:
            student = models.Student.get_enrolled_student_by_user(user)
        student = student or models.TransientStudent()

        # 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.
        student_view = unit_outline.StudentCourseView(course, student)
        if not student_view.is_visible([self.unit_id]):
            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', save_location=not embedded)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def get(self):
        """Handles GET requests."""
        models.MemcacheManager.begin_readonly()
        try:
            student = None
            user = self.personalize_page_and_get_user()
            if user:
                student = models.Student.get_enrolled_student_by_user(user)
            student = student or models.TransientStudent()

            # What unit/lesson/assessment IDs are wanted for this request?
            selected_ids = []
            if 'unit' in self.request.params:
                selected_ids.append(self.request.get('unit'))
                if 'lesson' in self.request.params:
                    selected_ids.append(self.request.get('lesson'))
                elif 'assessment' in self.request.params:
                    selected_ids.append(self.request.get('assessment'))

            # Build up an object giving this student's view on the course.
            course = self.get_course()
            student_view = unit_outline.StudentCourseView(
                course, student, selected_ids)

            # If the location in the course selected by GET arguments is not
            # available, redirect to the course overview page.
            active_elements = student_view.get_active_elements()
            if not active_elements:
                self.redirect('/')
                return
            unit = active_elements[0].course_element
            if (not unit.show_contents_on_one_page and
                len(active_elements) < len(selected_ids)):
                self.redirect('/')
                return
            lesson = assessment = None
            if len(active_elements) > 1:
                if active_elements[1].kind == 'lesson':
                    lesson = active_elements[1].course_element
                else:
                    assessment = active_elements[1].course_element

            # 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.unit_id

            course_availability = course.get_course_availability()
            settings = self.app_context.get_environ()
            self.template_value['course_outline'] = student_view.contents
            self.template_value['course_availability'] = course_availability
            if (unit.show_contents_on_one_page and
                'confirmation' not in self.request.params):
                self._show_all_contents(student, unit, student_view)
            else:
                # For all-on-one-page units, the student view won't believe
                # that pre/post assessments are separate, visibile things,
                # so we must separately load the appropriate assessment.
                if (unit.show_contents_on_one_page and
                    'confirmation' in self.request.params):
                    assessment = course.find_unit_by_id(
                        self.request.get('assessment'))
                self._show_single_element(student, unit, lesson, assessment,
                                          student_view)

            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')