--- a/app/projrev/views/proposal.py Thu Aug 06 12:17:29 2009 +0530
+++ b/app/projrev/views/proposal.py Thu Aug 06 18:15:57 2009 +0530
@@ -8,8 +8,11 @@
]
+import os
import time
+from django.core.urlresolvers import reverse
+from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from projrev.models import Project
@@ -17,16 +20,54 @@
from projrev.views.helpers import forms as projrev_forms
-def submit(request):
+def getMicr(request):
+ """View to get MICR Code from the user.
+ """
+
+ if request.method == 'POST':
+ post_params = request.POST
+ submit = post_params.get('submit')
+ if submit == 'New Proposal':
+ return HttpResponseRedirect(
+ reverse('app.projrev.views.proposal.submit'))
+ else:
+ micr_code = request.POST.get('micr_code')
+ if micr_code:
+ try:
+ Project.objects.get(micr_code=micr_code)
+ except Project.DoesNotExist:
+ if (submit == 'Edit Proposal for MICR Code' or
+ submit == 'Withdraw Proposal for MICR Code'):
+ template = 'projrev/proposal/get_micr.html'
+ context = {
+ 'error': True,
+ }
+ return render_to_response(template, context)
+ else:
+ if submit == 'Edit Proposal for MICR Code':
+ return HttpResponseRedirect(
+ reverse('app.projrev.views.proposal.submit',
+ args=(micr_code, )))
+ elif submit == 'Withdraw Proposal for MICR Code':
+ return HttpResponseRedirect(
+ reverse('app.projrev.views.proposal.withdraw',
+ args=(micr_code, )))
+ else:
+ template = 'projrev/proposal/get_micr.html'
+ context = {}
+
+ return render_to_response(template, context)
+
+def submit(request, micr_code=None):
"""View for proposal submission.
"""
if request.method == 'POST':
- return submitPost(request)
+ return submitPost(request, micr_code)
else:
- return submitGet(request)
+ return submitGet(request, micr_code)
-def submitPost(request):
+def submitPost(request, micr_code=None):
"""Handles POST request for the submitted proposal form.
"""
@@ -48,11 +89,15 @@
cleaned_data['state'] = Project.getState(cleaned_data['state'])
cleaned_data['district'] = Project.getDistrict(cleaned_data['district'])
+ prop_form.cleaned_data = cleaned_data
+
# If the form is valid create a new project or update the project
# if it already exists from the form.
project = prop_form.save()
project.status = 'new'
+ project.micr_code = cleaned_data['micr_code']
+ micr_code = cleaned_data['micr_code']
project.save()
@@ -62,21 +107,50 @@
proposal.save()
- return submitGet(request, project, proposal)
+ return HttpResponseRedirect(
+ reverse('app.projrev.views.proposal.submit', args=(micr_code,)))
-def submitGet(request, project=None, proposal=None):
+ return HttpResponseRedirect('')
+
+def submitGet(request, micr_code=None):
"""Handles GET request for the submission of proposal form.
"""
context = {}
+ project = None
- if proposal:
- context['document'] = proposal.document
+ if micr_code:
+ project = Project.objects.get(micr_code=micr_code)
+
+ if project:
+ initial_vals = {
+ 'line_item': Project.getLineItemCode(project.line_item),
+ 'state': Project.getStateCode(project.state),
+ 'district': Project.getDistrictCode(project.district),
+ }
+ prop_form = projrev_forms.ProposalForm(
+ initial=initial_vals, instance=project)
+
+ proposal_path = str(project.proposal_set.all()[0].document)
- if not project:
+ proposal_name = proposal_path.split('/')[-1]
+
+ context['proposal_path'] = proposal_path
+ context['proposal_name'] = proposal_name
+
+ if 'HTTP_REFERER' in request.META:
+ referer = request.META['HTTP_REFERER'].split('/')
+ if referer[-1]:
+ ref = referer[-1]
+ else:
+ ref = referer[-2]
+
+ if ref == 'create':
+ context['created_now'] = True
+
+ context['micr_code'] = project.micr_code
+ else:
prop_form = projrev_forms.ProposalForm()
- else:
- prop_form = projrev_forms.ProposalForm(instance=project)
context['form'] = prop_form
@@ -84,8 +158,25 @@
return render_to_response(template, context)
+def withdraw(request, micr_code=None):
+ """View Method for withdrawal of proposal.
+ """
+
+ if micr_code:
+ project = Project.objects.get(micr_code=micr_code)
+ if project:
+ project.status = 'invalid'
+ project.save()
+ context = {
+ 'withdrawn': True,
+ }
+
+ template = 'projrev/proposal/withdraw.html'
+
+ return render_to_response(template, context)
+
def review(request, micr_code=None):
- """
+ """View for reviewing the proposal.
"""
if request.method == 'POST':