author | Madhusudan.C.S <madhusudancs@gmail.com> |
Thu, 13 Aug 2009 04:01:15 +0530 | |
changeset 47 | 09c3b7aaa535 |
parent 46 | e27c75dedbfb |
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 |
||
40
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
15 |
from django.contrib.auth.models import User |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
16 |
from django.core.urlresolvers import reverse |
22 | 17 |
from django.http import HttpResponse |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
18 |
from django.http import HttpResponseRedirect |
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
6
diff
changeset
|
19 |
from django.shortcuts import render_to_response |
6 | 20 |
from django.template import RequestContext |
0 | 21 |
|
22 |
from projrev.models import Project |
|
23 |
from projrev.models import Proposal |
|
31
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
24 |
from projrev.models import Review |
5
88ae12bc6280
Access check helper file added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
4
diff
changeset
|
25 |
from projrev.views.helpers import access |
0 | 26 |
from projrev.views.helpers import forms as projrev_forms |
27 |
||
5
88ae12bc6280
Access check helper file added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
4
diff
changeset
|
28 |
|
12 | 29 |
@access.register('proposer') |
6 | 30 |
@access.checkAccess |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
31 |
def getMicr(request): |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
32 |
"""View to get MICR Code from the user. |
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 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
35 |
if request.method == 'POST': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
36 |
post_params = request.POST |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
37 |
submit = post_params.get('submit') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
38 |
if submit == 'New Proposal': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
39 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
40 |
reverse('app.projrev.views.proposal.submit')) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
41 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
42 |
micr_code = request.POST.get('micr_code') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
43 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
44 |
try: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
45 |
Project.objects.get(micr_code=micr_code) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
46 |
except Project.DoesNotExist: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
47 |
if (submit == 'Edit Proposal for MICR Code' or |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
48 |
submit == 'Withdraw Proposal for MICR Code'): |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
49 |
template = 'projrev/proposal/get_micr.html' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
50 |
context = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
51 |
'error': True, |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
52 |
} |
6 | 53 |
return render_to_response(template, |
54 |
RequestContext(request, context)) |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
55 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
56 |
if submit == 'Edit 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.submit', |
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 |
elif submit == 'Withdraw Proposal for MICR Code': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
61 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
62 |
reverse('app.projrev.views.proposal.withdraw', |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
63 |
args=(micr_code, ))) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
64 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
65 |
template = 'projrev/proposal/get_micr.html' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
66 |
context = {} |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
67 |
|
6 | 68 |
return render_to_response(template, RequestContext(request, context)) |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
69 |
|
12 | 70 |
@access.register('proposer') |
6 | 71 |
@access.checkAccess |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
72 |
def submit(request, micr_code=None): |
0 | 73 |
"""View for proposal submission. |
74 |
""" |
|
75 |
||
76 |
if request.method == 'POST': |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
77 |
return submitPost(request, micr_code) |
0 | 78 |
else: |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
79 |
return submitGet(request, micr_code) |
0 | 80 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
81 |
def submitPost(request, micr_code=None): |
0 | 82 |
"""Handles POST request for the submitted proposal form. |
83 |
""" |
|
84 |
||
85 |
prop_form = projrev_forms.ProposalForm(request.POST, request.FILES) |
|
86 |
||
87 |
project = None |
|
88 |
proposal = None |
|
89 |
||
90 |
if prop_form.is_valid(): |
|
91 |
cleaned_data = prop_form.cleaned_data |
|
92 |
||
13 | 93 |
if micr_code: |
94 |
project = Project.objects.get(micr_code=micr_code) |
|
95 |
project.line_item = Project.getLineItem(cleaned_data['line_item']) |
|
96 |
project.institution = cleaned_data['institution'] |
|
97 |
project.state = Project.getState(cleaned_data['state']) |
|
98 |
project.district = Project.getDistrict(cleaned_data['district']) |
|
99 |
else: |
|
100 |
# Generate MICR code |
|
39
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
101 |
if cleaned_data['district']: |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
102 |
cleaned_data['micr_code'] = '%s%s%d' % ( |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
103 |
cleaned_data['district'], cleaned_data['line_item'], |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
104 |
int(time.time() * 1000) % 1000000000) |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
105 |
else: |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
106 |
cleaned_data['micr_code'] = '%s%s%s%d' % ( |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
107 |
cleaned_data['state'], 'NN', cleaned_data['line_item'], |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
108 |
int(time.time() * 1000) % 1000000000) |
0 | 109 |
|
13 | 110 |
cleaned_data['line_item'] = Project.getLineItem(cleaned_data['line_item']) |
111 |
cleaned_data['state'] = Project.getState(cleaned_data['state']) |
|
112 |
cleaned_data['district'] = Project.getDistrict(cleaned_data['district']) |
|
113 |
||
114 |
prop_form.cleaned_data = cleaned_data |
|
0 | 115 |
|
13 | 116 |
# If the form is valid create a new project or update the project |
117 |
# if it already exists from the form. |
|
118 |
project = prop_form.save() |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
119 |
|
13 | 120 |
project.micr_code = cleaned_data['micr_code'] |
0 | 121 |
|
40
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
122 |
send_mails(request, project) |
18
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
16
diff
changeset
|
123 |
|
0 | 124 |
project.status = 'new' |
13 | 125 |
micr_code = project.micr_code |
0 | 126 |
|
127 |
project.save() |
|
128 |
||
13 | 129 |
if prop_form.cleaned_data['document']: |
130 |
# Create a proposal for the project. |
|
131 |
proposal = project.proposal_set.create( |
|
132 |
document=prop_form.cleaned_data['document'], |
|
133 |
submitted_by=request.user, rev_num = 0) |
|
0 | 134 |
|
13 | 135 |
proposal.save() |
0 | 136 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
137 |
return HttpResponseRedirect( |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
138 |
reverse('app.projrev.views.proposal.submit', args=(micr_code,))) |
0 | 139 |
|
19 | 140 |
return submitGet(request, micr_code, prop_form) |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
141 |
|
19 | 142 |
def submitGet(request, micr_code=None, prop_form=None): |
0 | 143 |
"""Handles GET request for the submission of proposal form. |
144 |
""" |
|
145 |
||
146 |
context = {} |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
147 |
project = None |
0 | 148 |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
149 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
150 |
project = Project.objects.get(micr_code=micr_code) |
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 project: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
153 |
initial_vals = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
154 |
'line_item': Project.getLineItemCode(project.line_item), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
155 |
'state': Project.getStateCode(project.state), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
156 |
'district': Project.getDistrictCode(project.district), |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
157 |
} |
19 | 158 |
if not prop_form: |
159 |
prop_form = projrev_forms.ProposalForm( |
|
160 |
initial=initial_vals, instance=project) |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
161 |
|
38 | 162 |
proposals = project.proposal_set.all() |
163 |
if proposals: |
|
164 |
proposal = proposals.order_by('-submitted_on')[0] |
|
0 | 165 |
|
38 | 166 |
if proposal: |
167 |
proposal_path = str(proposal.document) |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
168 |
|
38 | 169 |
proposal_name = proposal_path.split('/')[-1] |
170 |
||
171 |
context['proposal_path'] = proposal_path |
|
172 |
context['proposal_name'] = proposal_name |
|
173 |
context['last_submitted'] = proposal.submitted_on |
|
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
174 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
175 |
if 'HTTP_REFERER' in request.META: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
176 |
referer = request.META['HTTP_REFERER'].split('/') |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
177 |
if referer[-1]: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
178 |
ref = referer[-1] |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
179 |
else: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
180 |
ref = referer[-2] |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
181 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
182 |
if ref == 'create': |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
183 |
context['created_now'] = True |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
184 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
185 |
context['micr_code'] = project.micr_code |
13 | 186 |
|
187 |
reviews = project.review_set.all().order_by('-reviewed_on') |
|
188 |
if reviews: |
|
189 |
context['last_reviewed'] = reviews[0].reviewed_on |
|
190 |
context['nr_reviews'] = len(reviews) |
|
191 |
||
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
192 |
else: |
19 | 193 |
if not prop_form: |
22 | 194 |
|
19 | 195 |
prop_form = projrev_forms.ProposalForm() |
0 | 196 |
|
197 |
context['form'] = prop_form |
|
198 |
||
199 |
template = 'projrev/proposal/submit.html' |
|
200 |
||
6 | 201 |
return render_to_response(template, RequestContext(request, context)) |
0 | 202 |
|
12 | 203 |
@access.register('proposer') |
6 | 204 |
@access.checkAccess |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
205 |
def withdraw(request, micr_code=None): |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
206 |
"""View Method for withdrawal of proposal. |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
207 |
""" |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
208 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
209 |
if micr_code: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
210 |
project = Project.objects.get(micr_code=micr_code) |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
211 |
if project: |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
212 |
project.status = 'invalid' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
213 |
project.save() |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
214 |
context = { |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
215 |
'withdrawn': True, |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
216 |
} |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
217 |
|
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
218 |
template = 'projrev/proposal/withdraw.html' |
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
219 |
|
6 | 220 |
return render_to_response(template, RequestContext(request, context)) |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
221 |
|
12 | 222 |
@access.register('reviewer') |
6 | 223 |
@access.checkAccess |
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
224 |
def review(request, micr_code=None, review_id=None): |
4
8d9da911ed7d
Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
0
diff
changeset
|
225 |
"""View for reviewing the proposal. |
0 | 226 |
""" |
227 |
||
228 |
if request.method == 'POST': |
|
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
229 |
return reviewPost(request, micr_code, review_id) |
0 | 230 |
else: |
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
231 |
return reviewGet(request, micr_code, review_id) |
0 | 232 |
|
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
233 |
def reviewPost(request, micr_code=None, review_id=None): |
0 | 234 |
""" |
235 |
""" |
|
46
e27c75dedbfb
Fixed the correct redirects and review saves.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
45
diff
changeset
|
236 |
is_new = request.GET.get('new') |
e27c75dedbfb
Fixed the correct redirects and review saves.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
45
diff
changeset
|
237 |
if review_id and is_new != '0': |
e27c75dedbfb
Fixed the correct redirects and review saves.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
45
diff
changeset
|
238 |
redirect = False |
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
239 |
review_instance = Review.objects.get(id=review_id) |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
240 |
rev_form = projrev_forms.ReviewForm(request.POST, instance=review_instance) |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
241 |
else: |
46
e27c75dedbfb
Fixed the correct redirects and review saves.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
45
diff
changeset
|
242 |
redirect = True |
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
243 |
rev_form = projrev_forms.ReviewForm(request.POST) |
0 | 244 |
|
245 |
if rev_form.is_valid(): |
|
246 |
cleaned_data = rev_form.cleaned_data |
|
247 |
||
43
55e650bb9dbe
Star values recalled.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
40
diff
changeset
|
248 |
project = Project.objects.get(micr_code=micr_code) |
55e650bb9dbe
Star values recalled.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
40
diff
changeset
|
249 |
proposal = project.proposal_set.all().order_by('-submitted_on')[0] |
55e650bb9dbe
Star values recalled.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
40
diff
changeset
|
250 |
|
55e650bb9dbe
Star values recalled.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
40
diff
changeset
|
251 |
cleaned_data['project'] = project |
55e650bb9dbe
Star values recalled.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
40
diff
changeset
|
252 |
cleaned_data['proposal'] = proposal |
26
97bd3c28c957
Renamed Comments to Reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
23
diff
changeset
|
253 |
cleaned_data['reviewer'] = request.user |
0 | 254 |
|
255 |
# If the form is valid create a new project or update the project |
|
256 |
# if it already exists from the form. |
|
257 |
review = rev_form.save() |
|
46
e27c75dedbfb
Fixed the correct redirects and review saves.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
45
diff
changeset
|
258 |
|
e27c75dedbfb
Fixed the correct redirects and review saves.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
45
diff
changeset
|
259 |
if redirect: |
e27c75dedbfb
Fixed the correct redirects and review saves.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
45
diff
changeset
|
260 |
return HttpResponseRedirect(reverse('app.projrev.views.proposal.review', args=(micr_code, review.id))) |
0 | 261 |
|
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
262 |
return reviewGet(request, micr_code, review_id, rev_form) |
0 | 263 |
|
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
264 |
def reviewGet(request, micr_code=None, review_id=None, rev_form=None): |
0 | 265 |
""" |
266 |
""" |
|
267 |
||
14 | 268 |
context = {} |
269 |
||
0 | 270 |
if not micr_code: |
45
9ffe957d6159
Split list files between, review and rank.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
44
diff
changeset
|
271 |
template = 'projrev/proposal/review_list.html' |
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
272 |
context['projects'] = [] |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
273 |
projects = Project.objects.all().exclude( |
16
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
274 |
status__exact='invalid').order_by('-last_updated_on') |
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
275 |
|
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
276 |
for project in projects: |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
277 |
user_reviews = project.review_set.all().filter( |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
278 |
reviewer__id__exact=request.user.id).order_by('-reviewed_on') |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
279 |
|
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
280 |
proposals = project.proposal_set.all().order_by('-submitted_on') |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
281 |
|
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
282 |
if user_reviews and proposals: |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
283 |
info = { |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
284 |
'project': project, |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
285 |
} |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
286 |
proposal = proposals[0] |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
287 |
new_user_reviews = user_reviews.filter(proposal__id__exact=proposal.id) |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
288 |
if new_user_reviews: |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
289 |
info['user_review'] = new_user_reviews[0] |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
290 |
else: |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
291 |
info['not_this_proposal'] = True |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
292 |
info['user_review'] = user_reviews[0] |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
293 |
|
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
294 |
context['projects'].append(info) |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
295 |
elif proposals: |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
296 |
info = { |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
297 |
'project': project, |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
298 |
} |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
299 |
proposal = proposals[0] |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
300 |
context['projects'].append(info) |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
301 |
|
14 | 302 |
context['row_url'] = '/proposal/review/' |
0 | 303 |
|
6 | 304 |
return render_to_response(template, RequestContext(request, context)) |
0 | 305 |
|
14 | 306 |
project = Project.objects.get(micr_code=micr_code) |
0 | 307 |
|
39
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
308 |
proposals = project.proposal_set.all().order_by('-submitted_on') |
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
309 |
|
39
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
310 |
if proposals: |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
311 |
proposal = proposals[0] |
0 | 312 |
|
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
313 |
user_review = Review.objects.all().filter( |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
314 |
id__exact=review_id).order_by('-reviewed_on') |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
315 |
|
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
316 |
if user_review: |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
317 |
user_review = user_review[0] |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
318 |
|
39
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
319 |
if proposal: |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
320 |
proposal_path = str(proposal.document) |
14 | 321 |
|
39
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
322 |
proposal_name = proposal_path.split('/')[-1] |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
323 |
|
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
324 |
context['proposal_path'] = proposal_path |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
325 |
context['proposal_name'] = proposal_name |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
326 |
context['last_submitted'] = proposal.submitted_on |
14 | 327 |
|
44
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
328 |
if not rev_form: |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
329 |
if user_review: |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
330 |
rev_form = projrev_forms.ReviewForm(instance=user_review) |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
331 |
context['prev_data'] = rev_form.initial |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
332 |
else: |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
333 |
rev_form = projrev_forms.ReviewForm() |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
334 |
else: |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
335 |
context['prev_data'] = rev_form.data |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
336 |
|
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
337 |
context['form'] = rev_form |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
338 |
context['project'] = project |
6fda3f3cc873
All fixed for revising reviews and copying over reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
43
diff
changeset
|
339 |
|
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
340 |
reviews = project.review_set.all().order_by('reviewed_on') |
14 | 341 |
if reviews: |
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
342 |
context['reviews'] = reviews |
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
343 |
context['last_reviewed'] = reviews[len(reviews)-1].reviewed_on |
14 | 344 |
context['nr_reviews'] = len(reviews) |
0 | 345 |
|
346 |
template = 'projrev/proposal/review.html' |
|
347 |
||
6 | 348 |
return render_to_response(template, RequestContext(request, context)) |
0 | 349 |
|
12 | 350 |
@access.register('reviewer') |
6 | 351 |
@access.checkAccess |
0 | 352 |
def rank(request, micr_code=None): |
353 |
""" |
|
354 |
""" |
|
355 |
||
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
356 |
context = {} |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
357 |
|
0 | 358 |
if not micr_code: |
359 |
template = 'projrev/proposal/list.html' |
|
16
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
360 |
context['projects'] = Project.objects.all().exclude( |
bed14c9685a5
Project model changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
15
diff
changeset
|
361 |
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
|
362 |
context['row_url'] = '/proposal/rank/' |
0 | 363 |
|
6 | 364 |
return render_to_response(template, RequestContext(request, context)) |
0 | 365 |
|
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
366 |
project = Project.objects.get(micr_code=micr_code) |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
367 |
|
39
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
368 |
proposals = project.proposal_set.all().order_by('-submitted_on') |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
369 |
if proposals: |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
370 |
proposal = proposals[0] |
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
371 |
|
39
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
372 |
if proposal: |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
373 |
proposal_path = str(proposal.document) |
0 | 374 |
|
39
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
375 |
proposal_name = proposal_path.split('/')[-1] |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
376 |
|
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
377 |
context['proposal_path'] = proposal_path |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
378 |
context['proposal_name'] = proposal_name |
e7880a8f7e04
Changes to the data model for including blank districts.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
38
diff
changeset
|
379 |
context['last_submitted'] = proposal.submitted_on |
0 | 380 |
|
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
381 |
# 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
|
382 |
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
|
383 |
nr_reviews = len(reviews) |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
384 |
if reviews: |
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
385 |
context['reviews'] = reviews |
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
386 |
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
|
387 |
context['nr_reviews'] = nr_reviews |
0 | 388 |
|
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
389 |
# Calculate the review scores |
0 | 390 |
review_score = [0] * 9 |
391 |
for review in reviews: |
|
392 |
review_score[0] += review.attribute1 |
|
393 |
review_score[1] += review.attribute2 |
|
394 |
review_score[2] += review.attribute3 |
|
395 |
review_score[3] += review.attribute4 |
|
396 |
review_score[4] += review.attribute5 |
|
397 |
review_score[5] += review.attribute6 |
|
398 |
review_score[6] += review.attribute7 |
|
399 |
review_score[7] += review.attribute8 |
|
400 |
review_score[8] += review.attribute9 |
|
401 |
||
402 |
total_score = sum(review_score) |
|
403 |
||
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
404 |
# Get the Average for each attribute |
15
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
405 |
review_avg = [0] * 9 |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
406 |
for i, rs in enumerate(review_score): |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
407 |
try: |
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
408 |
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
|
409 |
except ZeroDivisionError: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
410 |
review_avg[i] = 0 |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
411 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
412 |
try: |
27
37612f295cd4
Added comments for ranks and reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
26
diff
changeset
|
413 |
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
|
414 |
except ZeroDivisionError: |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
415 |
total_avg = 0 |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
416 |
|
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
417 |
context['project'] = project |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
418 |
context['review_score'] = review_score |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
419 |
context['total_score'] = total_score |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
420 |
context['review_avg'] = review_avg |
8c9e6c98de82
Ranking of proposals view completion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
421 |
context['total_avg'] = total_avg |
0 | 422 |
|
423 |
template = 'projrev/proposal/rank.html' |
|
424 |
||
6 | 425 |
return render_to_response(template, RequestContext(request, context)) |
22 | 426 |
|
427 |
def getDistrictsForState(request): |
|
428 |
"""View function that sends the districts for the given state code via AJAXy. |
|
429 |
""" |
|
23
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
430 |
|
22 | 431 |
get_params = request.GET |
23
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
432 |
if get_params: |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
433 |
st_code = get_params['_value'] |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
434 |
dt_dict = Project.DISTRICT_CHOICES |
22 | 435 |
|
23
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
436 |
# 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
|
437 |
dt_names = {} |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
438 |
count = 1 |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
439 |
for dt_code in dt_dict: |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
440 |
if dt_code[:2] == st_code: |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
441 |
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
|
442 |
count += 1 |
22 | 443 |
|
23
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
444 |
# 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
|
445 |
dt_send = [{'': "---------" }] |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
446 |
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
|
447 |
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
|
448 |
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
|
449 |
|
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
450 |
return HttpResponse(json.dumps(dt_send)) |
91cf6872d853
Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
22
diff
changeset
|
451 |
|
30
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
452 |
return HttpResponse(None) |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
453 |
|
38 | 454 |
def getNewDistrictsForState(request): |
455 |
"""Get initial district for state. |
|
456 |
""" |
|
457 |
||
458 |
get_params = request.GET |
|
459 |
if get_params: |
|
460 |
st_code = get_params['_value'] |
|
461 |
dt_dict = Project.DISTRICT_CHOICES |
|
462 |
||
463 |
# Get the Districts corresponding to the given State code. |
|
464 |
dt_names = {} |
|
465 |
count = 1 |
|
466 |
for dt_code in dt_dict: |
|
467 |
if dt_code[:2] == st_code: |
|
468 |
dt_names[dt_code] = dt_dict[dt_code] |
|
469 |
count += 1 |
|
470 |
||
471 |
# Sort the List based on District Name. |
|
472 |
dt_send = [{'': "---------"}] |
|
473 |
dt_names_sorted = sorted(dt_names.items(), key=lambda (k,v): (v,k)) |
|
474 |
for dt_code, dt_name in dt_names_sorted: |
|
475 |
dt_send.append({dt_code: dt_name}) |
|
476 |
||
477 |
return HttpResponse(json.dumps(dt_send)) |
|
478 |
||
479 |
return HttpResponse(None) |
|
480 |
||
30
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
481 |
@access.register('reviewer') |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
482 |
@access.checkAccess |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
483 |
def listMyReviews(request): |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
484 |
"""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
|
485 |
""" |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
486 |
context = {} |
94fe7fe7394d
Complete star plugin implmentation on backend with database writes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
27
diff
changeset
|
487 |
|
31
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
488 |
# 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
|
489 |
reviews = Review.objects.all().order_by('reviewed_on') |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
490 |
nr_reviews = len(reviews) |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
491 |
if reviews: |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
492 |
context['reviews'] = reviews |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
493 |
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
|
494 |
context['nr_reviews'] = nr_reviews |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
495 |
|
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
496 |
template = 'projrev/proposal/myreviews.html' |
ef9fdc847543
Added list of My reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
30
diff
changeset
|
497 |
|
32 | 498 |
return render_to_response(template, RequestContext(request, context)) |
40
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
499 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
500 |
def send_mails(request, project): |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
501 |
"""Send mails to the user and all the reviewers after the project is created. |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
502 |
""" |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
503 |
pass |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
504 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
505 |
subject = '[Sakshath] MICR Code of the new proposal submitted' |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
506 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
507 |
message = """Hi, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
508 |
We have received a new proposal for National Mission on education from your, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
509 |
email address "%s", to the http://sakshath.ac.in portal. The MICR Code of the |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
510 |
submitted proposal is: |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
511 |
MICR Code: %s |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
512 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
513 |
Please remember this code for all future references. |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
514 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
515 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
516 |
-- |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
517 |
Regards, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
518 |
Saksath admin""" % (request.user.username, project.micr_code) |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
519 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
520 |
request.user.email_user(subject=subject, message=message) |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
521 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
522 |
subject = '[Sakshath] A new proposal has been submitted for review' |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
523 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
524 |
message_template = """Dear %(user)s, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
525 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
526 |
A new project proposal has been uploaded on the site for reviewing. The details are as follows: |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
527 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
528 |
*Title:* %(title)s |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
529 |
*Institution:* %(institution)s |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
530 |
*Address:* %(address)s |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
531 |
*City:* %(city)s |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
532 |
*State:* %(state)s |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
533 |
*Phone Number:* %(ph_no)s |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
534 |
*Email ID:* %(email)s |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
535 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
536 |
To review the proposal please logon to: <a href="">some website</a> |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
537 |
""" |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
538 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
539 |
reviewers = User.objects.all().filter(is_staff__exact='1') |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
540 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
541 |
for reviewer in reviewers: |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
542 |
message = message_template % { |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
543 |
'user': reviewer.username, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
544 |
'title': project.title, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
545 |
'institution': project.institution, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
546 |
'address': project.address, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
547 |
'city': project.city, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
548 |
'state': project.state, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
549 |
'ph_no': project.phone_num, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
550 |
'email': request.user.email, |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
551 |
} |
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
552 |
|
7f6f4b8525b8
Send mails to all reviewers.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
39
diff
changeset
|
553 |
reviewer.email_user(subject=subject, message=message) |