Example #1
0
File: views.py Project: NateWr/rua
def reviewer_decision(request, review_type, submission_id, review_assignment, decision=None,access_key=None):

	# Check the review assignment as not been completed and is being accessed by the assigned user
	submission = get_object_or_404(core_models.Book, pk=submission_id)
	if access_key:
		review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,pk=review_assignment, declined__isnull=True, review_type=review_type)
	else:
		review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=request.user), Q(book=submission),Q(pk=review_assignment), Q(declined__isnull=True), Q(review_type=review_type),Q(access_key__isnull=True) | Q(access_key__exact=''))
	#
	editors = logic.get_editors(review_assignment)


	if decision and decision == 'accept':
		review_assignment.accepted = timezone.now()
		message = "Review Assignment request for '%s' has been accepted by %s %s."  % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name)
		log.add_log_entry(book=submission, user=request.user, kind='review', message=message, short_name='Assignment accepted')
		logic.notify_editors(submission,message,editors,request.user,'review')
		
	elif decision and decision == 'decline':
		review_assignment.declined = timezone.now()
		message = "Review Assignment request for '%s' has been declined by %s %s."  % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name)
		logic.notify_editors(submission,message,editors,request.user,'review')
			
		log.add_log_entry(book=submission, user=request.user, kind='review', message=message, short_name='Assignment declined')


	# If we didn't get a decision above, offer the user a choice.
	if request.POST:
		if 'accept' in request.POST:
			review_assignment.accepted = timezone.now()
			message = "Review Assignment request for '%s' has been accepted by %s %s."  % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name)
			log.add_log_entry(book=submission, user=request.user, kind='review', message=message, short_name='Assignment accepted')
			logic.notify_editors(submission,message,editors,request.user,'review')
				
		elif 'decline' in request.POST:
			review_assignment.declined = timezone.now()
			message = "Review Assignment request for '%s' has been declined by %s %s."  % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name)
			logic.notify_editors(submission,message,editors,request.user,'review')
			log.add_log_entry(book=submission, user=request.user, kind='review', message=message, short_name='Assignment declined')


	if request.POST or decision:
		review_assignment.save()
		if review_assignment.accepted:
			if access_key:
				return redirect(reverse('review_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_assignment.review_round.round_number}))
			else:
				return redirect(reverse('review_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_assignment.review_round.round_number}))
		elif review_assignment.declined:
			return redirect(reverse('reviewer_dashboard'))

	template = 'review/reviewer_decision.html'
	context = {
		'submission': submission,
		'review_assignment': review_assignment,
		'has_additional_files': logic.has_additional_files(submission),
		'editors': editors
	}

	return render(request, template, context)
Example #2
0
File: views.py Project: StuJ/rua
def reviewer_decision(request, review_type, submission_id, review_assignment_id, decision=None, access_key=None):

	# Check the review assignment as not been completed and is being accessed by the assigned user
	review_assignment = None

	submission = get_object_or_404(core_models.Book, pk=submission_id)
	one_click_no_login = core_models.Setting.objects.filter(name = 'one_click_review_url')
	if one_click_no_login:
		if one_click_no_login[0].value == 'on':
			if access_key:
				review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,pk=review_assignment_id, declined__isnull=True, review_type=review_type, withdrawn = False)
				user = review_assignment.user
			else:
				if request.user.is_authenticated():
					review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=request.user), Q(book=submission),Q(pk=review_assignment_id), Q(declined__isnull=True), Q(review_type=review_type),Q(withdrawn = False),Q(access_key__isnull=True) | Q(access_key__exact=''))
					user = request.user
				else:
					raise Http404
		else:
			if access_key:
				review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,pk=review_assignment_id, declined__isnull=True, review_type=review_type, withdrawn = False)
				user = review_assignment.user
			elif request.user.is_authenticated():
				review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=request.user), Q(book=submission),Q(pk=review_assignment_id), Q(declined__isnull=True), Q(review_type=review_type),Q(withdrawn = False),Q(access_key__isnull=True) | Q(access_key__exact=''))
				user = request.user
			else:
				raise Http404
	else:
		user = request.user
		if access_key:
			review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,pk=review_assignment_id, declined__isnull=True, review_type=review_type, withdrawn = False)
		else:
			review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=user), Q(book=submission),Q(pk=review_assignment_id), Q(declined__isnull=True), Q(review_type=review_type),Q(withdrawn = False),Q(access_key__isnull=True) | Q(access_key__exact=''))
	
	
	if review_assignment:
		editors = logic.get_editors(review_assignment)
	else:
		editors = None

	if review_assignment.accepted:
		if access_key:
			return redirect(reverse('review_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_assignment.review_round.round_number}))
		else:
			return redirect(reverse('review_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_assignment.review_round.round_number}))
	elif review_assignment.declined:
		return redirect(reverse('reviewer_dashboard'))

	if decision and decision == 'accept':
		review_assignment.accepted = timezone.now()
		message = "Review Assignment request for '%s' has been accepted by %s %s."  % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name)
		log.add_log_entry(book=submission, user=user, kind='review', message=message, short_name='Assignment accepted')
		logic.notify_editors(submission,message,editors,user,'review')
		
	elif decision and decision == 'decline':
		review_assignment.declined = timezone.now()
		message = "Review Assignment request for '%s' has been declined by %s %s."  % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name)
		logic.notify_editors(submission,message,editors,user,'review')
			
		log.add_log_entry(book=submission, user=user, kind='review', message=message, short_name='Assignment declined')


	# If we didn't get a decision above, offer the user a choice.
	if request.POST:
		if 'accept' in request.POST:
			review_assignment.accepted = timezone.now()
			message = "Review Assignment request for '%s' has been accepted by %s %s."  % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name)
			log.add_log_entry(book=submission, user=user, kind='review', message=message, short_name='Assignment accepted')
			logic.notify_editors(submission,message,editors,user,'review')
				
		elif 'decline' in request.POST:
			review_assignment.declined = timezone.now()
			message = "Review Assignment request for '%s' has been declined by %s %s."  % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name)
			logic.notify_editors(submission,message,editors,user,'review')
			log.add_log_entry(book=submission, user=user, kind='review', message=message, short_name='Assignment declined')


	if request.POST or decision:
		review_assignment.save()
		if review_assignment.accepted:
			if access_key:
				return redirect(reverse('review_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_assignment.review_round.round_number}))
			else:
				return redirect(reverse('review_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_assignment.review_round.round_number}))
		elif review_assignment.declined:
			return redirect(reverse('reviewer_dashboard'))

	template = 'review/reviewer_decision.html'
	context = {
		'submission': submission,
		'review_assignment': review_assignment,
		'has_additional_files': logic.has_additional_files(submission),
		'editors': editors,
		'file_preview': core_models.Setting.objects.get(group__name='general', name='preview_review_files').value,
		'instructions': core_models.Setting.objects.get(group__name='general', name='instructions_for_task_review').value

	}

	return render(request, template, context)
Example #3
0
File: views.py Project: StuJ/rua
def review(request, review_type, submission_id, review_round, access_key=None):

	ci_required = core_models.Setting.objects.get(group__name='general', name='ci_required')
	one_click_no_login = core_models.Setting.objects.filter(name = 'one_click_review_url')
	if one_click_no_login:
		if one_click_no_login[0].value == 'on':
			if access_key:
				review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,review_round__round_number=review_round, declined__isnull=True, review_type=review_type, withdrawn = False)
				submission = get_object_or_404(core_models.Book, pk=submission_id)
				user = review_assignment.user
				if review_assignment.completed and not review_assignment.reopened:
					return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_round}))
			else:
				raise Http404
		else:
			user = request.user
			if access_key:
				review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,review_round__round_number=review_round, declined__isnull=True, review_type=review_type, withdrawn = False)
				submission = get_object_or_404(core_models.Book, pk=submission_id)
				if review_assignment.completed and not review_assignment.reopened:
					return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_round}))
			elif review_type == 'proposal':
				submission = get_object_or_404(submission_models.Proposal, pk=submission_id)
				review_assignment = get_object_or_404(submission_models.ProposalReview, user=user, proposal=submission, completed__isnull=True, declined__isnull=True, withdrawn = False)
			else:
				submission = get_object_or_404(core_models.Book, pk=submission_id)
				review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=user), Q(book=submission),Q(review_round__round_number=review_round), Q(declined__isnull=True), Q(review_type=review_type),Q(withdrawn = False),Q(access_key__isnull=True) | Q(access_key__exact=''))
				if review_assignment.completed and not review_assignment.reopened:
					return redirect(reverse('review_complete', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_round}))


	else:
		user = request.user
		if access_key:
			review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,review_round__round_number=review_round, declined__isnull=True, review_type=review_type, withdrawn = False)
			submission = get_object_or_404(core_models.Book, pk=submission_id)
			if review_assignment.completed and not review_assignment.reopened:
				return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_round}))
		elif review_type == 'proposal':
			submission = get_object_or_404(submission_models.Proposal, pk=submission_id)
			review_assignment = get_object_or_404(submission_models.ProposalReview, user=user, proposal=submission, completed__isnull=True, declined__isnull=True, withdrawn = False)
		else:
			submission = get_object_or_404(core_models.Book, pk=submission_id)
			review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=user), Q(book=submission),Q(review_round__round_number=review_round), Q(declined__isnull=True), Q(review_type=review_type),Q(withdrawn = False),Q(access_key__isnull=True) | Q(access_key__exact=''))
			if review_assignment.completed and not review_assignment.reopened:
				return redirect(reverse('review_complete', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_round}))
	
	# Check that this review is being access by the user, is not completed and has not been declined.
					
	if review_assignment:
		if not review_assignment.accepted and not review_assignment.declined:
			if access_key:
				return redirect(reverse('reviewer_decision_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_assignment_id':review_assignment.pk}))
			else:
				return redirect(reverse('reviewer_decision_without', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_assignment_id':review_assignment.pk}))
	
	editors = logic.get_editors(review_assignment)
	if review_assignment.review_form:
		form = forms.GeneratedForm(form=review_assignment.review_form)
	else:
		review_assignment.review_form = submission.review_form
		review_assignment.save()
		form = forms.GeneratedForm(form=submission.review_form)

	if review_assignment.reopened:
		result = review_assignment.results
		if result:
			initial_data = {}
			data = json.loads(result.data)
			for k,v in data.items():
				initial_data[k] = v[0]
			form.initial = initial_data
	
	recommendation_form = core_forms.RecommendationForm(ci_required=ci_required.value)
	
	if review_assignment.reopened:
		initial_data = {}
		initial_data[u'recommendation']=review_assignment.recommendation
		initial_data[u'competing_interests']=review_assignment.competing_interests
		recommendation_form.initial=initial_data
			
	if not request.POST and request.GET.get('download') == 'docx':
		path = create_completed_review_form(submission, review_assignment.pk)
		return serve_file(request, path)
	elif request.POST:
		form = forms.GeneratedForm(request.POST, request.FILES, form=review_assignment.review_form)
		recommendation_form = core_forms.RecommendationForm(request.POST, ci_required=ci_required.value)
		if form.is_valid() and recommendation_form.is_valid():
			save_dict = {}
			file_fields = models.FormElementsRelationship.objects.filter(form=review_assignment.review_form, element__field_type='upload')
			data_fields = models.FormElementsRelationship.objects.filter(~Q(element__field_type='upload'), form=review_assignment.review_form)

			for field in file_fields:
				if field.element.name in request.FILES:
					# TODO change value from string to list [value, value_type]
					save_dict[field.element.name] = [handle_review_file(request.FILES[field.element.name], submission, review_assignment, 'reviewer')]

			for field in data_fields:
				if field.element.name in request.POST:
					# TODO change value from string to list [value, value_type]
					save_dict[field.element.name] = [request.POST.get(field.element.name), 'text']

			json_data = smart_text(json.dumps(save_dict))
			if review_assignment.reopened:
				if review_assignment.results:
					review_assignment.results.data = json_data
					review_assignment.results.save()
					review_assignment.reopened=False
					review_assignment.save()
				else:
					form_results = models.FormResult(form=review_assignment.review_form, data=json_data)
					form_results.save()
					review_assignment.results = form_results
					review_assignment.reopened=False
					review_assignment.save()
			else:
				form_results = models.FormResult(form=review_assignment.review_form, data=json_data)
				form_results.save()
				review_assignment.results = form_results
				review_assignment.save()

			if request.FILES.get('review_file_upload'):
				handle_review_file(request.FILES.get('review_file_upload'), submission, review_assignment, 'reviewer')

			review_assignment.completed = timezone.now()
			if not review_assignment.accepted:
				review_assignment.accepted = timezone.now()
			review_assignment.recommendation = request.POST.get('recommendation')
			review_assignment.competing_interests = request.POST.get('competing_interests')
			
			review_assignment.save()
			message = "%s Review assignment with id %s has been completed by %s ."  % (review_assignment.review_type.title(),review_assignment.id,review_assignment.user.profile.full_name())
			press_editors = User.objects.filter(profile__roles__slug='press-editor')
			for editor in press_editors:
				notification = core_models.Task(assignee=editor,creator=user,text=message,workflow='review', book = submission)
				notification.save()
				print "notify"
			if not review_type == 'proposal':
				log.add_log_entry(book=submission, user=user, kind='review', message='Reviewer %s %s completed review for %s.' % (review_assignment.user.first_name, review_assignment.user.last_name, submission.title), short_name='Assignment Completed')
				
				message = "Reviewer %s %s has completed a review for '%s'."  % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name)
				logic.notify_editors(submission,message,editors,user,'review')
			if access_key:
				return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.id,'access_key':access_key,'review_round':review_round}))
			else:
				return redirect(reverse('review_complete', kwargs={'review_type': review_type, 'submission_id': submission.id,'review_round':review_round}))


	template = 'review/review.html'
	context = {
		'review_assignment': review_assignment,
		'submission': submission,
		'form': form,
		'form_info': review_assignment.review_form,
		'recommendation_form': recommendation_form,
		'editors':editors,
		'has_additional_files': logic.has_additional_files(submission),
		'instructions': core_models.Setting.objects.get(group__name='general', name='instructions_for_task_review').value

	}

	return render(request, template, context)
