author | Madhusudan.C.S <madhusudancs@gmail.com> |
Fri, 07 Aug 2009 03:04:57 +0530 | |
changeset 13 | 684540719344 |
parent 12 | aac4944aca52 |
child 14 | 9d720dfded68 |
permissions | -rw-r--r-- |
0 | 1 |
"""This module contains the views for the project's proposal |
2 |
funded by NME through ICT. |
|
3 |
""" |
|
4 |
||
5 |
||
6 |
__authors__ = [ |
|
7 |
'"Madhusudan.C.S" <madhusudancs@gmail.com>', |
|
8 |
] |
|
9 |
||
10 |
||
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
11 |
import os |
0 | 12 |
import time |
13 |
||
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
14 |
from django.core.urlresolvers import reverse |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
15 |
from django.http import HttpResponseRedirect |
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
6
diff
changeset
|
16 |
from django.shortcuts import render_to_response |
6 | 17 |
from django.template import RequestContext |
0 | 18 |
|
19 |
from projrev.models import Project |
|
20 |
from projrev.models import Proposal |
|
5
88ae12bc6280
Access check helper file added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
4
diff
changeset
|
21 |
from projrev.views.helpers import access |
0 | 22 |
from projrev.views.helpers import forms as projrev_forms |
23 |
||
5
88ae12bc6280
Access check helper file added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
4
diff
changeset
|
24 |
|
12 | 25 |
@access.register('proposer') |
6 | 26 |
@access.checkAccess |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
27 |
def getMicr(request): |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
28 |
"""View to get MICR Code from the user. |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
29 |
""" |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
30 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
31 |
if request.method == 'POST': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
32 |
post_params = request.POST |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
33 |
submit = post_params.get('submit') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
34 |
if submit == 'New Proposal': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
35 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
36 |
reverse('app.projrev.views.proposal.submit')) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
37 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
38 |
micr_code = request.POST.get('micr_code') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
39 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
40 |
try: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
41 |
Project.objects.get(micr_code=micr_code) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
42 |
except Project.DoesNotExist: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
43 |
if (submit == 'Edit Proposal for MICR Code' or |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
44 |
submit == 'Withdraw Proposal for MICR Code'): |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
45 |
template = 'projrev/proposal/get_micr.html' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
46 |
context = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
47 |
'error': True, |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
48 |
} |
6 | 49 |
return render_to_response(template, |
50 |
RequestContext(request, context)) |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
51 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
52 |
if submit == 'Edit Proposal for MICR Code': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
53 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
54 |
reverse('app.projrev.views.proposal.submit', |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
55 |
args=(micr_code, ))) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
56 |
elif submit == 'Withdraw Proposal for MICR Code': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
57 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
58 |
reverse('app.projrev.views.proposal.withdraw', |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
59 |
args=(micr_code, ))) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
60 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
61 |
template = 'projrev/proposal/get_micr.html' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
62 |
context = {} |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
63 |
|
6 | 64 |
return render_to_response(template, RequestContext(request, context)) |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
65 |
|
12 | 66 |
@access.register('proposer') |
6 | 67 |
@access.checkAccess |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
68 |
def submit(request, micr_code=None): |
0 | 69 |
"""View for proposal submission. |
70 |
""" |
|
71 |
||
72 |
if request.method == 'POST': |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
73 |
return submitPost(request, micr_code) |
0 | 74 |
else: |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
75 |
return submitGet(request, micr_code) |
0 | 76 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
77 |
def submitPost(request, micr_code=None): |
0 | 78 |
"""Handles POST request for the submitted proposal form. |
79 |
""" |
|
80 |
||
81 |
prop_form = projrev_forms.ProposalForm(request.POST, request.FILES) |
|
82 |
||
83 |
project = None |
|
84 |
proposal = None |
|
85 |
||
86 |
if prop_form.is_valid(): |
|
87 |
cleaned_data = prop_form.cleaned_data |
|
88 |
||
13 | 89 |
if micr_code: |
90 |
project = Project.objects.get(micr_code=micr_code) |
|
91 |
project.line_item = Project.getLineItem(cleaned_data['line_item']) |
|
92 |
project.institution = cleaned_data['institution'] |
|
93 |
project.state = Project.getState(cleaned_data['state']) |
|
94 |
project.district = Project.getDistrict(cleaned_data['district']) |
|
95 |
else: |
|
96 |
# Generate MICR code |
|
97 |
cleaned_data['micr_code'] = '%s%s%s%d' % ( |
|
98 |
cleaned_data['state'], cleaned_data['district'], |
|
99 |
cleaned_data['line_item'], |
|
100 |
int(time.time() * 1000) % 1000000000) |
|
0 | 101 |
|
13 | 102 |
cleaned_data['line_item'] = Project.getLineItem(cleaned_data['line_item']) |
103 |
cleaned_data['state'] = Project.getState(cleaned_data['state']) |
|
104 |
cleaned_data['district'] = Project.getDistrict(cleaned_data['district']) |
|
105 |
||
106 |
prop_form.cleaned_data = cleaned_data |
|
0 | 107 |
|
13 | 108 |
# If the form is valid create a new project or update the project |
109 |
# if it already exists from the form. |
|
110 |
project = prop_form.save() |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
111 |
|
13 | 112 |
project.micr_code = cleaned_data['micr_code'] |
0 | 113 |
|
114 |
project.status = 'new' |
|
13 | 115 |
micr_code = project.micr_code |
0 | 116 |
|
117 |
project.save() |
|
118 |
||
13 | 119 |
if prop_form.cleaned_data['document']: |
120 |
# Create a proposal for the project. |
|
121 |
proposal = project.proposal_set.create( |
|
122 |
document=prop_form.cleaned_data['document'], |
|
123 |
submitted_by=request.user, rev_num = 0) |
|
0 | 124 |
|
13 | 125 |
proposal.save() |
0 | 126 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
127 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
128 |
reverse('app.projrev.views.proposal.submit', args=(micr_code,))) |
0 | 129 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
130 |
return HttpResponseRedirect('') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
131 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
132 |
def submitGet(request, micr_code=None): |
0 | 133 |
"""Handles GET request for the submission of proposal form. |
134 |
""" |
|
135 |
||
136 |
context = {} |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
137 |
project = None |
0 | 138 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
139 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
140 |
project = Project.objects.get(micr_code=micr_code) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
141 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
142 |
if project: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
143 |
initial_vals = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
144 |
'line_item': Project.getLineItemCode(project.line_item), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
145 |
'state': Project.getStateCode(project.state), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
146 |
'district': Project.getDistrictCode(project.district), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
147 |
} |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
148 |
prop_form = projrev_forms.ProposalForm( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
149 |
initial=initial_vals, instance=project) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
150 |
|
13 | 151 |
proposal = project.proposal_set.all().order_by('-submitted_on')[0] |
152 |
||
153 |
if proposal: |
|
154 |
proposal_path = str(proposal.document) |
|
0 | 155 |
|
13 | 156 |
proposal_name = proposal_path.split('/')[-1] |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
157 |
|
13 | 158 |
context['proposal_path'] = proposal_path |
159 |
context['proposal_name'] = proposal_name |
|
160 |
context['last_submitted'] = proposal.submitted_on |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
161 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
162 |
if 'HTTP_REFERER' in request.META: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
163 |
referer = request.META['HTTP_REFERER'].split('/') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
164 |
if referer[-1]: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
165 |
ref = referer[-1] |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
166 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
167 |
ref = referer[-2] |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
168 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
169 |
if ref == 'create': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
170 |
context['created_now'] = True |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
171 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
172 |
context['micr_code'] = project.micr_code |
13 | 173 |
|
174 |
reviews = project.review_set.all().order_by('-reviewed_on') |
|
175 |
if reviews: |
|
176 |
context['last_reviewed'] = reviews[0].reviewed_on |
|
177 |
context['nr_reviews'] = len(reviews) |
|
178 |
||
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
179 |
else: |
0 | 180 |
prop_form = projrev_forms.ProposalForm() |
181 |
||
182 |
context['form'] = prop_form |
|
183 |
||
184 |
template = 'projrev/proposal/submit.html' |
|
185 |
||
6 | 186 |
return render_to_response(template, RequestContext(request, context)) |
0 | 187 |
|
12 | 188 |
@access.register('proposer') |
6 | 189 |
@access.checkAccess |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
190 |
def withdraw(request, micr_code=None): |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
191 |
"""View Method for withdrawal of proposal. |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
192 |
""" |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
193 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
194 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
195 |
project = Project.objects.get(micr_code=micr_code) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
196 |
if project: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
197 |
project.status = 'invalid' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
198 |
project.save() |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
199 |
context = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
200 |
'withdrawn': True, |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
201 |
} |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
202 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
203 |
template = 'projrev/proposal/withdraw.html' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
204 |
|
6 | 205 |
return render_to_response(template, RequestContext(request, context)) |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
206 |
|
12 | 207 |
@access.register('reviewer') |
6 | 208 |
@access.checkAccess |
0 | 209 |
def review(request, micr_code=None): |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
210 |
"""View for reviewing the proposal. |
0 | 211 |
""" |
212 |
||
213 |
if request.method == 'POST': |
|
214 |
return reviewPost(request, micr_code) |
|
215 |
else: |
|
216 |
return reviewGet(request, micr_code) |
|
217 |
||
218 |
def reviewPost(request, micr_code=None): |
|
219 |
""" |
|
220 |
""" |
|
221 |
||
222 |
rev_form = projrev_forms.ReviewForm(request.POST) |
|
223 |
||
224 |
if rev_form.is_valid(): |
|
225 |
cleaned_data = rev_form.cleaned_data |
|
226 |
||
227 |
cleaned_data['project'] = Project.objects.get(micr_code=micr_code) |
|
228 |
||
229 |
# If the form is valid create a new project or update the project |
|
230 |
# if it already exists from the form. |
|
231 |
review = rev_form.save() |
|
232 |
||
233 |
return reviewGet(request, micr_code, rev_form) |
|
234 |
||
235 |
def reviewGet(request, micr_code=None, rev_form=None): |
|
236 |
""" |
|
237 |
""" |
|
238 |
||
239 |
if not micr_code: |
|
240 |
template = 'projrev/proposal/list.html' |
|
241 |
context = { |
|
13 | 242 |
'projects': Project.objects.all().exclude(status__exact='invalid'), |
0 | 243 |
'row_url': '/proposal/review/', |
244 |
} |
|
245 |
||
6 | 246 |
return render_to_response(template, RequestContext(request, context)) |
0 | 247 |
|
248 |
if not rev_form: |
|
249 |
rev_form = projrev_forms.ReviewForm() |
|
250 |
||
251 |
proposal_path = str(Project.objects.get( |
|
12 | 252 |
micr_code=micr_code).proposal_set.all().order_by( |
253 |
'-submitted_on')[0].document) |
|
0 | 254 |
|
255 |
proposal_name = proposal_path.split('/')[-1] |
|
256 |
||
257 |
context = { |
|
258 |
'form': rev_form, |
|
259 |
'project': Project.objects.get(micr_code=micr_code), |
|
260 |
'proposal_path': proposal_path, |
|
261 |
'proposal_name': proposal_name, |
|
262 |
} |
|
263 |
||
264 |
template = 'projrev/proposal/review.html' |
|
265 |
||
6 | 266 |
return render_to_response(template, RequestContext(request, context)) |
0 | 267 |
|
12 | 268 |
@access.register('reviewer') |
6 | 269 |
@access.checkAccess |
0 | 270 |
def rank(request, micr_code=None): |
271 |
""" |
|
272 |
""" |
|
273 |
||
274 |
if request.method == 'POST': |
|
275 |
return rankPost(request, micr_code) |
|
276 |
else: |
|
277 |
return rankGet(request, micr_code) |
|
278 |
||
279 |
def rankPost(request, micr_code=None): |
|
280 |
""" |
|
281 |
""" |
|
282 |
||
283 |
return rankGet(request, micr_code) |
|
284 |
||
285 |
def rankGet(request, micr_code=None): |
|
286 |
""" |
|
287 |
""" |
|
288 |
||
289 |
if not micr_code: |
|
290 |
template = 'projrev/proposal/list.html' |
|
291 |
context = { |
|
292 |
'projects': Project.objects.all(), |
|
293 |
'row_url': '/proposal/rank/', |
|
294 |
} |
|
295 |
||
6 | 296 |
return render_to_response(template, RequestContext(request, context)) |
0 | 297 |
|
298 |
projects = Project.objects.get(micr_code=micr_code) |
|
299 |
||
12 | 300 |
proposal_path = str( |
301 |
projects.proposal_set.all().order_by('-submitted_on')[0].document) |
|
0 | 302 |
|
303 |
proposal_name = proposal_path.split('/')[-1] |
|
304 |
||
305 |
reviews = projects.review_set.all() |
|
306 |
||
307 |
review_score = [0] * 9 |
|
308 |
for review in reviews: |
|
309 |
review_score[0] += review.attribute1 |
|
310 |
review_score[1] += review.attribute2 |
|
311 |
review_score[2] += review.attribute3 |
|
312 |
review_score[3] += review.attribute4 |
|
313 |
review_score[4] += review.attribute5 |
|
314 |
review_score[5] += review.attribute6 |
|
315 |
review_score[6] += review.attribute7 |
|
316 |
review_score[7] += review.attribute8 |
|
317 |
review_score[8] += review.attribute9 |
|
318 |
||
319 |
total_score = sum(review_score) |
|
320 |
||
321 |
context = { |
|
322 |
'project': projects, |
|
323 |
'proposal_path': proposal_path, |
|
324 |
'proposal_name': proposal_name, |
|
325 |
'review_score': review_score, |
|
326 |
'total_score': total_score, |
|
327 |
} |
|
328 |
||
329 |
template = 'projrev/proposal/rank.html' |
|
330 |
||
6 | 331 |
return render_to_response(template, RequestContext(request, context)) |