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