def question_submission_view_student(request, object_id): question_submission = get_object_or_404(QuestionSubmission, id=object_id) # block access when grading is not finished assoc_submission = get_question_associated_submission(question_submission) if not is_staff(request.user) and not assoc_submission.allow_detail_access_for_student(): messages.warning(request, "You are not allowed to view question submission detail yet!") return HttpResponseRedirect(reverse("home")) disable_solution = False if isinstance(assoc_submission, OnlineTestQuestionSubmission): disable_solution = True remarking_records = question_submission.remarking_set.all() # Changing Score Form Processing form = ChangeScoreForm() if request.POST: if not is_staff(request.user): messages.warning(request, "You are not allowed to modify question submission!") return HttpResponseRedirect(reverse("home")) form = ChangeScoreForm(request.POST) if form.is_valid(): # process the form new_score = form.cleaned_data['new_score'] old_score = question_submission.score question_submission.score = new_score question_submission.save() Remarking.quick_save(old_score=old_score, new_score=new_score, modifier=request.user, comment=form.cleaned_data['comment'], question_submission=question_submission) messages.info(request, "Score has been successfully changed!") form = ChangeScoreForm() else: messages.warning(request, "Your form submission is not valid, please check!") # get relevant info about the submission question = question_submission.question # get the test case results test_case_set_results = TestCaseSetResult.objects.filter(question_submission=question_submission) question_submission_summary = get_summary(source=question_submission, fields=['get_score', 'submission_time', 'get_compilation_status']) similar_ques = question.get_similar_questions() return render(request, 'app-question/class-questionsubmission/detail.html', {'question_submission': question_submission, 'question_submission_summary': question_submission_summary, 'question': question, 'test_results': test_case_set_results, 'change_score_form': form, 'changing_score_records': remarking_records, 'similar_ques': similar_ques, 'disable_solution': disable_solution, 'is_staff': is_staff(request.user)})
def _get_table_html(self): table = "<h3>No data</h3>" if (len(self.paginated_data) > 0): table_maker = self.table_class( self.request_user, object_list=self.paginated_data, enable_edit=self.enable_staff_edit if is_staff(self.request_user) else False, field_names=self.get_fields(), enable_delete=self.enable_staff_delete if is_staff(self.request_user) else False, display_field_names=self.get_display_field_name(), ) table_maker.set_attr_method_args(self.get_attr_method_args()) table = table_maker.generate_table_html() return table
def user_login(request): message = '' if request.method == "POST": username = request.POST['username'] password = request.POST['password'] # authenticate the user user = authenticate(username=username, password=password) if (not user): # authentication failed message = 'Either the username or password is not correct' else: # authentication is okay new_assignment_submission_ids = None new_test_submission_ids = None if (is_staff(user)): new_assignment_submission_ids = [a.id for a in AssignmentSubmission.objects.filter( submission_time__gte=user.last_login) if a.is_completed] new_test_submission_ids = [a.id for a in OnlineTestSubmission.objects.filter(submission_time__gte=user.last_login)] login(request, user) request.session["new_assignment_submission_ids"] = new_assignment_submission_ids request.session["new_test_submission_ids"] = new_test_submission_ids if request.GET.get("next"): return HttpResponseRedirect(request.GET.get("next")) else: return HttpResponseRedirect('/home') return render(request, "account/login.html", {'message': message})
def question_submission_view_student_code_only(request, object_id): question_submission = get_object_or_404(QuestionSubmission, id=object_id) if question_submission.submitted_by != request.user: return HttpResponseRedirect("/") # block access when grading is not finished assoc_submission = get_question_associated_submission(question_submission) remarking_records = question_submission.remarking_set.all() # Changing Score Form Processing # form=ChangeScoreForm() # get relevant info about the submission question = question_submission.question # get the test case results # test_case_set_results=TestCaseSetResult.objects.filter(question_submission=question_submission) # question_submission_summary=get_summary(source=question_submission,fields=['get_score','submission_time','get_compilation_status']) similar_ques = question.get_similar_questions() return render(request, 'app-question/class-questionsubmission/detail.html', {'question_submission': question_submission, 'question': question, 'changing_score_records': remarking_records, 'similar_ques': similar_ques, 'is_staff': is_staff(request.user)})
def get_list_data(user, sort_by, **kwargs): if (is_staff(user)): return OnlineTestSubmission.objects.filter(**kwargs).order_by( sort_by) if sort_by else OnlineTestSubmission.objects.filter( **kwargs).order_by(sort_by) return OnlineTestSubmission.objects.filter( submitted_by=user, is_completed=True, **kwargs).order_by( sort_by) if sort_by else OnlineTestSubmission.objects.filter( submitted_by=user, is_completed=True, **kwargs)
def home(request): if is_staff(request.user): new_assignment_submissions=[] new_test_submissions=[] try: new_assignment_submissions=[get_object_or_404(AssignmentSubmission,id=a) for a in request.session["new_assignment_submission_ids"]] new_test_submissions=[get_object_or_404(OnlineTestSubmission,id=a) for a in request.session["new_test_submission_ids"]] except: pass return render(request, 'app-appglobal/home.html',{'new_assignment_submissions':new_assignment_submissions,'new_test_submissions':new_test_submissions}) else: return render(request, 'app-appglobal/home.html')
def get_object_list(self,sort_by,filter_dict,user): if (is_staff(user)): assignments=Assignment.objects.filter(**filter_dict) return assignments.order_by(sort_by) if sort_by else assignments else: return Assignment.get_student_can_submit(sort_by=sort_by,user=user,**filter_dict)
def get_fields(self): if (not is_staff(self.request_user)): return ["title","description","end_submission_time","get_start_submission"] else: return ["title","description","start_submission_time","get_submission_link"]
def get_fields(self): if (is_staff(self.request_user)): return ["get_question_title","weightage","get_score","get_detail_link"] else: return ["get_question_title","weightage","get_score","get_detail_link_for_student"]