author | Santosh G. Vattam <vattam.santosh@gmail.com> |
Mon, 10 Aug 2009 16:58:36 +0530 | |
changeset 36 | a7c525ec281a |
parent 32 | b39994cca761 |
child 38 | 3cb38edbe05f |
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 |
||
23
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
11 |
import json |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
12 |
import os |
0 | 13 |
import time |
14 |
||
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
15 |
from django.core.urlresolvers import reverse |
22 | 16 |
from django.http import HttpResponse |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
17 |
from django.http import HttpResponseRedirect |
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
6
diff
changeset
|
18 |
from django.shortcuts import render_to_response |
6 | 19 |
from django.template import RequestContext |
0 | 20 |
|
21 |
from projrev.models import Project |
|
22 |
from projrev.models import Proposal |
|
31
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
23 |
from projrev.models import Review |
5
88ae12bc6280
Access check helper file added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
4
diff
changeset
|
24 |
from projrev.views.helpers import access |
0 | 25 |
from projrev.views.helpers import forms as projrev_forms |
26 |
||
5
88ae12bc6280
Access check helper file added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
4
diff
changeset
|
27 |
|
12 | 28 |
@access.register('proposer') |
6 | 29 |
@access.checkAccess |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
30 |
def getMicr(request): |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
31 |
"""View to get MICR Code from the user. |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
32 |
""" |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
33 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
34 |
if request.method == 'POST': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
35 |
post_params = request.POST |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
36 |
submit = post_params.get('submit') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
37 |
if submit == 'New Proposal': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
38 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
39 |
reverse('app.projrev.views.proposal.submit')) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
40 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
41 |
micr_code = request.POST.get('micr_code') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
42 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
43 |
try: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
44 |
Project.objects.get(micr_code=micr_code) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
45 |
except Project.DoesNotExist: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
46 |
if (submit == 'Edit Proposal for MICR Code' or |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
47 |
submit == 'Withdraw Proposal for MICR Code'): |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
48 |
template = 'projrev/proposal/get_micr.html' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
49 |
context = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
50 |
'error': True, |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
51 |
} |
6 | 52 |
return render_to_response(template, |
53 |
RequestContext(request, context)) |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
54 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
55 |
if submit == 'Edit 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.submit', |
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 |
elif submit == 'Withdraw Proposal for MICR Code': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
60 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
61 |
reverse('app.projrev.views.proposal.withdraw', |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
62 |
args=(micr_code, ))) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
63 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
64 |
template = 'projrev/proposal/get_micr.html' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
65 |
context = {} |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
66 |
|
6 | 67 |
return render_to_response(template, RequestContext(request, context)) |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
68 |
|
12 | 69 |
@access.register('proposer') |
6 | 70 |
@access.checkAccess |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
71 |
def submit(request, micr_code=None): |
0 | 72 |
"""View for proposal submission. |
73 |
""" |
|
74 |
||
75 |
if request.method == 'POST': |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
76 |
return submitPost(request, micr_code) |
0 | 77 |
else: |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
78 |
return submitGet(request, micr_code) |
0 | 79 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
80 |
def submitPost(request, micr_code=None): |
0 | 81 |
"""Handles POST request for the submitted proposal form. |
82 |
""" |
|
83 |
||
84 |
prop_form = projrev_forms.ProposalForm(request.POST, request.FILES) |
|
85 |
||
86 |
project = None |
|
87 |
proposal = None |
|
88 |
||
89 |
if prop_form.is_valid(): |
|
90 |
cleaned_data = prop_form.cleaned_data |
|
91 |
||
13 | 92 |
if micr_code: |
93 |
project = Project.objects.get(micr_code=micr_code) |
|
94 |
project.line_item = Project.getLineItem(cleaned_data['line_item']) |
|
95 |
project.institution = cleaned_data['institution'] |
|
96 |
project.state = Project.getState(cleaned_data['state']) |
|
97 |
project.district = Project.getDistrict(cleaned_data['district']) |
|
98 |
else: |
|
99 |
# Generate MICR code |
|
21
153db75bb515
Changed data models to all new data.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
19
diff
changeset
|
100 |
cleaned_data['micr_code'] = '%s%s%d' % ( |
153db75bb515
Changed data models to all new data.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
19
diff
changeset
|
101 |
cleaned_data['district'], cleaned_data['line_item'], |
13 | 102 |
int(time.time() * 1000) % 1000000000) |
0 | 103 |
|
13 | 104 |
cleaned_data['line_item'] = Project.getLineItem(cleaned_data['line_item']) |
105 |
cleaned_data['state'] = Project.getState(cleaned_data['state']) |
|
106 |
cleaned_data['district'] = Project.getDistrict(cleaned_data['district']) |
|
107 |
||
108 |
prop_form.cleaned_data = cleaned_data |
|
0 | 109 |
|
13 | 110 |
# If the form is valid create a new project or update the project |
111 |
# if it already exists from the form. |
|
112 |
project = prop_form.save() |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
113 |
|
13 | 114 |
project.micr_code = cleaned_data['micr_code'] |
0 | 115 |
|
18
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
116 |
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
|
117 |
message = """Hi, |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
submitted proposal is: |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
121 |
MICR Code: %s |
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 |
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
|
124 |
|
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
125 |
|
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
126 |
-- |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
127 |
Regards, |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
128 |
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
|
129 |
|
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
130 |
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
|
131 |
|
0 | 132 |
project.status = 'new' |
13 | 133 |
micr_code = project.micr_code |
0 | 134 |
|
135 |
project.save() |
|
136 |
||
13 | 137 |
if prop_form.cleaned_data['document']: |
138 |
# Create a proposal for the project. |
|
139 |
proposal = project.proposal_set.create( |
|
140 |
document=prop_form.cleaned_data['document'], |
|
141 |
submitted_by=request.user, rev_num = 0) |
|
0 | 142 |
|
13 | 143 |
proposal.save() |
0 | 144 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
145 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
146 |
reverse('app.projrev.views.proposal.submit', args=(micr_code,))) |
0 | 147 |
|
19 | 148 |
return submitGet(request, micr_code, prop_form) |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
149 |
|
19 | 150 |
def submitGet(request, micr_code=None, prop_form=None): |
0 | 151 |
"""Handles GET request for the submission of proposal form. |
152 |
""" |
|
153 |
||
154 |
context = {} |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
155 |
project = None |
0 | 156 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
157 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
158 |
project = Project.objects.get(micr_code=micr_code) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
159 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
160 |
if project: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
161 |
initial_vals = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
162 |
'line_item': Project.getLineItemCode(project.line_item), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
163 |
'state': Project.getStateCode(project.state), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
164 |
'district': Project.getDistrictCode(project.district), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
165 |
} |
19 | 166 |
if not prop_form: |
167 |
prop_form = projrev_forms.ProposalForm( |
|
168 |
initial=initial_vals, instance=project) |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
169 |
|
13 | 170 |
proposal = project.proposal_set.all().order_by('-submitted_on')[0] |
171 |
||
172 |
if proposal: |
|
173 |
proposal_path = str(proposal.document) |
|
0 | 174 |
|
13 | 175 |
proposal_name = proposal_path.split('/')[-1] |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
176 |
|
13 | 177 |
context['proposal_path'] = proposal_path |
178 |
context['proposal_name'] = proposal_name |
|
14 | 179 |
context['last_submitted'] = proposal.submitted_on |
4
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 |
if 'HTTP_REFERER' in request.META: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
182 |
referer = request.META['HTTP_REFERER'].split('/') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
183 |
if referer[-1]: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
184 |
ref = referer[-1] |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
185 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
186 |
ref = referer[-2] |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
187 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
188 |
if ref == 'create': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
189 |
context['created_now'] = True |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
190 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
191 |
context['micr_code'] = project.micr_code |
13 | 192 |
|
193 |
reviews = project.review_set.all().order_by('-reviewed_on') |
|
194 |
if reviews: |
|
195 |
context['last_reviewed'] = reviews[0].reviewed_on |
|
196 |
context['nr_reviews'] = len(reviews) |
|
197 |
||
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
198 |
else: |
19 | 199 |
if not prop_form: |
22 | 200 |
|
19 | 201 |
prop_form = projrev_forms.ProposalForm() |
0 | 202 |
|
203 |
context['form'] = prop_form |
|
204 |
||
205 |
template = 'projrev/proposal/submit.html' |
|
206 |
||
6 | 207 |
return render_to_response(template, RequestContext(request, context)) |
0 | 208 |
|
12 | 209 |
@access.register('proposer') |
6 | 210 |
@access.checkAccess |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
211 |
def withdraw(request, micr_code=None): |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
212 |
"""View Method for withdrawal of proposal. |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
213 |
""" |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
214 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
215 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
216 |
project = Project.objects.get(micr_code=micr_code) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
217 |
if project: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
218 |
project.status = 'invalid' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
219 |
project.save() |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
220 |
context = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
221 |
'withdrawn': True, |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
222 |
} |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
223 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
224 |
template = 'projrev/proposal/withdraw.html' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
225 |
|
6 | 226 |
return render_to_response(template, RequestContext(request, context)) |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
227 |
|
12 | 228 |
@access.register('reviewer') |
6 | 229 |
@access.checkAccess |
0 | 230 |
def review(request, micr_code=None): |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
231 |
"""View for reviewing the proposal. |
0 | 232 |
""" |
233 |
||
234 |
if request.method == 'POST': |
|
235 |
return reviewPost(request, micr_code) |
|
236 |
else: |
|
237 |
return reviewGet(request, micr_code) |
|
238 |
||
239 |
def reviewPost(request, micr_code=None): |
|
240 |
""" |
|
241 |
""" |
|
242 |
||
243 |
rev_form = projrev_forms.ReviewForm(request.POST) |
|
244 |
||
245 |
if rev_form.is_valid(): |
|
246 |
cleaned_data = rev_form.cleaned_data |
|
247 |
||
248 |
cleaned_data['project'] = Project.objects.get(micr_code=micr_code) |
|
26
97bd3c28c957
Renamed Comments to Reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
23
diff
changeset
|
249 |
cleaned_data['reviewer'] = request.user |
0 | 250 |
|
251 |
# If the form is valid create a new project or update the project |
|
252 |
# if it already exists from the form. |
|
253 |
review = rev_form.save() |
|
30
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
254 |
return HttpResponseRedirect( |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
255 |
reverse('app.projrev.views.proposal.rank', args=(micr_code,))) |
0 | 256 |
|
257 |
return reviewGet(request, micr_code, rev_form) |
|
258 |
||
259 |
def reviewGet(request, micr_code=None, rev_form=None): |
|
260 |
""" |
|
261 |
""" |
|
262 |
||
14 | 263 |
context = {} |
264 |
||
0 | 265 |
if not micr_code: |
266 |
template = 'projrev/proposal/list.html' |
|
16
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
267 |
context['projects'] = Project.objects.all().exclude( |
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
268 |
status__exact='invalid').order_by('-last_updated_on') |
14 | 269 |
context['row_url'] = '/proposal/review/' |
0 | 270 |
|
6 | 271 |
return render_to_response(template, RequestContext(request, context)) |
0 | 272 |
|
273 |
if not rev_form: |
|
274 |
rev_form = projrev_forms.ReviewForm() |
|
275 |
||
14 | 276 |
project = Project.objects.get(micr_code=micr_code) |
277 |
context['form'] = rev_form |
|
278 |
context['project'] = project |
|
0 | 279 |
|
14 | 280 |
proposal = project.proposal_set.all().order_by('-submitted_on')[0] |
281 |
||
282 |
if proposal: |
|
283 |
proposal_path = str(proposal.document) |
|
0 | 284 |
|
14 | 285 |
proposal_name = proposal_path.split('/')[-1] |
286 |
||
287 |
context['proposal_path'] = proposal_path |
|
288 |
context['proposal_name'] = proposal_name |
|
289 |
context['last_submitted'] = proposal.submitted_on |
|
290 |
||
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
291 |
reviews = project.review_set.all().order_by('reviewed_on') |
14 | 292 |
if reviews: |
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
293 |
context['reviews'] = reviews |
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
294 |
context['last_reviewed'] = reviews[len(reviews)-1].reviewed_on |
14 | 295 |
context['nr_reviews'] = len(reviews) |
0 | 296 |
|
297 |
template = 'projrev/proposal/review.html' |
|
298 |
||
6 | 299 |
return render_to_response(template, RequestContext(request, context)) |
0 | 300 |
|
12 | 301 |
@access.register('reviewer') |
6 | 302 |
@access.checkAccess |
0 | 303 |
def rank(request, micr_code=None): |
304 |
""" |
|
305 |
""" |
|
306 |
||
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
307 |
context = {} |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
308 |
|
0 | 309 |
if not micr_code: |
310 |
template = 'projrev/proposal/list.html' |
|
16
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
311 |
context['projects'] = Project.objects.all().exclude( |
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
312 |
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
|
313 |
context['row_url'] = '/proposal/rank/' |
0 | 314 |
|
6 | 315 |
return render_to_response(template, RequestContext(request, context)) |
0 | 316 |
|
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
317 |
project = Project.objects.get(micr_code=micr_code) |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
318 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
319 |
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
|
320 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
321 |
if proposal: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
322 |
proposal_path = str(proposal.document) |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
323 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
324 |
proposal_name = proposal_path.split('/')[-1] |
0 | 325 |
|
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
326 |
context['proposal_path'] = proposal_path |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
327 |
context['proposal_name'] = proposal_name |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
328 |
context['last_submitted'] = proposal.submitted_on |
0 | 329 |
|
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
330 |
# Get all the reviews and put them to context. |
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
331 |
reviews = project.review_set.all().order_by('reviewed_on') |
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
332 |
nr_reviews = len(reviews) |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
333 |
if reviews: |
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
334 |
context['reviews'] = reviews |
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
335 |
context['last_reviewed'] = reviews[len(reviews)-1].reviewed_on |
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
336 |
context['nr_reviews'] = nr_reviews |
0 | 337 |
|
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
338 |
# Calculate the review scores |
0 | 339 |
review_score = [0] * 9 |
340 |
for review in reviews: |
|
341 |
review_score[0] += review.attribute1 |
|
342 |
review_score[1] += review.attribute2 |
|
343 |
review_score[2] += review.attribute3 |
|
344 |
review_score[3] += review.attribute4 |
|
345 |
review_score[4] += review.attribute5 |
|
346 |
review_score[5] += review.attribute6 |
|
347 |
review_score[6] += review.attribute7 |
|
348 |
review_score[7] += review.attribute8 |
|
349 |
review_score[8] += review.attribute9 |
|
350 |
||
351 |
total_score = sum(review_score) |
|
352 |
||
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
353 |
# Get the Average for each attribute |
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
354 |
review_avg = [0] * 9 |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
355 |
for i, rs in enumerate(review_score): |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
356 |
try: |
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
357 |
review_avg[i] = "%.2f" % (float(rs) / nr_reviews) |
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
358 |
except ZeroDivisionError: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
359 |
review_avg[i] = 0 |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
360 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
361 |
try: |
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
362 |
total_avg = "%.2f" % (float(total_score) / nr_reviews) |
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
363 |
except ZeroDivisionError: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
364 |
total_avg = 0 |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
365 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
366 |
context['project'] = project |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
367 |
context['review_score'] = review_score |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
368 |
context['total_score'] = total_score |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
369 |
context['review_avg'] = review_avg |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
370 |
context['total_avg'] = total_avg |
0 | 371 |
|
372 |
template = 'projrev/proposal/rank.html' |
|
373 |
||
6 | 374 |
return render_to_response(template, RequestContext(request, context)) |
22 | 375 |
|
376 |
def getDistrictsForState(request): |
|
377 |
"""View function that sends the districts for the given state code via AJAXy. |
|
378 |
""" |
|
23
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
379 |
|
22 | 380 |
get_params = request.GET |
23
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
381 |
if get_params: |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
382 |
st_code = get_params['_value'] |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
383 |
dt_dict = Project.DISTRICT_CHOICES |
22 | 384 |
|
23
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
385 |
# Get the Districts corresponding to the given State code. |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
386 |
dt_names = {} |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
387 |
count = 1 |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
388 |
for dt_code in dt_dict: |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
389 |
if dt_code[:2] == st_code: |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
390 |
dt_names[dt_code] = dt_dict[dt_code] |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
391 |
count += 1 |
22 | 392 |
|
23
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
393 |
# Sort the List based on District Name. |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
394 |
dt_send = [{'': "---------" }] |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
395 |
dt_names_sorted = sorted(dt_names.items(), key=lambda (k,v): (v,k)) |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
396 |
for dt_code, dt_name in dt_names_sorted: |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
397 |
dt_send.append({dt_code: dt_name}) |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
398 |
|
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
399 |
return HttpResponse(json.dumps(dt_send)) |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
400 |
|
30
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
401 |
return HttpResponse(None) |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
402 |
|
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
403 |
@access.register('reviewer') |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
404 |
@access.checkAccess |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
405 |
def listMyReviews(request): |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
406 |
"""View function to list all reviews given by a user. |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
407 |
""" |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
408 |
context = {} |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
409 |
|
31
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
410 |
# Get all the reviews and put them to context. |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
411 |
reviews = Review.objects.all().order_by('reviewed_on') |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
412 |
nr_reviews = len(reviews) |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
413 |
if reviews: |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
414 |
context['reviews'] = reviews |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
415 |
context['last_reviewed'] = reviews[len(reviews)-1].reviewed_on |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
416 |
context['nr_reviews'] = nr_reviews |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
417 |
|
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
418 |
template = 'projrev/proposal/myreviews.html' |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
419 |
|
32 | 420 |
return render_to_response(template, RequestContext(request, context)) |