author | Madhusudan.C.S <madhusudancs@gmail.com> |
Sun, 09 Aug 2009 12:40:14 +0530 | |
changeset 20 | 327b3f0b73bb |
parent 19 | 0c9bdcfac9f7 |
child 21 | 153db75bb515 |
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 |
|
18
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
114 |
subject = "[Sakshath] MICR Code of the new proposal submitted" |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
115 |
message = """Hi, |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
116 |
We have received a new proposal for National Mission on education from your, |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
117 |
email address "%s", to the http://sakshath.ac.in portal. The MICR Code of the |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
118 |
submitted proposal is: |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
119 |
MICR Code: %s |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
120 |
|
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
121 |
Please remember this code for all future references. |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
122 |
|
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
123 |
|
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
124 |
-- |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
125 |
Regards, |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
126 |
Saksath admin""" % (request.user.username, project.micr_code) |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
127 |
|
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
128 |
request.user.email_user(subject=subject, message=message) |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
129 |
|
0 | 130 |
project.status = 'new' |
13 | 131 |
micr_code = project.micr_code |
0 | 132 |
|
133 |
project.save() |
|
134 |
||
13 | 135 |
if prop_form.cleaned_data['document']: |
136 |
# Create a proposal for the project. |
|
137 |
proposal = project.proposal_set.create( |
|
138 |
document=prop_form.cleaned_data['document'], |
|
139 |
submitted_by=request.user, rev_num = 0) |
|
0 | 140 |
|
13 | 141 |
proposal.save() |
0 | 142 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
143 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
144 |
reverse('app.projrev.views.proposal.submit', args=(micr_code,))) |
0 | 145 |
|
19 | 146 |
return submitGet(request, micr_code, prop_form) |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
147 |
|
19 | 148 |
def submitGet(request, micr_code=None, prop_form=None): |
0 | 149 |
"""Handles GET request for the submission of proposal form. |
150 |
""" |
|
151 |
||
152 |
context = {} |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
153 |
project = None |
0 | 154 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
155 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
156 |
project = Project.objects.get(micr_code=micr_code) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
157 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
158 |
if project: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
159 |
initial_vals = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
160 |
'line_item': Project.getLineItemCode(project.line_item), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
161 |
'state': Project.getStateCode(project.state), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
162 |
'district': Project.getDistrictCode(project.district), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
163 |
} |
19 | 164 |
if not prop_form: |
165 |
prop_form = projrev_forms.ProposalForm( |
|
166 |
initial=initial_vals, instance=project) |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
167 |
|
13 | 168 |
proposal = project.proposal_set.all().order_by('-submitted_on')[0] |
169 |
||
170 |
if proposal: |
|
171 |
proposal_path = str(proposal.document) |
|
0 | 172 |
|
13 | 173 |
proposal_name = proposal_path.split('/')[-1] |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
174 |
|
13 | 175 |
context['proposal_path'] = proposal_path |
176 |
context['proposal_name'] = proposal_name |
|
14 | 177 |
context['last_submitted'] = proposal.submitted_on |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
178 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
179 |
if 'HTTP_REFERER' in request.META: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
180 |
referer = request.META['HTTP_REFERER'].split('/') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
181 |
if referer[-1]: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
182 |
ref = referer[-1] |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
183 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
184 |
ref = referer[-2] |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
185 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
186 |
if ref == 'create': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
187 |
context['created_now'] = True |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
188 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
189 |
context['micr_code'] = project.micr_code |
13 | 190 |
|
191 |
reviews = project.review_set.all().order_by('-reviewed_on') |
|
192 |
if reviews: |
|
193 |
context['last_reviewed'] = reviews[0].reviewed_on |
|
194 |
context['nr_reviews'] = len(reviews) |
|
195 |
||
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
196 |
else: |
19 | 197 |
if not prop_form: |
198 |
prop_form = projrev_forms.ProposalForm() |
|
0 | 199 |
|
200 |
context['form'] = prop_form |
|
201 |
||
202 |
template = 'projrev/proposal/submit.html' |
|
203 |
||
6 | 204 |
return render_to_response(template, RequestContext(request, context)) |
0 | 205 |
|
12 | 206 |
@access.register('proposer') |
6 | 207 |
@access.checkAccess |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
208 |
def withdraw(request, micr_code=None): |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
209 |
"""View Method for withdrawal of proposal. |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
210 |
""" |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
211 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
212 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
213 |
project = Project.objects.get(micr_code=micr_code) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
214 |
if project: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
215 |
project.status = 'invalid' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
216 |
project.save() |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
217 |
context = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
218 |
'withdrawn': True, |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
219 |
} |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
220 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
221 |
template = 'projrev/proposal/withdraw.html' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
222 |
|
6 | 223 |
return render_to_response(template, RequestContext(request, context)) |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
224 |
|
12 | 225 |
@access.register('reviewer') |
6 | 226 |
@access.checkAccess |
0 | 227 |
def review(request, micr_code=None): |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
228 |
"""View for reviewing the proposal. |
0 | 229 |
""" |
230 |
||
231 |
if request.method == 'POST': |
|
232 |
return reviewPost(request, micr_code) |
|
233 |
else: |
|
234 |
return reviewGet(request, micr_code) |
|
235 |
||
236 |
def reviewPost(request, micr_code=None): |
|
237 |
""" |
|
238 |
""" |
|
239 |
||
240 |
rev_form = projrev_forms.ReviewForm(request.POST) |
|
241 |
||
242 |
if rev_form.is_valid(): |
|
243 |
cleaned_data = rev_form.cleaned_data |
|
244 |
||
245 |
cleaned_data['project'] = Project.objects.get(micr_code=micr_code) |
|
246 |
||
247 |
# If the form is valid create a new project or update the project |
|
248 |
# if it already exists from the form. |
|
249 |
review = rev_form.save() |
|
250 |
||
251 |
return reviewGet(request, micr_code, rev_form) |
|
252 |
||
253 |
def reviewGet(request, micr_code=None, rev_form=None): |
|
254 |
""" |
|
255 |
""" |
|
256 |
||
14 | 257 |
context = {} |
258 |
||
0 | 259 |
if not micr_code: |
260 |
template = 'projrev/proposal/list.html' |
|
16
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
261 |
context['projects'] = Project.objects.all().exclude( |
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
262 |
status__exact='invalid').order_by('-last_updated_on') |
14 | 263 |
context['row_url'] = '/proposal/review/' |
0 | 264 |
|
6 | 265 |
return render_to_response(template, RequestContext(request, context)) |
0 | 266 |
|
267 |
if not rev_form: |
|
268 |
rev_form = projrev_forms.ReviewForm() |
|
269 |
||
14 | 270 |
project = Project.objects.get(micr_code=micr_code) |
271 |
context['form'] = rev_form |
|
272 |
context['project'] = project |
|
0 | 273 |
|
14 | 274 |
proposal = project.proposal_set.all().order_by('-submitted_on')[0] |
275 |
||
276 |
if proposal: |
|
277 |
proposal_path = str(proposal.document) |
|
0 | 278 |
|
14 | 279 |
proposal_name = proposal_path.split('/')[-1] |
280 |
||
281 |
context['proposal_path'] = proposal_path |
|
282 |
context['proposal_name'] = proposal_name |
|
283 |
context['last_submitted'] = proposal.submitted_on |
|
284 |
||
285 |
reviews = project.review_set.all().order_by('-reviewed_on') |
|
286 |
if reviews: |
|
287 |
context['last_reviewed'] = reviews[0].reviewed_on |
|
288 |
context['nr_reviews'] = len(reviews) |
|
0 | 289 |
|
290 |
template = 'projrev/proposal/review.html' |
|
291 |
||
6 | 292 |
return render_to_response(template, RequestContext(request, context)) |
0 | 293 |
|
12 | 294 |
@access.register('reviewer') |
6 | 295 |
@access.checkAccess |
0 | 296 |
def rank(request, micr_code=None): |
297 |
""" |
|
298 |
""" |
|
299 |
||
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
300 |
context = {} |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
301 |
|
0 | 302 |
if not micr_code: |
303 |
template = 'projrev/proposal/list.html' |
|
16
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
304 |
context['projects'] = Project.objects.all().exclude( |
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
305 |
status__exact='invalid').order_by('-last_updated_on') |
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
306 |
context['row_url'] = '/proposal/rank/' |
0 | 307 |
|
6 | 308 |
return render_to_response(template, RequestContext(request, context)) |
0 | 309 |
|
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
310 |
project = Project.objects.get(micr_code=micr_code) |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
311 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
312 |
proposal = project.proposal_set.all().order_by('-submitted_on')[0] |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
313 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
314 |
if proposal: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
315 |
proposal_path = str(proposal.document) |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
316 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
317 |
proposal_name = proposal_path.split('/')[-1] |
0 | 318 |
|
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
319 |
context['proposal_path'] = proposal_path |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
320 |
context['proposal_name'] = proposal_name |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
321 |
context['last_submitted'] = proposal.submitted_on |
0 | 322 |
|
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
323 |
reviews = project.review_set.all().order_by('-reviewed_on') |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
324 |
nr_reviews = len(reviews) |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
325 |
if reviews: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
326 |
context['last_reviewed'] = reviews[0].reviewed_on |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
327 |
context['nr_reviews'] = nr_reviews |
0 | 328 |
|
329 |
review_score = [0] * 9 |
|
330 |
for review in reviews: |
|
331 |
review_score[0] += review.attribute1 |
|
332 |
review_score[1] += review.attribute2 |
|
333 |
review_score[2] += review.attribute3 |
|
334 |
review_score[3] += review.attribute4 |
|
335 |
review_score[4] += review.attribute5 |
|
336 |
review_score[5] += review.attribute6 |
|
337 |
review_score[6] += review.attribute7 |
|
338 |
review_score[7] += review.attribute8 |
|
339 |
review_score[8] += review.attribute9 |
|
340 |
||
341 |
total_score = sum(review_score) |
|
342 |
||
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
343 |
review_avg = [0] * 9 |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
344 |
for i, rs in enumerate(review_score): |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
345 |
try: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
346 |
review_avg[i] = float(rs) / nr_reviews |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
347 |
except ZeroDivisionError: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
348 |
review_avg[i] = 0 |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
349 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
350 |
try: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
351 |
total_avg = float(total_score) / nr_reviews |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
352 |
except ZeroDivisionError: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
353 |
total_avg = 0 |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
354 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
355 |
context['project'] = project |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
356 |
context['review_score'] = review_score |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
357 |
context['total_score'] = total_score |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
358 |
context['review_avg'] = review_avg |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
359 |
context['total_avg'] = total_avg |
0 | 360 |
|
361 |
template = 'projrev/proposal/rank.html' |
|
362 |
||
6 | 363 |
return render_to_response(template, RequestContext(request, context)) |