Exemplo n.º 1
0
Arquivo: views.py Projeto: 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)
Exemplo n.º 2
0
Arquivo: views.py Projeto: StuJ/rua
def editorial_review_complete(request, submission_id, access_key):

	review_assignment = get_object_or_404(core_models.EditorialReviewAssignment, Q(publishing_committee_access_key = access_key) |  Q(editorial_board_access_key = access_key))
	submission = get_object_or_404(core_models.Book, pk=submission_id)
	
	if access_key  == review_assignment.editorial_board_access_key:
		editorial_board = True
		result = review_assignment.editorial_board_results
		review_form = review_assignment.editorial_board_review_form
	elif access_key  == review_assignment.publishing_committee_access_key:
		editorial_board = False
		result = review_assignment.publication_committee_results
		review_form = review_assignment.publication_committee_review_form

	
	if not result and not editorial_board:
		return redirect(reverse('editorial_review', kwargs={'submission_id': submission.id,'access_key':review_assignment.publishing_committee_access_key}))
	elif not result and editorial_board:
		return redirect(reverse('editorial_review', kwargs={'submission_id': submission.id,'access_key':review_assignment.editorial_board_access_key}))
	
	elif review_assignment.completed and review_assignment.reopened:
		if editorial_board:
			return redirect(reverse('editorial_review_complete', kwargs={'submission_id': submission.id,'access_key':review_assignment.publishing_committee_access_key}))
		else: 
			return redirect(reverse('editorial_review_complete', kwargs={'submission_id': submission.id,'access_key':review_assignment.editorial_board_access_key}))
	
	relations = models.FormElementsRelationship.objects.filter(form=result.form)
	data_ordered = core_logic.order_data(core_logic.decode_json(result.data), relations)

	template = 'review/editorial_complete.html'
	context = {
		'submission': submission,
		'review_assignment': review_assignment,
		'form_info': review_form,
		'data_ordered': data_ordered,
		'result': result,
		'editorial_board':editorial_board,
		'additional_files': logic.has_additional_files(submission),
		'editors': logic.get_editors(review_assignment),
		'instructions': core_models.Setting.objects.get(group__name='general', name='instructions_for_task_review').value
	}

	return render(request,template, context)
Exemplo n.º 3
0
Arquivo: views.py Projeto: StuJ/rua
def review_complete_no_redirect(request, review_type, submission_id,review_round,access_key=None):
	user = request.user
	if access_key:
		review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key, results__isnull=False, declined__isnull=True, review_type=review_type, review_round=review_round, withdrawn = False)
		submission = get_object_or_404(core_models.Book, pk=submission_id)
	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, results__isnull=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(results__isnull=False), Q(review_round__round_number=review_round), Q(book=submission), Q(withdrawn = False), Q(review_type=review_type), Q(access_key__isnull=True) | Q(access_key__exact=''))

	
	result = review_assignment.results

	if not request.POST and request.GET.get('download') == 'docx':
		path = create_completed_review_form(submission, review_assignment.pk)
		return serve_file(request, path)
	
	relations = models.FormElementsRelationship.objects.filter(form=result.form)
	data_ordered = core_logic.order_data(core_logic.decode_json(result.data), relations)

	if not review_assignment.review_form:
		review_assignment.review_form = submission.review_form
		review_assignment.save()

	template = 'review/complete.html'
	context = {
		'submission': submission,
		'review_assignment': review_assignment,
		'form_info': review_assignment.review_form,
		'data_ordered': data_ordered,
		'result': result,
		'additional_files': logic.has_additional_files(submission),
		'editors': logic.get_editors(review_assignment),
		'instructions': core_models.Setting.objects.get(group__name='general', name='instructions_for_task_review').value
	}

	return render(request,template, context)
