def post(self, *args, **kwargs): """ TODO: error checking """ self.object = self.get_object() ctx = self.get_context_data() exercise = self.object as_student_form = ChooseStudentForm(self.request.POST, exercise=exercise) answers_valid, answer_forms = ReviewExerciseDetailView._validate_forms(self) if answers_valid and as_student_form.is_valid(): rsub = ReviewSubmission(course=ctx['course'], exercise=self.object, reviewed_submission=as_student_form.cleaned_data['reviewed_submission'], submitter_user=as_student_form.cleaned_data['submitter_user']) if exercise.use_groups: rsub.submitter_group = as_student_form.cleaned_data['submitter_group'] rsub.save() ReviewExerciseDetailView._save_modelform_answers(self, answer_forms, rsub) messages.success(self.request, 'Submission successful! You may see it below.') return redirect(rsub) ctx['forms'] = answer_forms ctx['choose_student_form'] = as_student_form return self.render_to_response(ctx)
def _post_random(self, ctx): rlock_list = self.object.reviewlocks_for(self.request.user) rlock = rlock_list.last() reviewed_submission = None lock_was_expired = False if rlock: reviewed_submission = rlock.original_submission elif not rlock and self.object.reviewlock_expiry_hours != 0: # if the expiry time has been set and a user keeps the exercise page # visible for a very long time without refreshing, it is possible that # whenever the form is actually submitted the original reviewlock has # already expired and deleted. in that situation, from the system's POV, # the user is making a bogus form submission since no lock is held. # if this "race condition" happens, grab the originally reviewed submission's # PK from the submitted form. # # this is not beautiful, but serves the purpose. other implementation # possibilities could be to just show an error page but that would waste # the peer-reviewing efforts by the student. some sort of verification could # also be implemented client-side in JavaScript to show the user a warning or # something. this, however, is the easiest solution. reviewed_submission = self.object.reviewable_exercise.submissions.get(pk=self.request.POST.get('choice')) lock_was_expired = True new_review_submission = ReviewSubmission(course=ctx['course'], submitter_user=self.request.user, exercise=self.object, reviewed_submission=reviewed_submission) if self.object.use_groups: new_review_submission.submitter_group = ctx['my_group'] if lock_was_expired: new_review_submission.save() else: new_review_submission.save_and_destroy_lock() self._save_modelform_answers(self.answer_forms, new_review_submission) if self.request.LTI_MODE: return _construct_aplus_response(exercise=self.object, user=self.request.user) return HttpResponseRedirect(new_review_submission.get_absolute_url())
def _post_choose(self, ctx): cf = ChooseForm(self.request.POST, exercise=self.object, user=self.request.user) if not cf.is_valid(): # this prevents fiddling with html form fields in dev tools raise PermissionDenied('You cannot do that. If you believe this is an error, contact admin.') # if ChooseForm is valid, construct a new ReviewSubmission reviewed_submission = OriginalSubmission.objects.get(pk=self.request.POST.get('choice')) new_review_submission = ReviewSubmission(course=ctx['course'], submitter_user=self.request.user, exercise=self.object, reviewed_submission=reviewed_submission) if self.object.use_groups: new_review_submission.submitter_group = ctx['my_group'] new_review_submission.save() self._save_modelform_answers(self.answer_forms, new_review_submission) if self.request.LTI_MODE: return _construct_aplus_response(exercise=self.object, user=self.request.user) return HttpResponseRedirect(new_review_submission.get_absolute_url())