def post(self): """Allows a reviewer to request a new review.""" student = self.personalize_page_and_get_enrolled() if not student: return if not self.assert_xsrf_token_or_fail(self.request, "review-dashboard-post"): return course = self.get_course() unit, unused_lesson = extract_unit_and_lesson(self) if not unit: self.error(404) return rp = course.get_reviews_processor() review_steps = rp.get_review_steps_by(unit.unit_id, student.get_key()) self.template_value["navbar"] = {"course": True} if not course.needs_human_grader(unit): self.error(404) return # Check that the student has submitted the corresponding assignment. if not rp.does_submission_exist(unit.unit_id, student.get_key()): self.template_value["error_code"] = "cannot_review_before_submitting_assignment" self.render("error.html") return # Check that the review due date has not passed. time_now = datetime.datetime.now() review_due_date = unit.workflow.get_review_due_date() if time_now > review_due_date: self.template_value["error_code"] = "cannot_request_review_after_deadline" self.render("error.html") return # Check that the student can request a new review. review_min_count = unit.workflow.get_review_min_count() can_request_new_review = len(review_steps) < review_min_count or ReviewUtils.has_completed_all_assigned_reviews( review_steps ) if not can_request_new_review: self.template_value["review_min_count"] = review_min_count self.template_value["error_code"] = "must_complete_more_reviews" self.render("error.html") return self.template_value["no_submissions_available"] = True try: review_step_key = rp.get_new_review(unit.unit_id, student.get_key()) redirect_params = {"key": review_step_key, "unit": unit.unit_id} self.redirect("/review?%s" % urllib.urlencode(redirect_params)) except Exception: # pylint: disable-msg=broad-except review_steps = rp.get_review_steps_by(unit.unit_id, student.get_key()) self.populate_template(unit, review_steps) self.render("review_dashboard.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, _ = extract_unit_and_lesson(self) if not unit: self.error(404) return self.template_value['navbar'] = {'course': True} if not course.needs_human_grader(unit): self.error(404) return #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', '') # Check that the student has submitted the corresponding assignment. if not rp.does_submission_exist(unit.unit_id, student.get_key()): self.template_value['error_code'] = ( 'cannot_review_before_submitting_assignment') self.render('error.html') return review_steps = rp.get_review_steps_by(unit.unit_id, student.get_key()) self.populate_template(unit, review_steps) required_review_count = unit.workflow.get_review_min_count() # The student can request a new submission if: # - all his/her current reviews are in Draft/Completed state, and # - he/she is not in the state where the required number of reviews # has already been requested, but not all of these are completed. self.template_value['can_request_new_review'] = ( len(review_steps) < required_review_count or ReviewUtils.has_completed_all_assigned_reviews(review_steps)) self.render('review_dashboard.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, _ = extract_unit_and_lesson(self) if not unit: self.error(404) return self.template_value['navbar'] = {'course': True} if not course.needs_human_grader(unit): self.error(404) return # 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 # Check that the student has submitted the corresponding assignment. if not rp.does_submission_exist(unit.unit_id, student.get_key()): self.template_value['error_code'] = ( 'cannot_review_before_submitting_assignment') self.render('error.html') return review_steps = rp.get_review_steps_by(unit.unit_id, student.get_key()) self.populate_template(unit, review_steps) required_review_count = unit.workflow.get_review_min_count() # The student can request a new submission if: # - all his/her current reviews are in Draft/Completed state, and # - he/she is not in the state where the required number of reviews # has already been requested, but not all of these are completed. self.template_value['can_request_new_review'] = ( len(review_steps) < required_review_count or ReviewUtils.has_completed_all_assigned_reviews(review_steps) ) self.render('review_dashboard.html')
def augment_assessment_units(self, student): """Adds additional fields to assessment units.""" course = self.get_course() rp = course.get_reviews_processor() for unit in self.template_value["units"]: if unit.type == "A": unit.needs_human_grader = course.needs_human_grader(unit) if unit.needs_human_grader: review_steps = rp.get_review_steps_by(unit.unit_id, student.get_key()) review_min_count = unit.workflow.get_review_min_count() unit.matcher = unit.workflow.get_matcher() unit.review_progress = ReviewUtils.get_review_progress( review_steps, review_min_count, course.get_progress_tracker() ) unit.is_submitted = rp.does_submission_exist(unit.unit_id, student.get_key())
def augment_assessment_units(course, student): """Adds additional fields to assessment units.""" rp = course.get_reviews_processor() for unit in course.get_units(): if unit.type == 'A': if unit.needs_human_grader(): review_steps = rp.get_review_steps_by( unit.unit_id, student.get_key()) review_min_count = unit.workflow.get_review_min_count() unit.matcher = unit.workflow.get_matcher() unit.review_progress = ReviewUtils.get_review_progress( review_steps, review_min_count, course.get_progress_tracker() ) unit.is_submitted = rp.does_submission_exist( unit.unit_id, student.get_key())
def augment_assessment_units(self, student): """Adds additional fields to assessment units.""" course = self.get_course() rp = course.get_reviews_processor() for unit in self.template_value['units']: if unit.type == 'A': unit.needs_human_grader = course.needs_human_grader(unit) if unit.needs_human_grader: review_steps = rp.get_review_steps_by( unit.unit_id, student.get_key()) review_min_count = unit.workflow.get_review_min_count() unit.matcher = unit.workflow.get_matcher() unit.review_progress = ReviewUtils.get_review_progress( review_steps, review_min_count, course.get_progress_tracker()) unit.is_submitted = rp.does_submission_exist( unit.unit_id, student.get_key())
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, _ = extract_unit_and_lesson(self) if not unit: self.error(404) return self.template_value["navbar"] = {"course": True} if not course.needs_human_grader(unit): self.error(404) return # Check that the student has submitted the corresponding assignment. if not rp.does_submission_exist(unit.unit_id, student.get_key()): self.template_value["error_code"] = "cannot_review_before_submitting_assignment" self.render("error.html") return review_steps = rp.get_review_steps_by(unit.unit_id, student.get_key()) self.populate_template(unit, review_steps) required_review_count = unit.workflow.get_review_min_count() # The student can request a new submission if: # - all his/her current reviews are in Draft/Completed state, and # - he/she is not in the state where the required number of reviews # has already been requested, but not all of these are completed. self.template_value["can_request_new_review"] = len( review_steps ) < required_review_count or ReviewUtils.has_completed_all_assigned_reviews(review_steps) self.render("review_dashboard.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 post(self): """Allows a reviewer to request a new review.""" student = self.personalize_page_and_get_enrolled() if not student: return if not self.assert_xsrf_token_or_fail( self.request, 'review-dashboard-post'): return course = self.get_course() unit, unused_lesson = extract_unit_and_lesson(self) if not unit: self.error(404) return rp = course.get_reviews_processor() review_steps = rp.get_review_steps_by(unit.unit_id, student.get_key()) self.template_value['navbar'] = {'course': True} if not course.needs_human_grader(unit): self.error(404) return # Check that the student has submitted the corresponding assignment. if not rp.does_submission_exist(unit.unit_id, student.get_key()): self.template_value['error_code'] = ( 'cannot_review_before_submitting_assignment') self.render('error.html') return # Check that the review due date has not passed. time_now = datetime.datetime.now() review_due_date = unit.workflow.get_review_due_date() if time_now > review_due_date: self.template_value['error_code'] = ( 'cannot_request_review_after_deadline') self.render('error.html') return # Check that the student can request a new review. review_min_count = unit.workflow.get_review_min_count() can_request_new_review = ( len(review_steps) < review_min_count or ReviewUtils.has_completed_all_assigned_reviews(review_steps)) if not can_request_new_review: self.template_value['review_min_count'] = review_min_count self.template_value['error_code'] = 'must_complete_more_reviews' self.render('error.html') return self.template_value['no_submissions_available'] = True try: review_step_key = rp.get_new_review(unit.unit_id, student.get_key()) redirect_params = { 'key': review_step_key, 'unit': unit.unit_id, } self.redirect('/review?%s' % urllib.urlencode(redirect_params)) except Exception: # pylint: disable-msg=broad-except review_steps = rp.get_review_steps_by( unit.unit_id, student.get_key()) self.populate_template(unit, review_steps) self.render('review_dashboard.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 post(self): """Allows a reviewer to request a new review.""" student = self.personalize_page_and_get_enrolled() if not student: return if not self.assert_xsrf_token_or_fail( self.request, 'review-dashboard-post'): return # 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 course = self.get_course() unit, unused_lesson = extract_unit_and_lesson(self) if not unit: self.error(404) return rp = course.get_reviews_processor() review_steps = rp.get_review_steps_by(unit.unit_id, student.get_key()) self.template_value['navbar'] = {'course': True} if not course.needs_human_grader(unit): self.error(404) return # Check that the student has submitted the corresponding assignment. if not rp.does_submission_exist(unit.unit_id, student.get_key()): self.template_value['error_code'] = ( 'cannot_review_before_submitting_assignment') self.render('error.html') return # Check that the review due date has not passed. time_now = datetime.datetime.now() review_due_date = unit.workflow.get_review_due_date() if time_now > review_due_date: self.template_value['error_code'] = ( 'cannot_request_review_after_deadline') self.render('error.html') return # Check that the student can request a new review. review_min_count = unit.workflow.get_review_min_count() can_request_new_review = ( len(review_steps) < review_min_count or ReviewUtils.has_completed_all_assigned_reviews(review_steps)) if not can_request_new_review: self.template_value['review_min_count'] = review_min_count self.template_value['error_code'] = 'must_complete_more_reviews' self.render('error.html') return self.template_value['no_submissions_available'] = True try: review_step_key = rp.get_new_review(unit.unit_id, student.get_key()) redirect_params = { 'key': review_step_key, 'unit': unit.unit_id, } self.redirect('/review?%s' % urllib.urlencode(redirect_params)) except Exception: # pylint: disable-msg=broad-except review_steps = rp.get_review_steps_by( unit.unit_id, student.get_key()) self.populate_template(unit, review_steps) self.render('review_dashboard.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(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')
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")