File size: 2,671 Bytes
7a71a69 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | # Create your views here.
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from permissions.utils import has_permission
from workflows.utils import do_transition
from django.shortcuts import get_object_or_404
from django.core.exceptions import PermissionDenied
from ethicsapplication.models import EthicsApplication
from review.models import Committee
from django.contrib.auth.decorators import login_required
from review.signals import application_submitted_for_review,\
application_accepted_by_reviewer, application_rejected_by_reviewer
def submit_for_review(request, ethics_application_id):
'''
This view will ascertain if the submit_for_review transition can be
carried out on the specified ethicsApplication, by the logged in user.
If any of the following goes wrong then a forbidden exception will be raised:
1.User is not logged in
2.User does not have the submit permission for this application
3.The transition is not allowed
'''
ethics_application = get_object_or_404(EthicsApplication, pk=ethics_application_id)
if not request.user.is_authenticated() or not has_permission(ethics_application, request.user, 'submit') or not do_transition(ethics_application, 'submit_for_review', request.user):
raise PermissionDenied()
reviewer = Committee.objects.get_next_free_reviewer()
ethics_application.assign_reviewer(reviewer)
application_submitted_for_review.send(None, application=ethics_application, reviewer=reviewer)
return HttpResponseRedirect(reverse('index_view'))
@login_required
def evaluate_application_form(request, ethics_application_id, approved=False):
'''
This view will attempt to transition the ethics application to the
correct state depending on whether the approved flag is True, in which
case it will have the Approved trnsition applied, otherwise it will have the
reject transition applied. All of this is dependent on the requesting user having
the appropriate permissions to perform these transitions.
'''
ethics_application = get_object_or_404(EthicsApplication, pk=ethics_application_id)
if approved:
transition = 'approve'
signal = application_accepted_by_reviewer
else:
transition = 'reject'
signal = application_rejected_by_reviewer
if not do_transition(ethics_application, transition, request.user):
raise PermissionDenied()
signal.send(None, application=ethics_application, reviewer=request.user)
return HttpResponseRedirect(reverse('index_view'))
|