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