Exemplo n.º 4
0
Arquivo: views.py Projeto: NateWr/rua
def review_complete(request, review_type, submission_id,review_round,access_key=None):

	if access_key:
		review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key, declined__isnull=True, review_type=review_type)
		submission = get_object_or_404(core_models.Book, pk=submission_id)
	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)
	else:
		submission = get_object_or_404(core_models.Book, pk=submission_id)
	 	review_assignment = get_object_or_404(core_models.ReviewAssignment, user=request.user, book=submission, review_type=review_type, access_key="")

	
	result = review_assignment.results
	if not result or not review_assignment.completed:
		if not result:
			review_assignment.completed=None
			review_assignment.save()
		if access_key:
			return redirect(reverse('review_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_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.id,'review_round':review_round}))

	relations = models.FormElementsRelationship.objects.filter(form=result.form)
	data_ordered = core_logic.order_data(core_logic.decode_json(result.data), relations)

	template = 'review/complete.html'
	context = {
		'submission': submission,
		'review_assignment': review_assignment,
		'form_info': submission.review_form,
		'data_ordered': data_ordered,
		'result': result,
		'additional_files': logic.has_additional_files(submission),
		'editors': logic.get_editors(review_assignment)
	}

	return render(request,template, context)
Exemplo n.º 5
0
Arquivo: views.py Projeto: 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)
Exemplo n.º 6
0
Arquivo: views.py Projeto: StuJ/rua
def editorial_review(request, submission_id, access_key):

	ci_required = core_models.Setting.objects.get(group__name='general', name='ci_required')
	print uuid4()
	# Check that this review is being access by the user, is not completed and has not been declined.
	review_assignment = get_object_or_404(core_models.EditorialReviewAssignment, Q(publishing_committee_access_key = access_key) |  Q(editorial_board_access_key = access_key))
	submission = get_object_or_404(core_models.Book, pk=submission_id)
	
	if review_assignment.completed and not review_assignment.reopened:
		return redirect(reverse('editorial_review_complete', kwargs={'submission_id': submission.pk,'access_key':access_key}))
	editorial_board = False
	
	if access_key  == review_assignment.editorial_board_access_key:
		editorial_board = True
	elif access_key  == review_assignment.publishing_committee_access_key:
		editorial_board = False

	resubmit = True
	editors = logic.get_editors(review_assignment)
	form_info = None
	if editorial_board:
		editorial_result = None
		editorial_relations = None
		editorial_data_ordered = None

		form_info = review_assignment.editorial_board_review_form
		form = forms.GeneratedForm(form=review_assignment.editorial_board_review_form)
	else:
		editorial_result = review_assignment.editorial_board_results
		editorial_relations = models.FormElementsRelationship.objects.filter(form=editorial_result.form)
		editorial_data_ordered = core_logic.order_data(core_logic.decode_json(editorial_result.data), editorial_relations)

		if not review_assignment.publication_committee_review_form:
			form_info = review_assignment.editorial_board_review_form
			form = forms.GeneratedForm(form=review_assignment.editorial_board_review_form)
		else:
			form_info = review_assignment.publication_committee_review_form
			form = forms.GeneratedForm(form=review_assignment.publication_committee_review_form)
	
	if editorial_board:
		result = review_assignment.editorial_board_results
		if result and not review_assignment.editorial_board_passed:
			initial_data = {}
			data = json.loads(result.data)
			for k,v in data.items():
				initial_data[k] = v[0]
			form.initial = initial_data
		elif not result:
			resubmit = True
		elif result and review_assignment.editorial_board_passed:
			resubmit = False
	else:
		result = review_assignment.publication_committee_results
		if result and not review_assignment.publication_committee_passed:
			initial_data = {}
			data = json.loads(result.data)
			for k,v in data.items():
				initial_data[k] = v[0]
			form.initial = initial_data
		elif not result:
			resubmit = True
		elif result and review_assignment.publication_committee_passed:
			resubmit = False

	recommendation_form = core_forms.RecommendationForm(ci_required=ci_required.value)
	
	initial_data = {}
	if editorial_board and not review_assignment.editorial_board_passed:
		initial_data[u'recommendation']=review_assignment.editorial_board_recommendation
		initial_data[u'competing_interests']=review_assignment.editorial_board_competing_interests
	elif not editorial_board and not review_assignment.publication_committee_passed:
		initial_data[u'recommendation']=review_assignment.publication_committee_recommendation
		initial_data[u'competing_interests']=review_assignment.publication_committee_competing_interests

	recommendation_form.initial=initial_data
			
	if not request.POST and request.GET.get('download') == 'docx':
		if editorial_board:
			path = create_review_form(submission, review_assignment.editorial_board_review_form)
		else:
			path = create_review_form(submission, review_assignment.publication_committee_review_form)

		return serve_file(request, path)
	elif request.POST:
		if editorial_board:
			form = forms.GeneratedForm(request.POST, request.FILES, form=review_assignment.editorial_board_review_form)
		else:
			if not review_assignment.publication_committee_review_form:
				form = forms.GeneratedForm(request.POST, request.FILES, form=review_assignment.editorial_board_review_form)
			else:
				form = forms.GeneratedForm(request.POST, request.FILES, form=review_assignment.publication_committee_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 = {}
			if editorial_board:
				file_fields = models.FormElementsRelationship.objects.filter(form=review_assignment.editorial_board_review_form, element__field_type='upload')
				data_fields = models.FormElementsRelationship.objects.filter(~Q(element__field_type='upload'), form=review_assignment.editorial_board_review_form)
			else:
				if not review_assignment.publication_committee_review_form:
					file_fields = models.FormElementsRelationship.objects.filter(form=review_assignment.editorial_board_review_form, element__field_type='upload')
					data_fields = models.FormElementsRelationship.objects.filter(~Q(element__field_type='upload'), form=review_assignment.editorial_board_review_form)
				else:
					file_fields = models.FormElementsRelationship.objects.filter(form=review_assignment.publication_committee_review_form, element__field_type='upload')
					data_fields = models.FormElementsRelationship.objects.filter(~Q(element__field_type='upload'), form=review_assignment.publication_committee_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_editorial_review_file(request.FILES[field.element.name], submission, review_assignment, 'reviewer',editorial_board)]

			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 editorial_board:
					review_assignment.editorial_board_results.data = json_data
					review_assignment.editorial_board_results.save()
					review_assignment.reopened=False
					review_assignment.save()
				else:
					review_assignment.publication_committee_results.data = json_data
					review_assignment.publication_committee_results.save()
					review_assignment.reopened=False
					review_assignment.save()

			else:
				if editorial_board:
					form_results = models.FormResult(form=review_assignment.editorial_board_review_form, data=json_data)
					form_results.save()
					review_assignment.editorial_board_results = form_results
					review_assignment.save()
				else:
					if not review_assignment.publication_committee_review_form:
						form_results = models.FormResult(form=review_assignment.editorial_board_review_form, data=json_data)
					else:
						form_results = models.FormResult(form=review_assignment.publication_committee_review_form, data=json_data)
					form_results.save()
					review_assignment.publication_committee_results = form_results
					review_assignment.save()


			if request.FILES.get('review_file_upload'):
				handle_editorial_review_file(request.FILES.get('review_file_upload'), submission, review_assignment, 'reviewer',editorial_board)
	
			if editorial_board:
				review_assignment.editorial_board_recommendation = request.POST.get('recommendation')
				review_assignment.editorial_board_competing_interests = request.POST.get('competing_interests')
			else:
				review_assignment.publication_committee_recommendation = request.POST.get('recommendation')
				review_assignment.publication_committee_competing_interests = request.POST.get('competing_interests')

			review_assignment.save()
			message = "Editorial review assignment #%s has been completed."  % (review_assignment.id)
			press_editors = User.objects.filter(profile__roles__slug='press-editor')
			for editor in press_editors:
				notification = core_models.Task(assignee=editor,creator=request.user,text=message,workflow='editorial-review', book = submission, editorial_review = review_assignment)
				notification.save()
				print "notify"
			messages.add_message(request, messages.INFO, 'Submitted successfully')
			if editorial_board:
				return redirect(reverse('editorial_review', kwargs={'submission_id': submission.id,'access_key':review_assignment.editorial_board_access_key}))
			else:
				return redirect(reverse('editorial_review', kwargs={'submission_id': submission.id,'access_key':review_assignment.publishing_committee_access_key}))


	template = 'review/editorial_review.html'
	context = {
		'review_assignment': review_assignment,
		'submission': submission,
		'form': form,
		'editorial_board': editorial_board,
		'form_info': form_info,
		'recommendation_form': recommendation_form,
		'editors':editors,
		'resubmit': resubmit,

		'editorial_data_ordered': editorial_data_ordered,
		'editorial_result': editorial_result,

		'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)
Exemplo n.º 7
0
Arquivo: views.py Projeto: 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)
Exemplo n.º 8
0
Arquivo: views.py Projeto: 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)