def _populate_template(self, course, unit, review_steps): """Adds variables to the template for the review dashboard.""" self.template_value['assessment_name'] = unit.title self.template_value['unit_id'] = unit.unit_id parent_unit = course.get_parent_unit(unit.unit_id) if parent_unit is not None: self.template_value['back_link'] = 'unit?unit=%s&assessment=%s' % ( parent_unit.unit_id, unit.unit_id) else: self.template_value['back_link'] = ( 'assessment?name=%s' % unit.unit_id) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.template_value['review_dashboard_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('review-dashboard-post')) self.template_value['REVIEW_STATE_COMPLETED'] = ( domain.REVIEW_STATE_COMPLETED) self.template_value['review_steps'] = review_steps self.template_value['review_min_count'] = ( unit.workflow.get_review_min_count()) review_due_date = unit.workflow.get_review_due_date() if review_due_date: self.template_value['review_due_date'] = review_due_date.strftime( HUMAN_READABLE_DATETIME_FORMAT) time_now = datetime.datetime.now() self.template_value['due_date_exceeded'] = (time_now > review_due_date)
def get(self): """Handles GET requests.""" if not self.personalize_page_and_get_enrolled(): return # Extract incoming args unit_id, lesson_id = extract_unit_and_lesson_id(self) self.template_value['unit_id'] = unit_id self.template_value['lesson_id'] = lesson_id # Set template values for a unit and its lesson entities for unit in self.get_units(): if unit.unit_id == str(unit_id): self.template_value['units'] = unit lessons = self.get_lessons(unit_id) self.template_value['lessons'] = lessons # Set template values for nav bar self.template_value['navbar'] = {'course': True} # Set template values for back and next nav buttons self.template_value['back_button_url'] = ( 'unit?unit=%s&lesson=%s' % (unit_id, lesson_id)) if lesson_id == len(lessons): self.template_value['next_button_url'] = '' else: self.template_value['next_button_url'] = ( 'unit?unit=%s&lesson=%s' % (unit_id, lesson_id + 1)) self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.render('activity.html')
def get(self): """Handles GET requests.""" models.MemcacheManager.begin_readonly() try: user = self.personalize_page_and_get_user() if user is None: student = TRANSIENT_STUDENT else: student = Student.get_enrolled_student_by_user(user) profile = StudentProfileDAO.get_profile_by_user(user) self.template_value['has_global_profile'] = profile is not None if not student: student = TRANSIENT_STUDENT if (student.is_transient and not self.app_context.get_environ()['course']['browsable']): self.redirect('/preview') return # If we are on this page due to visiting the course base URL # (and not base url plus "/course"), redirect registered students # to the last page they were looking at. last_location = self.get_redirect_location(student) if last_location: self.redirect(last_location) return tracker = self.get_progress_tracker() units = self.get_track_matching_student(student) units = filter_assessments_used_within_units(units) self.template_value['units'] = units self.template_value['show_registration_page'] = True if student and not student.is_transient: augment_assessment_units(self.get_course(), student) self.template_value['course_progress'] = ( tracker.get_course_progress(student)) elif user: profile = StudentProfileDAO.get_profile_by_user_id( user.user_id()) additional_registration_fields = self.app_context.get_environ( )['reg_form']['additional_registration_fields'] if profile is not None and not additional_registration_fields: self.template_value['show_registration_page'] = False self.template_value['register_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('register-post')) self.template_value['transient_student'] = student.is_transient self.template_value['progress'] = tracker.get_unit_progress(student) course = self.app_context.get_environ()['course'] set_image_or_video_exists(self.template_value, course) self.template_value['is_progress_recorded'] = is_progress_recorded( self, student) self.template_value['navbar'] = {'course': True} finally: models.MemcacheManager.end_readonly() self.render('course.html')
def get(self): """Handles GET requests.""" user = self.personalize_page_and_get_user() if user is None: student = TRANSIENT_STUDENT else: student = Student.get_enrolled_student_by_email(user.email()) profile = StudentProfileDAO.get_profile_by_user_id(user.user_id()) self.template_value['has_global_profile'] = profile is not None if not student: student = TRANSIENT_STUDENT if (student.is_transient and not self.app_context.get_environ()['course']['browsable']): self.redirect('/preview') return self.template_value['units'] = self.get_units() self.template_value['show_registration_page'] = True if student and not student.is_transient: self.augment_assessment_units(student) elif user: profile = StudentProfileDAO.get_profile_by_user_id(user.user_id()) additional_registration_fields = self.app_context.get_environ( )['reg_form']['additional_registration_fields'] if profile is not None and not additional_registration_fields: self.template_value['show_registration_page'] = False self.template_value['register_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('register-post')) self.template_value['transient_student'] = student.is_transient self.template_value['progress'] = ( self.get_progress_tracker().get_unit_progress(student)) #progress bar total_progress = (self.get_progress_tracker().get_overall_progress_score(student)) self.template_value['progress_value'] = total_progress.get('progress_score', 0) self.template_value['complete_value'] = total_progress.get('completed_score', 0) self.template_value['percentage'] = total_progress.get('percentage', '') self.template_value['progress'] = (self.get_progress_tracker().get_unit_progress(student)) course = self.app_context.get_environ()['course'] self.template_value['video_exists'] = bool( 'main_video' in course and 'url' in course['main_video'] and course['main_video']['url']) self.template_value['image_exists'] = bool( 'main_image' in course and 'url' in course['main_image'] and course['main_image']['url']) self.template_value['is_progress_recorded'] = ( CAN_PERSIST_ACTIVITY_EVENTS.value) self.template_value['navbar'] = {'course': True} self.render('home.html')
def get(self): """Handles GET requests.""" if not self.personalize_page_and_get_enrolled(): return # Extract incoming args unit_id = self.request.get('name') self.template_value['navbar'] = {'course': True} self.template_value['assessment_script_src'] = ( self.get_course().get_assessment_filename(unit_id)) self.template_value['unit_id'] = unit_id self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value['assessment_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('assessment-post')) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.render('assessment.html')
def populate_template(self, unit, review_steps): """Adds variables to the template for the review dashboard.""" self.template_value["assessment_name"] = unit.title self.template_value["unit_id"] = unit.unit_id self.template_value["event_xsrf_token"] = XsrfTokenManager.create_xsrf_token("event-post") self.template_value["review_dashboard_xsrf_token"] = XsrfTokenManager.create_xsrf_token("review-dashboard-post") self.template_value["REVIEW_STATE_COMPLETED"] = domain.REVIEW_STATE_COMPLETED self.template_value["review_steps"] = review_steps self.template_value["review_min_count"] = unit.workflow.get_review_min_count() review_due_date = unit.workflow.get_review_due_date() if review_due_date: self.template_value["review_due_date"] = review_due_date.strftime(HUMAN_READABLE_DATETIME_FORMAT) time_now = datetime.datetime.now() self.template_value["due_date_exceeded"] = time_now > review_due_date
def get(self): """Handles GET requests.""" if not self.personalize_page_and_get_enrolled(): return # Extract incoming args n = self.request.get('name') if not n: n = 'Pre' self.template_value['name'] = n self.template_value['navbar'] = {'course': True} self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value['assessment_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('assessment-post')) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.render('assessment.html')
def get(self): """Handles GET requests.""" if not self.personalize_page_and_get_enrolled(): return # Extract incoming args n = self.request.get('name') if not n: n = 'Pre' self.template_value['name'] = n self.template_value['navbar'] = {'course': True} self.template_value[ 'record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value['assessment_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('assessment-post')) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.render('assessment.html')
def get(self): """Handles GET requests.""" user = self.personalize_page_and_get_user() if user is None: student = TRANSIENT_STUDENT else: student = Student.get_enrolled_student_by_email(user.email()) profile = StudentProfileDAO.get_profile_by_user_id(user.user_id()) self.template_value['has_global_profile'] = profile is not None if not student: student = TRANSIENT_STUDENT if (student.is_transient and not self.app_context.get_environ()['course']['browsable']): self.redirect('/preview') return self.template_value['units'] = self.get_units() self.template_value['show_registration_page'] = True if student and not student.is_transient: self.augment_assessment_units(student) elif user: profile = StudentProfileDAO.get_profile_by_user_id(user.user_id()) additional_registration_fields = self.app_context.get_environ( )['reg_form']['additional_registration_fields'] if profile is not None and not additional_registration_fields: self.template_value['show_registration_page'] = False self.template_value['register_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('register-post')) self.template_value['transient_student'] = student.is_transient self.template_value['progress'] = ( self.get_progress_tracker().get_unit_progress(student)) course = self.app_context.get_environ()['course'] self.template_value['video_exists'] = bool( 'main_video' in course and 'url' in course['main_video'] and course['main_video']['url']) self.template_value['image_exists'] = bool( 'main_image' in course and 'url' in course['main_image'] and course['main_image']['url']) self.template_value['is_progress_recorded'] = ( CAN_PERSIST_ACTIVITY_EVENTS.value) self.template_value['navbar'] = {'course': True} self.template_value['units_progress'] = self.get_course().get_units_progress() self.render('course.html')
def populate_template(self, unit, review_steps): """Adds variables to the template for the review dashboard.""" self.template_value['assessment_name'] = unit.title self.template_value['unit_id'] = unit.unit_id self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.template_value['review_dashboard_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('review-dashboard-post')) self.template_value['REVIEW_STATE_COMPLETED'] = ( domain.REVIEW_STATE_COMPLETED) self.template_value['review_steps'] = review_steps self.template_value['review_min_count'] = ( unit.workflow.get_review_min_count()) review_due_date = unit.workflow.get_review_due_date() if review_due_date: self.template_value['review_due_date'] = review_due_date.strftime( HUMAN_READABLE_DATETIME_FORMAT) time_now = datetime.datetime.now() self.template_value['due_date_exceeded'] = (time_now > review_due_date)
def get(self): """Handles GET requests.""" if not self.personalize_page_and_get_enrolled(): return user = self.personalize_page_and_get_user() student = Student.get_by_email(user.email()) playlist = filter(lambda x: x != "", student.playlist) # Extract incoming args unit_id, lesson_id = extract_unit_and_lesson_id(self) self.template_value['unit_id'] = unit_id self.template_value['lesson_id'] = lesson_id # Set template values for a unit and its lesson entities for unit in self.get_units(): if unit.unit_id == str(unit_id): self.template_value['units'] = unit lessons = self.get_lessons(unit_id) self.template_value['lessons'] = lessons # Set template values for nav bar self.template_value['navbar'] = {'course': True} # Set template values for back and next nav buttons self.template_value['back_button_url'] = ( 'unit?unit=%s&lesson=%s' % (unit_id, lesson_id)) if str(unit_id) + '.' + str(lesson_id) in playlist: for i in range (len(playlist)): if playlist[i] == str(unit_id) + '.' + str(lesson_id) and i != len(playlist) - 1: next_playlist = playlist[i + 1] #will go out of bounds if at last item in playlist self.template_value['playlist_button_url'] = ( 'unit?unit=%s&lesson=%s' % (next_playlist[0], next_playlist[2])) break if lesson_id == len(lessons): self.template_value['next_button_url'] = '' else: self.template_value['next_button_url'] = ( 'unit?unit=%s&lesson=%s' % (unit_id, lesson_id + 1)) self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.render('activity.html')
def get(self): """Handles GET requests.""" user = self.personalize_page_and_get_user() if user is None: student = TRANSIENT_STUDENT else: student = Student.get_enrolled_student_by_email(user.email()) profile = StudentProfileDAO.get_profile_by_user_id(user.user_id()) self.template_value["has_global_profile"] = profile is not None if not student: student = TRANSIENT_STUDENT if student.is_transient and not self.app_context.get_environ()["course"]["browsable"]: self.redirect("/preview") return self.template_value["units"] = self.get_units() self.template_value["show_registration_page"] = True if student and not student.is_transient: self.augment_assessment_units(student) elif user: profile = StudentProfileDAO.get_profile_by_user_id(user.user_id()) additional_registration_fields = self.app_context.get_environ()["reg_form"][ "additional_registration_fields" ] if profile is not None and not additional_registration_fields: self.template_value["show_registration_page"] = False self.template_value["register_xsrf_token"] = XsrfTokenManager.create_xsrf_token("register-post") self.template_value["transient_student"] = student.is_transient self.template_value["progress"] = self.get_progress_tracker().get_unit_progress(student) course = self.app_context.get_environ()["course"] self.template_value["video_exists"] = bool( "main_video" in course and "url" in course["main_video"] and course["main_video"]["url"] ) self.template_value["image_exists"] = bool( "main_image" in course and "url" in course["main_image"] and course["main_image"]["url"] ) self.template_value["is_progress_recorded"] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value["navbar"] = {"course": True} self.render("course.html")
def get(self): """Handles GET requests.""" if not self.personalize_page_and_get_enrolled(): return # Extract incoming args unit_id, lesson_id = extract_unit_and_lesson_id(self) self.template_value['unit_id'] = unit_id self.template_value['lesson_id'] = lesson_id # Set template values for a unit and its lesson entities for unit in self.get_units(): if unit.unit_id == str(unit_id): self.template_value['units'] = unit lessons = self.get_lessons(unit_id) self.template_value['lessons'] = lessons # Set template values for nav bar self.template_value['navbar'] = {'course': True} # Set template values for back and next nav buttons self.template_value['back_button_url'] = ('unit?unit=%s&lesson=%s' % (unit_id, lesson_id)) if lesson_id == len(lessons): self.template_value['next_button_url'] = '' else: self.template_value['next_button_url'] = ( 'unit?unit=%s&lesson=%s' % (unit_id, lesson_id + 1)) self.template_value[ 'record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.render('activity.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled( supports_transient_student=True) if not student: return # Extract incoming args unit, lesson = extract_unit_and_lesson(self) unit_id = unit.unit_id # If the unit is not currently available, and the user is not an admin, # redirect to the main page. if (not unit.now_available and not Roles.is_course_admin(self.app_context)): self.redirect('/') return # Set template values for nav bar and page type. self.template_value['navbar'] = {'course': True} self.template_value['page_type'] = ACTIVITY_PAGE_TYPE lessons = self.get_lessons(unit_id) # Set template values for a unit and its lesson entities self.template_value['unit'] = unit self.template_value['unit_id'] = unit_id self.template_value['lesson'] = lesson self.template_value['lessons'] = lessons # If this unit contains no lessons, return. if not lesson: self.render('activity.html') return lesson_id = lesson.lesson_id self.template_value['lesson_id'] = lesson_id self.template_value['activity_script_src'] = ( self.get_course().get_activity_filename(unit_id, lesson_id)) index = lesson.index - 1 # indexes are 1-based # Format back button. self.template_value['back_button_url'] = ( 'unit?unit=%s&lesson=%s' % (unit_id, lesson_id)) # Format next button. if index >= len(lessons) - 1: self.template_value['next_button_url'] = '' else: next_lesson = lessons[index + 1] self.template_value['next_button_url'] = ( 'unit?unit=%s&lesson=%s' % ( unit_id, next_lesson.lesson_id)) # Set template values for student progress self.template_value['is_progress_recorded'] = ( CAN_PERSIST_ACTIVITY_EVENTS.value and not student.is_transient) if CAN_PERSIST_ACTIVITY_EVENTS.value: self.template_value['lesson_progress'] = ( self.get_progress_tracker().get_lesson_progress( student, unit_id)) # Mark this page as accessed. This is done after setting the # student progress template value, so that the mark only shows up # after the student visits the page for the first time. self.get_course().get_progress_tracker().put_activity_accessed( student, unit_id, lesson_id) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.render('activity.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled() if not student: return if student.playList is None or len(student.playList) == 0: return index = self.request.get('index') if not index: index = 0 index = int(index) if index >= len(student.playList): index = 0 unit, lesson = get_unit_lesson_from_playlist(self.get_course(), student.playList, index) unit_id = unit.unit_id # If the unit is not currently available, and the user is not an admin, # redirect to the main page. if (not unit.now_available and not Roles.is_course_admin(self.app_context)): self.redirect('/') return # Set template values for nav bar and page type. self.template_value['navbar'] = {'course': True} self.template_value['page_type'] = ACTIVITY_PAGE_TYPE lessons = self.get_lessons(unit_id) # Set template values for a unit and its lesson entities self.template_value['unit'] = unit self.template_value['unit_id'] = unit_id self.template_value['lesson'] = lesson self.template_value['lessons'] = lessons # If this unit contains no lessons, return. if not lesson: self.render('activity.html') return lesson_id = lesson.lesson_id self.template_value['lesson_id'] = lesson_id self.template_value['activity_script_src'] = ( self.get_course().get_activity_filename(unit_id, lesson_id)) # Format back button. self.template_value['back_button_url'] = ('unitplaylist?index=%s' % (index)) # Format next button. if not index < len(student.playList) - 1: self.template_value['next_button_url'] = '' else: self.template_value['next_button_url'] = ('unitplaylist?index=%s' % (index + 1)) # Set template value for event recording self.template_value[ 'record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value # Set template values for student progress self.template_value['is_progress_recorded'] = ( CAN_PERSIST_ACTIVITY_EVENTS.value) if CAN_PERSIST_ACTIVITY_EVENTS.value: self.template_value['progress'] = ( self.get_progress_tracker().get_lesson_progress( student, unit_id)) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) # Mark this page as accessed. This is done after setting the student # progress template value, so that the mark only shows up after the # student visits the page for the first time. self.get_course().get_progress_tracker().put_activity_accessed( student, unit_id, lesson_id) self.render('activity.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled() if not student: return course = self.get_course() rp = course.get_reviews_processor() unit, unused_lesson = extract_unit_and_lesson(self) if not course.needs_human_grader(unit): self.error(404) return review_step_key = self.request.get('key') if not unit or not review_step_key: self.error(404) return try: review_step_key = db.Key(encoded=review_step_key) review_step = rp.get_review_steps_by_keys( unit.unit_id, [review_step_key])[0] except Exception: # pylint: disable-msg=broad-except self.error(404) return if not review_step: self.error(404) return # Check that the student is allowed to review this submission. if not student.has_same_key_as(review_step.reviewer_key): self.error(404) return model_version = course.get_assessment_model_version(unit) assert model_version in courses.SUPPORTED_ASSESSMENT_MODEL_VERSIONS self.template_value['model_version'] = model_version if model_version == courses.ASSESSMENT_MODEL_VERSION_1_4: configure_assessment_view = self.configure_assessment_view_1_4 configure_readonly_review = self.configure_readonly_review_1_4 configure_active_review = self.configure_active_review_1_4 elif model_version == courses.ASSESSMENT_MODEL_VERSION_1_5: configure_assessment_view = self.configure_assessment_view_1_5 configure_readonly_review = self.configure_readonly_review_1_5 configure_active_review = self.configure_active_review_1_5 else: raise ValueError('Bad assessment model version: %s' % model_version) self.template_value['navbar'] = {'course': True} self.template_value['unit_id'] = unit.unit_id self.template_value['key'] = review_step_key submission_key = review_step.submission_key submission_contents = student_work.Submission.get_contents_by_key( submission_key) configure_assessment_view(unit, submission_contents) review_due_date = unit.workflow.get_review_due_date() if review_due_date: self.template_value['review_due_date'] = review_due_date.strftime( HUMAN_READABLE_DATETIME_FORMAT) review_key = review_step.review_key rev = rp.get_reviews_by_keys( unit.unit_id, [review_key])[0] if review_key else None time_now = datetime.datetime.now() show_readonly_review = ( review_step.state == domain.REVIEW_STATE_COMPLETED or time_now > review_due_date) self.template_value['due_date_exceeded'] = (time_now > review_due_date) if show_readonly_review: configure_readonly_review(unit, rev) else: # Populate the review form, configure_active_review(unit, rev) self.template_value['assessment_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('review-post')) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) # CGL-MOOC-Builder starts: # Set template value for students progress bar that shows on the top navigation(header.html) total_progress = (self.get_progress_tracker().get_overall_progress_score(student)) self.template_value['progress_value'] = total_progress.get('progress_score', 0) self.template_value['complete_value'] = total_progress.get('completed_score', 0) self.template_value['percentage'] = total_progress.get('percentage', '') # CGL-MOOC-Builder ends self.render('review.html')
def get(self): """Handles GET requests.""" 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 self.template_value['assessment_name'] = assessment_name course = self.get_course() unit = course.find_unit_by_id(self.unit_id) if not unit: self.error(404) return # If the assessment is not currently available, and the user is not an # admin, redirect to the main page. if (not unit.now_available and not Roles.is_course_admin(self.app_context)): self.redirect('/') return model_version = course.get_assessment_model_version(unit) assert model_version in courses.SUPPORTED_ASSESSMENT_MODEL_VERSIONS self.template_value['model_version'] = model_version if model_version == courses.ASSESSMENT_MODEL_VERSION_1_4: configure_readonly_view = self.configure_readonly_view_1_4 configure_active_view = self.configure_active_view_1_4 get_review_received = self.get_review_received_1_4 elif model_version == courses.ASSESSMENT_MODEL_VERSION_1_5: configure_readonly_view = self.configure_readonly_view_1_5 configure_active_view = self.configure_active_view_1_5 get_review_received = self.get_review_received_1_5 else: raise ValueError('Bad assessment model version: %s' % model_version) self.template_value['navbar'] = {'course': True} self.template_value['unit_id'] = self.unit_id self.template_value['assessment_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('assessment-post')) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.template_value['grader'] = unit.workflow.get_grader() readonly_view = False due_date_exceeded = False submission_due_date = unit.workflow.get_submission_due_date() if submission_due_date: self.template_value['submission_due_date'] = ( submission_due_date.strftime(HUMAN_READABLE_DATETIME_FORMAT)) time_now = datetime.datetime.now() if time_now > submission_due_date: readonly_view = True due_date_exceeded = True self.template_value['due_date_exceeded'] = True if course.needs_human_grader(unit) and not student.is_transient: self.template_value['matcher'] = unit.workflow.get_matcher() rp = course.get_reviews_processor() review_steps_by = rp.get_review_steps_by( unit.unit_id, student.get_key()) # Determine if the student can see others' reviews of his/her work. if (ReviewUtils.has_completed_enough_reviews( review_steps_by, unit.workflow.get_review_min_count())): submission_and_review_steps = ( rp.get_submission_and_review_steps( unit.unit_id, student.get_key())) submission_contents = submission_and_review_steps[0] review_steps_for = submission_and_review_steps[1] review_keys_for_student = [] for review_step in review_steps_for: can_show_review = ( review_step.state == domain.REVIEW_STATE_COMPLETED and not review_step.removed and review_step.review_key ) if can_show_review: review_keys_for_student.append(review_step.review_key) reviews_for_student = rp.get_reviews_by_keys( unit.unit_id, review_keys_for_student) self.template_value['reviews_received'] = [get_review_received( unit, review) for review in reviews_for_student] else: submission_contents = student_work.Submission.get_contents( unit.unit_id, student.get_key()) # Determine whether to show the assessment in readonly mode. if submission_contents or due_date_exceeded: readonly_view = True configure_readonly_view(unit, submission_contents) if not readonly_view: submission_contents = None if not student.is_transient: submission_contents = student_work.Submission.get_contents( unit.unit_id, student.get_key()) configure_active_view(unit, submission_contents) # CGL-MOOC-Builder starts: # Set template value for students progress bar that shows on the top navigation(header.html) total_progress = (self.get_progress_tracker().get_overall_progress_score(student)) self.template_value['progress_value'] = total_progress.get('progress_score', 0) self.template_value['complete_value'] = total_progress.get('completed_score', 0) self.template_value['percentage'] = total_progress.get('percentage', '') # CGL-MOOC-Builder ends self.render('assessment.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled() if not student: return course = self.get_course() rp = course.get_reviews_processor() unit, unused_lesson = extract_unit_and_lesson(self) if not course.needs_human_grader(unit): self.error(404) return review_step_key = self.request.get('key') if not unit or not review_step_key: self.error(404) return try: review_step_key = db.Key(encoded=review_step_key) review_step = rp.get_review_steps_by_keys( unit.unit_id, [review_step_key])[0] except Exception: # pylint: disable-msg=broad-except self.error(404) return if not review_step: self.error(404) return # Check that the student is allowed to review this submission. if not student.has_same_key_as(review_step.reviewer_key): self.error(404) return self.template_value['navbar'] = {'course': True} self.template_value['unit_id'] = unit.unit_id self.template_value['key'] = review_step_key submission_key = review_step.submission_key submission_contents = student_work.Submission.get_contents_by_key( submission_key) readonly_student_assessment = create_readonly_assessment_params( course.get_assessment_content(unit), StudentWorkUtils.get_answer_list(submission_contents) ) self.template_value['readonly_student_assessment'] = ( readonly_student_assessment ) review_due_date = unit.workflow.get_review_due_date() if review_due_date: self.template_value['review_due_date'] = review_due_date.strftime( HUMAN_READABLE_DATETIME_FORMAT) review_key = review_step.review_key rev = rp.get_reviews_by_keys( unit.unit_id, [review_key])[0] if review_key else None time_now = datetime.datetime.now() show_readonly_review = ( review_step.state == domain.REVIEW_STATE_COMPLETED or time_now > review_due_date) self.template_value['due_date_exceeded'] = (time_now > review_due_date) if show_readonly_review: readonly_review_form = create_readonly_assessment_params( course.get_review_form_content(unit), StudentWorkUtils.get_answer_list(rev) ) self.template_value['readonly_review_form'] = readonly_review_form else: # Populate the review form, self.template_value['assessment_script_src'] = ( self.get_course().get_review_form_filename(unit.unit_id)) saved_answers = (StudentWorkUtils.get_answer_list(rev) if rev else []) self.template_value['saved_answers'] = transforms.dumps( saved_answers) self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value['assessment_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('review-post')) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.render('review.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled() if not student: return course = self.get_course() rp = course.get_reviews_processor() unit, unused_lesson = extract_unit_and_lesson(self) if not course.needs_human_grader(unit): self.error(404) return review_step_key = self.request.get('key') if not unit or not review_step_key: self.error(404) return try: review_step_key = db.Key(encoded=review_step_key) review_step = rp.get_review_steps_by_keys( unit.unit_id, [review_step_key])[0] except Exception: # pylint: disable-msg=broad-except self.error(404) return if not review_step: self.error(404) return # Check that the student is allowed to review this submission. if not student.has_same_key_as(review_step.reviewer_key): self.error(404) return model_version = course.get_assessment_model_version(unit) assert model_version in courses.SUPPORTED_ASSESSMENT_MODEL_VERSIONS self.template_value['model_version'] = model_version if model_version == courses.ASSESSMENT_MODEL_VERSION_1_4: configure_assessment_view = self.configure_assessment_view_1_4 configure_readonly_review = self.configure_readonly_review_1_4 configure_active_review = self.configure_active_review_1_4 elif model_version == courses.ASSESSMENT_MODEL_VERSION_1_5: configure_assessment_view = self.configure_assessment_view_1_5 configure_readonly_review = self.configure_readonly_review_1_5 configure_active_review = self.configure_active_review_1_5 else: raise ValueError('Bad assessment model version: %s' % model_version) self.template_value['navbar'] = {'course': True} self.template_value['unit_id'] = unit.unit_id self.template_value['key'] = review_step_key submission_key = review_step.submission_key submission_contents = student_work.Submission.get_contents_by_key( submission_key) configure_assessment_view(unit, submission_contents) review_due_date = unit.workflow.get_review_due_date() if review_due_date: self.template_value['review_due_date'] = review_due_date.strftime( HUMAN_READABLE_DATETIME_FORMAT) review_key = review_step.review_key rev = rp.get_reviews_by_keys( unit.unit_id, [review_key])[0] if review_key else None time_now = datetime.datetime.now() show_readonly_review = ( review_step.state == domain.REVIEW_STATE_COMPLETED or time_now > review_due_date) self.template_value['due_date_exceeded'] = (time_now > review_due_date) if show_readonly_review: configure_readonly_review(unit, rev) else: # Populate the review form, configure_active_review(unit, rev) self.template_value['assessment_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('review-post')) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.render('review.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled() if not student: return # Extract incoming args unit, lesson = extract_unit_and_lesson(self) unit_id = unit.unit_id # If the unit is not currently available, and the user is not an admin, # redirect to the main page. if (not unit.now_available and not Roles.is_course_admin(self.app_context)): self.redirect('/') return # Set template values for nav bar and page type. self.template_value['navbar'] = {'course': True} self.template_value['page_type'] = ACTIVITY_PAGE_TYPE lessons = self.get_lessons(unit_id) # Set template values for a unit and its lesson entities self.template_value['unit'] = unit self.template_value['unit_id'] = unit_id self.template_value['lesson'] = lesson self.template_value['lessons'] = lessons # If this unit contains no lessons, return. if not lesson: self.render('activity.html') return lesson_id = lesson.lesson_id self.template_value['lesson_id'] = lesson_id self.template_value['activity_script_src'] = ( self.get_course().get_activity_filename(unit_id, lesson_id)) index = lesson.index - 1 # indexes are 1-based # Format back button. self.template_value['back_button_url'] = ( 'unit?unit=%s&lesson=%s' % (unit_id, lesson_id)) # Format next button. if index >= len(lessons) - 1: self.template_value['next_button_url'] = '' else: next_lesson = lessons[index + 1] self.template_value['next_button_url'] = ( 'unit?unit=%s&lesson=%s' % ( unit_id, next_lesson.lesson_id)) # Set template value for event recording self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value # Set template values for student progress self.template_value['is_progress_recorded'] = ( CAN_PERSIST_ACTIVITY_EVENTS.value) if CAN_PERSIST_ACTIVITY_EVENTS.value: self.template_value['progress'] = ( self.get_progress_tracker().get_lesson_progress( student, unit_id)) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) # Mark this page as accessed. This is done after setting the student # progress template value, so that the mark only shows up after the # student visits the page for the first time. self.get_course().get_progress_tracker().put_activity_accessed( student, unit_id, lesson_id) self.render('activity.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled( supports_transient_student=True) if not student: return # Extract incoming args unit_id = self.request.get('name') course = self.get_course() unit = course.find_unit_by_id(unit_id) if not unit: self.error(404) return model_version = course.get_assessment_model_version(unit) assert model_version in courses.SUPPORTED_ASSESSMENT_MODEL_VERSIONS self.template_value['model_version'] = model_version if model_version == courses.ASSESSMENT_MODEL_VERSION_1_4: configure_readonly_view = self.configure_readonly_view_1_4 configure_active_view = self.configure_active_view_1_4 get_review_received = self.get_review_received_1_4 elif model_version == courses.ASSESSMENT_MODEL_VERSION_1_5: configure_readonly_view = self.configure_readonly_view_1_5 configure_active_view = self.configure_active_view_1_5 get_review_received = self.get_review_received_1_5 else: raise ValueError('Bad assessment model version: %s' % model_version) self.template_value['navbar'] = {'course': True} self.template_value['unit_id'] = unit_id self.template_value['assessment_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('assessment-post')) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.template_value['grader'] = unit.workflow.get_grader() readonly_view = False due_date_exceeded = False submission_due_date = unit.workflow.get_submission_due_date() if submission_due_date: self.template_value['submission_due_date'] = ( submission_due_date.strftime(HUMAN_READABLE_DATETIME_FORMAT)) time_now = datetime.datetime.now() if time_now > submission_due_date: readonly_view = True due_date_exceeded = True self.template_value['due_date_exceeded'] = True if course.needs_human_grader(unit) and not student.is_transient: self.template_value['matcher'] = unit.workflow.get_matcher() rp = course.get_reviews_processor() review_steps_by = rp.get_review_steps_by( unit.unit_id, student.get_key()) # Determine if the student can see others' reviews of his/her work. if (ReviewUtils.has_completed_enough_reviews( review_steps_by, unit.workflow.get_review_min_count())): submission_and_review_steps = ( rp.get_submission_and_review_steps( unit.unit_id, student.get_key())) submission_contents = submission_and_review_steps[0] review_steps_for = submission_and_review_steps[1] review_keys_for_student = [] for review_step in review_steps_for: can_show_review = ( review_step.state == domain.REVIEW_STATE_COMPLETED and not review_step.removed and review_step.review_key ) if can_show_review: review_keys_for_student.append(review_step.review_key) reviews_for_student = rp.get_reviews_by_keys( unit.unit_id, review_keys_for_student) self.template_value['reviews_received'] = [get_review_received( unit, review) for review in reviews_for_student] else: submission_contents = student_work.Submission.get_contents( unit.unit_id, student.get_key()) # Determine whether to show the assessment in readonly mode. if submission_contents or due_date_exceeded: readonly_view = True configure_readonly_view(unit, submission_contents) if not readonly_view: submission_contents = None if not student.is_transient: submission_contents = student_work.Submission.get_contents( unit.unit_id, student.get_key()) configure_active_view(unit, submission_contents) self.render('assessment.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled() if not student: return course = self.get_course() rp = course.get_reviews_processor() unit, unused_lesson = extract_unit_and_lesson(self) if not course.needs_human_grader(unit): self.error(404) return review_step_key = self.request.get("key") if not unit or not review_step_key: self.error(404) return try: review_step_key = db.Key(encoded=review_step_key) review_step = rp.get_review_steps_by_keys(unit.unit_id, [review_step_key])[0] except Exception: # pylint: disable-msg=broad-except self.error(404) return if not review_step: self.error(404) return # Check that the student is allowed to review this submission. if not student.has_same_key_as(review_step.reviewer_key): self.error(404) return model_version = course.get_assessment_model_version(unit) assert model_version in courses.SUPPORTED_ASSESSMENT_MODEL_VERSIONS self.template_value["model_version"] = model_version if model_version == courses.ASSESSMENT_MODEL_VERSION_1_4: configure_assessment_view = self.configure_assessment_view_1_4 configure_readonly_review = self.configure_readonly_review_1_4 configure_active_review = self.configure_active_review_1_4 elif model_version == courses.ASSESSMENT_MODEL_VERSION_1_5: configure_assessment_view = self.configure_assessment_view_1_5 configure_readonly_review = self.configure_readonly_review_1_5 configure_active_review = self.configure_active_review_1_5 else: raise ValueError("Bad assessment model version: %s" % model_version) self.template_value["navbar"] = {"course": True} self.template_value["unit_id"] = unit.unit_id self.template_value["key"] = review_step_key submission_key = review_step.submission_key submission_contents = student_work.Submission.get_contents_by_key(submission_key) configure_assessment_view(unit, submission_contents) review_due_date = unit.workflow.get_review_due_date() if review_due_date: self.template_value["review_due_date"] = review_due_date.strftime(HUMAN_READABLE_DATETIME_FORMAT) review_key = review_step.review_key rev = rp.get_reviews_by_keys(unit.unit_id, [review_key])[0] if review_key else None time_now = datetime.datetime.now() show_readonly_review = review_step.state == domain.REVIEW_STATE_COMPLETED or time_now > review_due_date self.template_value["due_date_exceeded"] = time_now > review_due_date if show_readonly_review: configure_readonly_review(unit, rev) else: # Populate the review form, configure_active_review(unit, rev) self.template_value["assessment_xsrf_token"] = XsrfTokenManager.create_xsrf_token("review-post") self.template_value["event_xsrf_token"] = XsrfTokenManager.create_xsrf_token("event-post") self.render("review.html")
def get(self): """Handles GET requests.""" user = self.personalize_page_and_get_user() if user is None: student = TRANSIENT_STUDENT else: student = Student.get_enrolled_student_by_email(user.email()) profile = StudentProfileDAO.get_profile_by_user_id(user.user_id()) self.template_value['has_global_profile'] = profile is not None if not student: student = TRANSIENT_STUDENT if (student.is_transient and not self.app_context.get_environ()['course']['browsable']): self.redirect('/preview') return # CGL-MOOC-Builder: self.template_value['units'] = self.get_units() self.template_value['sorted_units'] = self.get_units_groupby_section() self.template_value['show_registration_page'] = True if student and not student.is_transient: self.augment_assessment_units(student) elif user: profile = StudentProfileDAO.get_profile_by_user_id(user.user_id()) additional_registration_fields = self.app_context.get_environ( )['reg_form']['additional_registration_fields'] if profile is not None and not additional_registration_fields: self.template_value['show_registration_page'] = False self.template_value['register_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('register-post')) self.template_value['transient_student'] = student.is_transient self.template_value['progress'] = ( self.get_progress_tracker().get_unit_progress(student)) course = self.app_context.get_environ()['course'] self.template_value['video_exists'] = bool( 'main_video' in course and 'url' in course['main_video'] and course['main_video']['url']) self.template_value['image_exists'] = bool( 'main_image' in course and 'url' in course['main_image'] and course['main_image']['url']) # CGL-MOOC-Builder: Set template values for instructor_details and main_video if 'instructor_details' in course: self.template_value['instructor_details'] = course['instructor_details'] else: self.template_value['instructor_details'] = '' if self.template_value['video_exists']: self.template_value['main_video'] = course['main_video']['url'] else: self.template_value['main_video'] = '' # CGL-MOOC-Builder: Set template value for instructor image and alt text. self.set_instructor_image_and_alt() # CGL-MOOC-Builder: Set template value for Google Community ID self.set_google_community_template_value() self.template_value['is_progress_recorded'] = ( CAN_PERSIST_ACTIVITY_EVENTS.value) self.template_value['navbar'] = {'course': True} # CGL-MOOC-Builder starts: # Set template value for students progress bar that shows on the top navigation(header.html) total_progress = (self.get_progress_tracker().get_overall_progress_score(student)) self.template_value['progress_value'] = total_progress.get('progress_score', 0) self.template_value['complete_value'] = total_progress.get('completed_score', 0) self.template_value['percentage'] = total_progress.get('percentage', '') # Set template value for all lesson information in course_structure.html all_lessons = {} for u in self.template_value['units']: if u.type == 'U': all_lessons[u.unit_id] = get_all_lesson(self, u.unit_id) self.template_value['all_lessons'] = all_lessons # CGL-MOOC-Builder ends self.render('home.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled(supports_transient_student=True) if not student: return # Extract incoming args unit, lesson = extract_unit_and_lesson(self) unit_id = unit.unit_id # If the unit is not currently available, and the user is not an admin, # redirect to the main page. if not unit.now_available and not Roles.is_course_admin(self.app_context): self.redirect("/") return # Set template values for nav bar and page type. self.template_value["navbar"] = {"course": True} self.template_value["page_type"] = ACTIVITY_PAGE_TYPE lessons = self.get_lessons(unit_id) # Set template values for a unit and its lesson entities self.template_value["unit"] = unit self.template_value["unit_id"] = unit_id self.template_value["lesson"] = lesson self.template_value["lessons"] = lessons # If this unit contains no lessons, return. if not lesson: self.render("activity.html") return lesson_id = lesson.lesson_id self.template_value["lesson_id"] = lesson_id self.template_value["activity_script_src"] = self.get_course().get_activity_filename(unit_id, lesson_id) index = lesson.index - 1 # indexes are 1-based # Format back button. self.template_value["back_button_url"] = "unit?unit=%s&lesson=%s" % (unit_id, lesson_id) # Format next button. if index >= len(lessons) - 1: self.template_value["next_button_url"] = "" else: next_lesson = lessons[index + 1] self.template_value["next_button_url"] = "unit?unit=%s&lesson=%s" % (unit_id, next_lesson.lesson_id) # Set template values for student progress self.template_value["is_progress_recorded"] = CAN_PERSIST_ACTIVITY_EVENTS.value and not student.is_transient if CAN_PERSIST_ACTIVITY_EVENTS.value: self.template_value["lesson_progress"] = self.get_progress_tracker().get_lesson_progress(student, unit_id) # Mark this page as accessed. This is done after setting the # student progress template value, so that the mark only shows up # after the student visits the page for the first time. self.get_course().get_progress_tracker().put_activity_accessed(student, unit_id, lesson_id) self.template_value["event_xsrf_token"] = XsrfTokenManager.create_xsrf_token("event-post") self.render("activity.html")
def get_start(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled() if not student: return if not self.assert_participant_or_fail(student): return # Extract incoming args unit_id = self.request.get('name') course = self.get_course() unit = course.find_unit_by_id(unit_id) if not unit: self.error(404) return self.template_value['navbar'] = {'course': True} try: AssessmentTracker.try_start_test(student, unit_id) except ValueError as e: self.template_value['error'] = e.message self.render('assessment_denied.html') return self.template_value['unit_id'] = unit_id self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value['assessment_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('assessment-post')) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.template_value['grader'] = unit.workflow.get_grader() readonly_view = False due_date_exceeded = False submission_due_date = unit.workflow.get_submission_due_date() if submission_due_date: self.template_value['submission_due_date'] = ( submission_due_date.strftime(HUMAN_READABLE_DATETIME_FORMAT)) time_now = datetime.datetime.now() if time_now > submission_due_date: readonly_view = True due_date_exceeded = True self.template_value['due_date_exceeded'] = True if course.needs_human_grader(unit): self.template_value['matcher'] = unit.workflow.get_matcher() rp = course.get_reviews_processor() review_steps_by = rp.get_review_steps_by( unit.unit_id, student.get_key()) # Determine if the student can see others' reviews of his/her work. if (ReviewUtils.has_completed_enough_reviews( review_steps_by, unit.workflow.get_review_min_count())): submission_and_review_steps = ( rp.get_submission_and_review_steps( unit.unit_id, student.get_key())) submission_contents = submission_and_review_steps[0] review_steps_for = submission_and_review_steps[1] review_keys_for_student = [] for review_step in review_steps_for: can_show_review = ( review_step.state == domain.REVIEW_STATE_COMPLETED and not review_step.removed and review_step.review_key ) if can_show_review: review_keys_for_student.append(review_step.review_key) reviews_for_student = rp.get_reviews_by_keys( unit.unit_id, review_keys_for_student) self.template_value['reviews_received'] = [ create_readonly_assessment_params( course.get_review_form_content(unit), StudentWorkUtils.get_answer_list(review) ) for review in reviews_for_student] else: submission_contents = student_work.Submission.get_contents( unit.unit_id, student.get_key()) # Determine whether to show the assessment in readonly mode. if submission_contents or due_date_exceeded: readonly_view = True self.template_value['readonly_student_assessment'] = ( create_readonly_assessment_params( course.get_assessment_content(unit), StudentWorkUtils.get_answer_list(submission_contents) ) ) if not readonly_view: self.template_value['assessment_script_src'] = ( self.get_course().get_assessment_filename(unit_id)) # If a previous submission exists, reinstate it. submission_contents = student_work.Submission.get_contents( unit.unit_id, student.get_key()) saved_answers = ( StudentWorkUtils.get_answer_list(submission_contents) if submission_contents else []) self.template_value['saved_answers'] = transforms.dumps( saved_answers) self.render('assessment.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled() if not student: return # Extract incoming args unit_id = self.request.get('name') course = self.get_course() unit = course.find_unit_by_id(unit_id) if not unit: self.error(404) return self.template_value['navbar'] = {'course': True} self.template_value['unit_id'] = unit_id self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value['assessment_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('assessment-post')) self.template_value['event_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('event-post')) self.template_value['grader'] = unit.workflow.get_grader() readonly_view = False due_date_exceeded = False submission_due_date = unit.workflow.get_submission_due_date() if submission_due_date: self.template_value['submission_due_date'] = ( submission_due_date.strftime(HUMAN_READABLE_DATETIME_FORMAT)) time_now = datetime.datetime.now() if time_now > submission_due_date: readonly_view = True due_date_exceeded = True self.template_value['due_date_exceeded'] = True if course.needs_human_grader(unit): self.template_value['matcher'] = unit.workflow.get_matcher() rp = course.get_reviews_processor() review_steps_by = rp.get_review_steps_by( unit.unit_id, student.get_key()) # Determine if the student can see others' reviews of his/her work. if (ReviewUtils.has_completed_enough_reviews( review_steps_by, unit.workflow.get_review_min_count())): submission_and_review_steps = ( rp.get_submission_and_review_steps( unit.unit_id, student.get_key())) submission_contents = submission_and_review_steps[0] review_steps_for = submission_and_review_steps[1] review_keys_for_student = [] for review_step in review_steps_for: can_show_review = ( review_step.state == domain.REVIEW_STATE_COMPLETED and not review_step.removed and review_step.review_key ) if can_show_review: review_keys_for_student.append(review_step.review_key) reviews_for_student = rp.get_reviews_by_keys( unit.unit_id, review_keys_for_student) self.template_value['reviews_received'] = [ create_readonly_assessment_params( course.get_review_form_content(unit), StudentWorkUtils.get_answer_list(review) ) for review in reviews_for_student] else: submission_contents = student_work.Submission.get_contents( unit.unit_id, student.get_key()) # Determine whether to show the assessment in readonly mode. if submission_contents or due_date_exceeded: readonly_view = True self.template_value['readonly_student_assessment'] = ( create_readonly_assessment_params( course.get_assessment_content(unit), StudentWorkUtils.get_answer_list(submission_contents) ) ) if not readonly_view: self.template_value['assessment_script_src'] = ( self.get_course().get_assessment_filename(unit_id)) # If a previous submission exists, reinstate it. submission_contents = student_work.Submission.get_contents( unit.unit_id, student.get_key()) saved_answers = ( StudentWorkUtils.get_answer_list(submission_contents) if submission_contents else []) self.template_value['saved_answers'] = transforms.dumps( saved_answers) self.render('assessment.html')
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled(supports_transient_student=True) if not student: return # Extract incoming args unit_id = self.request.get("name") course = self.get_course() unit = course.find_unit_by_id(unit_id) if not unit: self.error(404) return model_version = course.get_assessment_model_version(unit) assert model_version in courses.SUPPORTED_ASSESSMENT_MODEL_VERSIONS self.template_value["model_version"] = model_version if model_version == courses.ASSESSMENT_MODEL_VERSION_1_4: configure_readonly_view = self.configure_readonly_view_1_4 configure_active_view = self.configure_active_view_1_4 get_review_received = self.get_review_received_1_4 elif model_version == courses.ASSESSMENT_MODEL_VERSION_1_5: configure_readonly_view = self.configure_readonly_view_1_5 configure_active_view = self.configure_active_view_1_5 get_review_received = self.get_review_received_1_5 else: raise ValueError("Bad assessment model version: %s" % model_version) self.template_value["navbar"] = {"course": True} self.template_value["unit_id"] = unit_id self.template_value["assessment_xsrf_token"] = XsrfTokenManager.create_xsrf_token("assessment-post") self.template_value["event_xsrf_token"] = XsrfTokenManager.create_xsrf_token("event-post") self.template_value["grader"] = unit.workflow.get_grader() readonly_view = False due_date_exceeded = False submission_due_date = unit.workflow.get_submission_due_date() if submission_due_date: self.template_value["submission_due_date"] = submission_due_date.strftime(HUMAN_READABLE_DATETIME_FORMAT) time_now = datetime.datetime.now() if time_now > submission_due_date: readonly_view = True due_date_exceeded = True self.template_value["due_date_exceeded"] = True if course.needs_human_grader(unit) and not student.is_transient: self.template_value["matcher"] = unit.workflow.get_matcher() rp = course.get_reviews_processor() review_steps_by = rp.get_review_steps_by(unit.unit_id, student.get_key()) # Determine if the student can see others' reviews of his/her work. if ReviewUtils.has_completed_enough_reviews(review_steps_by, unit.workflow.get_review_min_count()): submission_and_review_steps = rp.get_submission_and_review_steps(unit.unit_id, student.get_key()) submission_contents = submission_and_review_steps[0] review_steps_for = submission_and_review_steps[1] review_keys_for_student = [] for review_step in review_steps_for: can_show_review = ( review_step.state == domain.REVIEW_STATE_COMPLETED and not review_step.removed and review_step.review_key ) if can_show_review: review_keys_for_student.append(review_step.review_key) reviews_for_student = rp.get_reviews_by_keys(unit.unit_id, review_keys_for_student) self.template_value["reviews_received"] = [ get_review_received(unit, review) for review in reviews_for_student ] else: submission_contents = student_work.Submission.get_contents(unit.unit_id, student.get_key()) # Determine whether to show the assessment in readonly mode. if submission_contents or due_date_exceeded: readonly_view = True configure_readonly_view(unit, submission_contents) if not readonly_view: submission_contents = None if not student.is_transient: submission_contents = student_work.Submission.get_contents(unit.unit_id, student.get_key()) configure_active_view(unit, submission_contents) self.render("assessment.html")
def get_start(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled() if not student: return if not self.assert_participant_or_fail(student): return # Extract incoming args unit_id = self.request.get("name") course = self.get_course() unit = course.find_unit_by_id(unit_id) if not unit: self.error(404) return self.template_value["navbar"] = {"course": True} try: AssessmentTracker.try_start_test(student, unit_id) except ValueError as e: self.template_value["error"] = e.message self.render("assessment_denied.html") return self.template_value["unit_id"] = unit_id self.template_value["record_events"] = CAN_PERSIST_ACTIVITY_EVENTS.value self.template_value["assessment_xsrf_token"] = XsrfTokenManager.create_xsrf_token("assessment-post") self.template_value["event_xsrf_token"] = XsrfTokenManager.create_xsrf_token("event-post") self.template_value["grader"] = unit.workflow.get_grader() readonly_view = False due_date_exceeded = False submission_due_date = unit.workflow.get_submission_due_date() if submission_due_date: self.template_value["submission_due_date"] = submission_due_date.strftime(HUMAN_READABLE_DATETIME_FORMAT) time_now = datetime.datetime.now() if time_now > submission_due_date: readonly_view = True due_date_exceeded = True self.template_value["due_date_exceeded"] = True if course.needs_human_grader(unit): self.template_value["matcher"] = unit.workflow.get_matcher() rp = course.get_reviews_processor() review_steps_by = rp.get_review_steps_by(unit.unit_id, student.get_key()) # Determine if the student can see others' reviews of his/her work. if ReviewUtils.has_completed_enough_reviews(review_steps_by, unit.workflow.get_review_min_count()): submission_and_review_steps = rp.get_submission_and_review_steps(unit.unit_id, student.get_key()) submission_contents = submission_and_review_steps[0] review_steps_for = submission_and_review_steps[1] review_keys_for_student = [] for review_step in review_steps_for: can_show_review = ( review_step.state == domain.REVIEW_STATE_COMPLETED and not review_step.removed and review_step.review_key ) if can_show_review: review_keys_for_student.append(review_step.review_key) reviews_for_student = rp.get_reviews_by_keys(unit.unit_id, review_keys_for_student) self.template_value["reviews_received"] = [ create_readonly_assessment_params( course.get_review_form_content(unit), StudentWorkUtils.get_answer_list(review) ) for review in reviews_for_student ] else: submission_contents = student_work.Submission.get_contents(unit.unit_id, student.get_key()) # Determine whether to show the assessment in readonly mode. if submission_contents or due_date_exceeded: readonly_view = True self.template_value["readonly_student_assessment"] = create_readonly_assessment_params( course.get_assessment_content(unit), StudentWorkUtils.get_answer_list(submission_contents) ) if not readonly_view: self.template_value["assessment_script_src"] = self.get_course().get_assessment_filename(unit_id) # If a previous submission exists, reinstate it. submission_contents = student_work.Submission.get_contents(unit.unit_id, student.get_key()) saved_answers = StudentWorkUtils.get_answer_list(submission_contents) if submission_contents else [] self.template_value["saved_answers"] = transforms.dumps(saved_answers) self.render("assessment.html")