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