def guide_get(self, config): student, can_display, displayability = ( can_display_guide_to_current_user(self.get_course(), config)) if not can_display: self.error( 404, 'Negative displayability: %s' % str(displayability)) return unit_id = self.request.get('unit_id') if not unit_id: self.error(404, 'Bad unit_id') return view = unit_outline.StudentCourseView( self.get_course(), student=student) unit = self.get_course().find_unit_by_id(unit_id) if not unit in view.get_units(): self.error(404, 'Unit not visible') return self.prepare(config, view, student, unit, view.get_lessons(unit.unit_id), self.template_value) template = jinja_utils.get_template( 'steps.html', TEMPLATE_DIRS, handler=self) self.response.write(template.render(self.template_value))
def set_common_values(self, settings, student, course, course_availability): self.template_value['transient_student'] = student.is_transient self.template_value['navbar'] = {'course': True} student_view = unit_outline.StudentCourseView(course, student) self.template_value['course_outline'] = student_view.contents self.template_value['course_availability'] = course_availability self.template_value['show_lessons_in_syllabus'] = ( settings['course'].get('show_lessons_in_syllabus', False))
def set_common_values(self, settings, student, course, course_availability): self.template_value['transient_student'] = student.is_transient self.template_value['navbar'] = {'course': True} student_view = unit_outline.StudentCourseView(course, student) self.template_value['course_outline'] = student_view.contents self.template_value['course_availability'] = course_availability self.template_value['show_lessons_in_syllabus'] = ( settings['course'].get('show_lessons_in_syllabus', False)) self.template_value['extra_content'] = [] for extra_content_hook in self.EXTRA_CONTENT: extra_content = extra_content_hook(self.app_context, course, student_view, student) if extra_content is not None: self.template_value['extra_content'].append(extra_content)
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)
def get_courses(self): all_courses = [] for app_context in sorted(sites.get_all_courses()): with common_utils.Namespace(app_context.namespace): course = courses.Course(None, app_context) # check rights config = get_config(app_context) if not config.get(GUIDE_ENABLED_FOR_THIS_COURSE): continue student, can_display, displayability = ( can_display_guide_to_current_user(course, config)) if not can_display: continue # prepare values to render title = self.format_title( app_context, course, displayability, config) slug = app_context.get_slug() if slug == '/': slug = '' category_color = config.get(GUIDE_COLOR) if not category_color: category_color = GUIDE_COLOR_DEFAULT # iterate units units = [] for unit in unit_outline.StudentCourseView( course, student=student).get_units(): if unit.type != verify.UNIT_TYPE_UNIT: continue units.append(( unit.unit_id, unit.title, unit.description if unit.description else '', self.get_duration(config, course, unit) )) if units: all_courses.append((slug, title, category_color, units,)) sorted(all_courses, key=lambda x: x[1]) return all_courses
def get_course_view(cls, course, student): with common_utils.Namespace(course.app_context.namespace): return unit_outline.StudentCourseView( course, student=student, list_lessons_with_visible_names=True)
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')