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