app/projrev/views/proposal.py
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--
Full Comments window decoration.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
"""This module contains the views for the project's proposal 
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
funded by NME through ICT.
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
"""
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
__authors__ = [
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
  '"Madhusudan.C.S" <madhusudancs@gmail.com>',
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
]
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
import time
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    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
0321f984fb16 Made form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 21
diff changeset
    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
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
    20
from django.template import RequestContext
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
from projrev.models import Project
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
from projrev.views.helpers import forms as projrev_forms
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
5
88ae12bc6280 Access check helper file added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 4
diff changeset
    28
12
aac4944aca52 With ACL registers
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 8
diff changeset
    29
@access.register('proposer')
6
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
    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
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
    53
            return render_to_response(template,
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
    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
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
    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
aac4944aca52 With ACL registers
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 8
diff changeset
    70
@access.register('proposer')
6
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
    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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
  """View for proposal submission.
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
  """
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
  else:
4
8d9da911ed7d Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 0
diff changeset
    79
    return submitGet(request, micr_code)
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
4
8d9da911ed7d Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 0
diff changeset
    81
def submitPost(request, micr_code=None):
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
  """Handles POST request for the submitted proposal form. 
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
  """
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
  prop_form = projrev_forms.ProposalForm(request.POST, request.FILES)
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
  project = None
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
  proposal = None
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
  if prop_form.is_valid():
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
    cleaned_data = prop_form.cleaned_data
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
13
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
    93
    if micr_code:
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
    94
      project = Project.objects.get(micr_code=micr_code)
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
    95
      project.line_item = Project.getLineItem(cleaned_data['line_item'])
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
    96
      project.institution = cleaned_data['institution']
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
    97
      project.state = Project.getState(cleaned_data['state'])
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
    98
      project.district = Project.getDistrict(cleaned_data['district'])
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
    99
    else:
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
13
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   110
      cleaned_data['line_item'] = Project.getLineItem(cleaned_data['line_item'])
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   111
      cleaned_data['state'] = Project.getState(cleaned_data['state'])
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   112
      cleaned_data['district'] = Project.getDistrict(cleaned_data['district'])
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   113
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   114
      prop_form.cleaned_data = cleaned_data
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   115
13
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   116
      # If the form is valid create a new project or update the project
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   117
      # if it already exists from the form.
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   118
      project = prop_form.save()
4
8d9da911ed7d Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 0
diff changeset
   119
13
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   120
      project.micr_code = cleaned_data['micr_code']
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
    project.status = 'new'
13
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   125
    micr_code = project.micr_code
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
    project.save()
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
13
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   129
    if prop_form.cleaned_data['document']:
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   130
      # Create a proposal for the project.
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   131
      proposal = project.proposal_set.create(
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   132
          document=prop_form.cleaned_data['document'], 
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   133
          submitted_by=request.user, rev_num = 0)
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
13
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   135
      proposal.save()
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
19
0c9bdcfac9f7 Added all data
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   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
0c9bdcfac9f7 Added all data
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   142
def submitGet(request, micr_code=None, prop_form=None):
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
  """Handles GET request for the submission of proposal form.
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
  """
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   145
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
  context = {}
4
8d9da911ed7d Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 0
diff changeset
   147
  project = None
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
0c9bdcfac9f7 Added all data
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   158
    if not prop_form:
0c9bdcfac9f7 Added all data
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   159
      prop_form = projrev_forms.ProposalForm(
0c9bdcfac9f7 Added all data
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   160
          initial=initial_vals, instance=project)
4
8d9da911ed7d Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 0
diff changeset
   161
38
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   162
    proposals = project.proposal_set.all()
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   163
    if proposals:
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   164
      proposal = proposals.order_by('-submitted_on')[0]
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   165
38
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   166
      if proposal:
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   167
        proposal_path = str(proposal.document)
4
8d9da911ed7d Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 0
diff changeset
   168
38
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   169
        proposal_name = proposal_path.split('/')[-1]
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   170
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   171
        context['proposal_path'] = proposal_path
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   172
        context['proposal_name'] = proposal_name
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   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
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   186
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   187
    reviews = project.review_set.all().order_by('-reviewed_on')
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   188
    if reviews:
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   189
      context['last_reviewed'] = reviews[0].reviewed_on
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   190
      context['nr_reviews'] = len(reviews)
684540719344 Added footer line.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 12
diff changeset
   191
 
4
8d9da911ed7d Withdraw of proposals.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 0
diff changeset
   192
  else:
19
0c9bdcfac9f7 Added all data
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   193
    if not prop_form:
22
0321f984fb16 Made form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 21
diff changeset
   194
19
0c9bdcfac9f7 Added all data
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   195
      prop_form = projrev_forms.ProposalForm()
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   196
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
  context['form'] = prop_form
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   198
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
  template = 'projrev/proposal/submit.html'
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
6
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   201
  return render_to_response(template, RequestContext(request, context))
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
12
aac4944aca52 With ACL registers
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 8
diff changeset
   203
@access.register('proposer')
6
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   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
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   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
aac4944aca52 With ACL registers
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 8
diff changeset
   222
@access.register('reviewer')
6
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
  """
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   234
  """
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   244
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   245
  if rev_form.is_valid():
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   246
    cleaned_data = rev_form.cleaned_data
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
    # If the form is valid create a new project or update the project
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   256
    # if it already exists from the form.
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   265
  """
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   266
  """
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   267
14
9d720dfded68 Footer for reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 13
diff changeset
   268
  context = {}
9d720dfded68 Footer for reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 13
diff changeset
   269
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
9d720dfded68 Footer for reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 13
diff changeset
   302
    context['row_url'] = '/proposal/review/'
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   303
6
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   304
    return render_to_response(template, RequestContext(request, context))
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   305
14
9d720dfded68 Footer for reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 13
diff changeset
   306
  project = Project.objects.get(micr_code=micr_code)
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
9d720dfded68 Footer for reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 13
diff changeset
   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
9d720dfded68 Footer for reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 13
diff changeset
   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
9d720dfded68 Footer for reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 13
diff changeset
   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
9d720dfded68 Footer for reviews.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 13
diff changeset
   344
    context['nr_reviews'] = len(reviews)
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   345
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   346
  template = 'projrev/proposal/review.html'
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   347
6
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   348
  return render_to_response(template, RequestContext(request, context))
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   349
12
aac4944aca52 With ACL registers
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 8
diff changeset
   350
@access.register('reviewer')
6
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   351
@access.checkAccess
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   352
def rank(request, micr_code=None):
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   353
  """
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   354
  """
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   358
  if not micr_code:
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   363
6
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   364
    return render_to_response(template, RequestContext(request, context))
0
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   390
  review_score = [0] * 9
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   391
  for review in reviews:
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   392
    review_score[0] += review.attribute1
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   393
    review_score[1] += review.attribute2
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   394
    review_score[2] += review.attribute3
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   395
    review_score[3] += review.attribute4
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   396
    review_score[4] += review.attribute5
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   397
    review_score[5] += review.attribute6
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   398
    review_score[6] += review.attribute7
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   399
    review_score[7] += review.attribute8
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   400
    review_score[8] += review.attribute9
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   401
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   402
  total_score = sum(review_score)
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   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
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   422
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   423
  template = 'projrev/proposal/rank.html'
c94bd9ae70d2 First commit.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   424
6
17cab73c49eb Request context.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   425
  return render_to_response(template, RequestContext(request, context))
22
0321f984fb16 Made form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 21
diff changeset
   426
0321f984fb16 Made form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 21
diff changeset
   427
def getDistrictsForState(request):
0321f984fb16 Made form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 21
diff changeset
   428
  """View function that sends the districts for the given state code via AJAXy.
0321f984fb16 Made form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 21
diff changeset
   429
  """
23
91cf6872d853 Add jqeury purr plugin for help text.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 22
diff changeset
   430
22
0321f984fb16 Made form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 21
diff changeset
   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
0321f984fb16 Made form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 21
diff changeset
   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
0321f984fb16 Made form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 21
diff changeset
   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
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   454
def getNewDistrictsForState(request):
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   455
  """Get initial district for state.
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   456
  """
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   457
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   458
  get_params = request.GET
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   459
  if get_params:
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   460
    st_code = get_params['_value']
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   461
    dt_dict = Project.DISTRICT_CHOICES
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   462
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   463
    # Get the Districts corresponding to the given State code.
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   464
    dt_names = {}
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   465
    count = 1
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   466
    for dt_code in dt_dict:
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   467
      if dt_code[:2] == st_code:
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   468
        dt_names[dt_code] = dt_dict[dt_code]
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   469
        count += 1
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   470
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   471
    # Sort the List based on District Name.
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   472
    dt_send = [{'': "---------"}]
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   473
    dt_names_sorted = sorted(dt_names.items(), key=lambda (k,v): (v,k))
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   474
    for dt_code, dt_name in dt_names_sorted:
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   475
      dt_send.append({dt_code: dt_name})
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   476
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   477
    return HttpResponse(json.dumps(dt_send))
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   478
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   479
  return HttpResponse(None)
3cb38edbe05f Form changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 32
diff changeset
   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
b39994cca761 Attribute Names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 31
diff changeset
   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)