def save_peer_review(request, publication_id): if request.is_ajax(): if request.method == 'POST': peer_review_id = int(request.POST['peer_review_id']) form = PeerReviewForm(request.POST, request.FILES); try: publication = Publication.objects.get(publication_id=publication_id) except Publication.DoesNotExist: return HttpResponse(json.dumps({ 'status' : 'failed', 'message' : 'record does not exist' }), content_type="application/json") if form.is_valid(): # Save the peer review form.instance.user = request.user form.save() if peer_review_id == 0: publication.reviews.add(form.instance) # Indicate success response_data = {'status' : 'success', 'message' : 'submitted'} else: response_data = {'status' : 'failed', 'message' : json.dumps(form.errors)} return HttpResponse(json.dumps(response_data), content_type="application/json")
def save_peer_review(request, course_id, submission_id): if request.is_ajax(): if request.method == 'POST': question_id = int(request.POST['question_id']) question_type = int(request.POST['question_type']) # Fetch from database course = Course.objects.get(id=course_id) try: a_submission = AssignmentSubmission.objects.get(submission_id=submission_id) except AssignmentSubmission.DoesNotExist: response_data = {'status' : 'failed', 'message' : 'cannot find submission'} return HttpResponse(json.dumps(response_data), content_type="application/json") assignment = a_submission.assignment question = None q_submission = None if question_type == settings.RESPONSE_QUESTION_TYPE: question = ResponseQuestion.objects.get( assignment=assignment, question_id=question_id, ) q_submission = ResponseSubmission.objects.get( question=question, student=a_submission.student, ) elif question_type == settings.ESSAY_QUESTION_TYPE: question = EssayQuestion.objects.get( assignment=assignment, question_id=question_id ) q_submission = EssaySubmission.objects.get( question=question, student=a_submission.student, ) # Defensive Code if question is None: response_data = {'status' : 'failed', 'message' : 'cannot find question at id ' + question_id} return HttpResponse(json.dumps(response_data), content_type="application/json") if q_submission is None: response_data = {'status' : 'failed', 'message' : 'cannot find question submission'} return HttpResponse(json.dumps(response_data), content_type="application/json") form = PeerReviewForm(request.POST, request.FILES); if form.is_valid(): # Save the peer review form.instance.user = request.user form.save() # Save the peer review to the submission q_submission.reviews.add(form.instance) # Indicate success response_data = {'status' : 'success', 'message' : 'submitted'} else: response_data = {'status' : 'failed', 'message' : json.dumps(form.errors)} return HttpResponse(json.dumps(response_data), content_type="application/json")
def save_peer_review(request, course_id, assignment_id): if request.is_ajax(): if request.method == 'POST': question_id = int(request.POST['question_id']) question_type = int(request.POST['question_type']) submission_id = int(request.POST['submission_id']) # Fetch from database course = Course.objects.get(id=course_id) try: assignment = Assignment.objects.get(assignment_id=assignment_id) except Assignment.DoesNotExist: response_data = {'status' : 'failed', 'message' : 'cannot find assignment'} return HttpResponse(json.dumps(response_data), content_type="application/json") question = None submission = None if question_type == settings.RESPONSE_QUESTION_TYPE: question = ResponseQuestion.objects.get( assignment=assignment, question_id=question_id, ) submission = ResponseSubmission.objects.get( submission_id=submission_id ) elif question_type == settings.ESSAY_QUESTION_TYPE: question = EssayQuestion.objects.get( assignment=assignment, question_id=question_id ) submission = EssaySubmission.objects.get( submission_id=submission_id ) # Defensive Code if question is None: response_data = {'status' : 'failed', 'message' : 'cannot find question at id ' + question_id} return HttpResponse(json.dumps(response_data), content_type="application/json") if submission is None: response_data = {'status' : 'failed', 'message' : 'cannot find submission'} return HttpResponse(json.dumps(response_data), content_type="application/json") form = PeerReviewForm(request.POST, request.FILES); if form.is_valid(): # Save the peer review form.instance.user = request.user form.save() # Save the peer review to the submission submission.reviews.add(form.instance) # Indicate success response_data = {'status' : 'success', 'message' : 'submitted'} else: response_data = {'status' : 'failed', 'message' : json.dumps(form.errors)} return HttpResponse(json.dumps(response_data), content_type="application/json")
def save_peer_review(request, course_id, assignment_id): if request.is_ajax(): if request.method == "POST": question_id = int(request.POST["question_id"]) question_type = int(request.POST["question_type"]) submission_id = int(request.POST["submission_id"]) # Fetch from database course = Course.objects.get(id=course_id) try: assignment = Assignment.objects.get(assignment_id=assignment_id) except Assignment.DoesNotExist: response_data = {"status": "failed", "message": "cannot find assignment"} return HttpResponse(json.dumps(response_data), content_type="application/json") question = None submission = None if question_type == settings.RESPONSE_QUESTION_TYPE: question = ResponseQuestion.objects.get(assignment=assignment, question_id=question_id) submission = ResponseSubmission.objects.get(submission_id=submission_id) elif question_type == settings.ESSAY_QUESTION_TYPE: question = EssayQuestion.objects.get(assignment=assignment, question_id=question_id) submission = EssaySubmission.objects.get(submission_id=submission_id) # Defensive Code if question is None: response_data = {"status": "failed", "message": "cannot find question at id " + question_id} return HttpResponse(json.dumps(response_data), content_type="application/json") if submission is None: response_data = {"status": "failed", "message": "cannot find submission"} return HttpResponse(json.dumps(response_data), content_type="application/json") form = PeerReviewForm(request.POST, request.FILES) if form.is_valid(): # Save the peer review form.instance.user = request.user form.save() # Save the peer review to the submission submission.reviews.add(form.instance) # Indicate success response_data = {"status": "success", "message": "submitted"} else: response_data = {"status": "failed", "message": json.dumps(form.errors)} return HttpResponse(json.dumps(response_data), content_type="application/json")
def peer_review_modal(request, course_id, submission_id): response_data = {} if request.is_ajax(): if request.method == 'POST': form = PeerReviewForm() # Check to see if any fields where missing from the form. return render( request, 'course/peer_review/review_modal.html', { 'question_id': request.POST['question_id'], 'question_type': request.POST['question_type'], 'submission_id': request.POST['submission_id'], 'form': form, 'user': request.user, })
def peer_review_modal(request, publication_id): response_data = {'status' : 'failed', 'message' : 'unknown error with deleting'} if request.is_ajax(): if request.method == 'POST': try: publication = Publication.objects.get(publication_id=publication_id) except Publication.DoesNotExist: publication = None form = PeerReviewForm() return render(request, 'publisher/publication/modal.html',{ 'publication': publication, 'form': form, 'user': request.user, 'tab': 'publisher_catalog', })
def peer_review_modal(request, course_id, assignment_id): response_data = {} if request.is_ajax(): if request.method == 'POST': form = PeerReviewForm() # Check to see if any fields where missing from the form. return render(request, 'teacher/peer_review/review_modal.html',{ 'question_id': request.POST['question_id'], 'question_type': request.POST['question_type'], 'submission_id': request.POST['submission_id'], 'form': form, 'user': request.user, 'local_css_urls': settings.SB_ADMIN_2_CSS_LIBRARY_URLS, 'local_js_urls': settings.SB_ADMIN_2_JS_LIBRARY_URLS, })