Example #4
0
File: views.py Project: NateWr/rua
def review(request, review_type, submission_id,review_round, access_key=None):

	ci_required = core_models.Setting.objects.get(group__name='general', name='ci_required')

	# Check that this review is being access by the user, is not completed and has not been declined.
	if access_key:
		review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,review_round__round_number=review_round, declined__isnull=True, review_type=review_type)
		submission = get_object_or_404(core_models.Book, pk=submission_id)
		if review_assignment.completed:
			return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_round}))
	
	elif review_type == 'proposal':
		submission = get_object_or_404(submission_models.Proposal, pk=submission_id)
		review_assignment = get_object_or_404(submission_models.ProposalReview, user=request.user, proposal=submission, completed__isnull=True, declined__isnull=True)
	else:
		submission = get_object_or_404(core_models.Book, pk=submission_id)
		review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=request.user), Q(book=submission),Q(review_round__round_number=review_round), Q(declined__isnull=True), Q(review_type=review_type),Q(access_key__isnull=True) | Q(access_key__exact=''))
		if review_assignment.completed:
			return redirect(reverse('review_complete', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_round}))
	
	if review_assignment:
		if not review_assignment.accepted and not review_assignment.declined:
			if access_key:
				return redirect(reverse('reviewer_decision_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_assignment':review_assignment.pk}))
			else:
				return redirect(reverse('reviewer_decision_without', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_assignment':review_assignment.pk}))
	
	editors = logic.get_editors(review_assignment)
		
	form = forms.GeneratedForm(form=submission.review_form)
	recommendation_form = core_forms.RecommendationForm(ci_required=ci_required.value)
	
	if not request.POST and request.GET.get('download') == 'docx':
		path = create_review_form(submission)
		return serve_file(request, path)
	elif request.POST:
		form = forms.GeneratedForm(request.POST, request.FILES, form=submission.review_form)
		recommendation_form = core_forms.RecommendationForm(request.POST, ci_required=ci_required.value)
		if form.is_valid() and recommendation_form.is_valid():
			save_dict = {}
			file_fields = models.FormElementsRelationship.objects.filter(form=submission.review_form, element__field_type='upload')
			data_fields = models.FormElementsRelationship.objects.filter(~Q(element__field_type='upload'), form=submission.review_form)

			for field in file_fields:
				if field.element.name in request.FILES:
					# TODO change value from string to list [value, value_type]
					save_dict[field.element.name] = [handle_review_file(request.FILES[field.element.name], submission, review_assignment, 'reviewer')]

			for field in data_fields:
				if field.element.name in request.POST:
					# TODO change value from string to list [value, value_type]
					save_dict[field.element.name] = [request.POST.get(field.element.name), 'text']

			json_data = json.dumps(save_dict)
			form_results = models.FormResult(form=submission.review_form, data=json_data)
			form_results.save()

			if request.FILES.get('review_file_upload'):
				handle_review_file(request.FILES.get('review_file_upload'), submission, review_assignment, 'reviewer')

			review_assignment.completed = timezone.now()
			if not review_assignment.accepted:
				review_assignment.accepted = timezone.now()
			review_assignment.recommendation = request.POST.get('recommendation')
			review_assignment.competing_interests = request.POST.get('competing_interests')
			review_assignment.results = form_results
			review_assignment.save()

			if not review_type == 'proposal':
				log.add_log_entry(book=submission, user=request.user, kind='review', message='Reviewer %s %s completed review for %s.' % (review_assignment.user.first_name, review_assignment.user.last_name, submission.title), short_name='Assignment Completed')
				
				message = "Reviewer %s %s has completed a review for '%s'."  % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name)
				logic.notify_editors(submission,message,editors,request.user,'review')
			if access_key:
				return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.id,'access_key':access_key,'review_round':review_round}))
			else:
				return redirect(reverse('review_complete', kwargs={'review_type': review_type, 'submission_id': submission.id,'review_round':review_round}))


	template = 'review/review.html'
	context = {
		'review_assignment': review_assignment,
		'submission': submission,
		'form': form,
		'form_info': submission.review_form,
		'recommendation_form': recommendation_form,
		'editors':editors,
		'has_additional_files': logic.has_additional_files(submission),

	}

	return render(request, template, context)