# HG changeset patch # User Madhusudan.C.S # Date 1249562757 -19800 # Node ID 8d9da911ed7d0cb5b75c7b137dbae27562600787 # Parent 252a2d9713a549f35dcb4232a3957a9554074329 Withdraw of proposals. diff -r 252a2d9713a5 -r 8d9da911ed7d app/projrev/models.py --- a/app/projrev/models.py Thu Aug 06 12:17:29 2009 +0530 +++ b/app/projrev/models.py Thu Aug 06 18:15:57 2009 +0530 @@ -64,15 +64,8 @@ # status of the project can be one among the following # New, Revised, Funded, Pilot, DPE status = models.CharField(max_length=256, - choices=[('new', 'New'), ('pilot', 'Pilot')]) - - @classmethod - def getLineItem(cls, code): - """Get the State name from its code. - """ - - line_item_dict = dict(cls.LINE_ITEM_CHOICES) - return line_item_dict[code] + choices=[('new', 'New'), ('pilot', 'Pilot'), + ('invalid', 'Invalid')]) @classmethod def getLineItem(cls, code): @@ -83,29 +76,54 @@ return line_item_dict[code] @classmethod + def getLineItemCode(cls, name): + """Get the Line Item code from its name. + """ + + for ln_code, ln_name in cls.LINE_ITEM_CHOICES: + if ln_name == name: + return ln_code + + return None + + @classmethod def getState(cls, code): - """Get the State name from its code. + """Get the State code from its name. """ state_dict = dict(cls.STATE_CHOICES) return state_dict[code] @classmethod - def getState(cls, code): - """Get the State name from its code. + def getStateCode(cls, name): + """Get the State code from its name. """ - state_dict = dict(cls.STATE_CHOICES) - return state_dict[code] + for st_code, st_name in cls.STATE_CHOICES: + if st_name == name: + return st_code + + return None @classmethod def getDistrict(cls, code): - """Get the State name from its code. + """Get the District name from its code. """ district_dict = dict(cls.DISTRICT_CHOICES) return district_dict[code] + @classmethod + def getDistrictCode(cls, name): + """Get the District code from its name. + """ + + for dt_code, dt_name in cls.DISTRICT_CHOICES: + if dt_name == name: + return dt_code + + return None + class Proposal(models.Model): """Model class for the project's proposal. """ diff -r 252a2d9713a5 -r 8d9da911ed7d app/projrev/views/base.py --- a/app/projrev/views/base.py Thu Aug 06 12:17:29 2009 +0530 +++ b/app/projrev/views/base.py Thu Aug 06 18:15:57 2009 +0530 @@ -18,8 +18,8 @@ if request.user.is_authenticated(): if request.user.is_staff: - HttpResponseRedirect(reverse('app.projrev.views.proposal.review')) + return HttpResponseRedirect(reverse('app.projrev.views.proposal.review')) else: - HttpResponseRedirect(reverse('app.projrev.views.proposal.submit')) + return HttpResponseRedirect(reverse('app.projrev.views.proposal.submit')) else: - HttpResponseRedirect(reverse('app.projrev.views.login.login_validate')) + return HttpResponseRedirect(reverse('app.projrev.views.login.login_validate')) diff -r 252a2d9713a5 -r 8d9da911ed7d app/projrev/views/helpers/forms.py --- a/app/projrev/views/helpers/forms.py Thu Aug 06 12:17:29 2009 +0530 +++ b/app/projrev/views/helpers/forms.py Thu Aug 06 18:15:57 2009 +0530 @@ -16,7 +16,6 @@ """ document = forms.FileField() - micr_code = forms.CharField(max_length=15, required=False) class Meta: # We store most of the data in Project model. So even though the @@ -26,7 +25,7 @@ # fields in the Project that must not appear in the form, but have # be automatically generated. - fields = ('micr_code', 'line_item', 'institution', 'state', 'district') + fields = ('line_item', 'institution', 'state', 'district') class ReviewForm(forms.ModelForm): """Creates a form for review of proposal. diff -r 252a2d9713a5 -r 8d9da911ed7d app/projrev/views/proposal.py --- 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': diff -r 252a2d9713a5 -r 8d9da911ed7d app/settings.py --- a/app/settings.py Thu Aug 06 12:17:29 2009 +0530 +++ b/app/settings.py Thu Aug 06 18:15:57 2009 +0530 @@ -54,6 +54,15 @@ # Make this unique, and don't share it with anybody. SECRET_KEY = '4akwt2sqybl#+rr^l3hk(c#3dj^$+=3l$88-j-l%uy%)*%l8_m' +# List of context processors. +TEMPLATE_CONTEXT_PROCESSORS = ( + 'django.core.context_processors.auth', + 'django.core.context_processors.debug', + 'django.core.context_processors.i18n', + 'django.core.context_processors.media' +) + + # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', diff -r 252a2d9713a5 -r 8d9da911ed7d app/site-content/css/projrev.css --- a/app/site-content/css/projrev.css Thu Aug 06 12:17:29 2009 +0530 +++ b/app/site-content/css/projrev.css Thu Aug 06 18:15:57 2009 +0530 @@ -167,6 +167,39 @@ color: #333; border: 1px solid #DADADA; } + +label.micr { + float: left; + font-weight:bold; + text-align: left; +} + +input.micr { + width: 40%; + position: relative; + left: -150px; + top: 2px; +} + +input.micr_button { + width: auto; + font: bold 1em Arial, Sans-serif; + background: #FFF url(/site-content/images/gradientbg.jpg) repeat-x; + color: #333; + border: 1px solid #DADADA; +} + +a.document-right { + padding: 3px; + margin-left: 3%; + width: 40%; + position: relative; + top: 3px; + border:1px solid #eee; + font: normal 1em "Trebuchet MS", Tahoma, sans-serif; + color:#777; +} + ul.errorlist { width: 60%; color: #ff0000; @@ -441,4 +474,13 @@ margin: 1px 0 0 10%; font: normal 1em "Trebuchet MS", Tahoma, sans-serif; color:#777; +} +div.error { + padding: 3px; + margin-left: 3%; + width: 40%; + position: relative; + left: 22%; + font: normal 1em "Trebuchet MS", Tahoma, sans-serif; + color:#f00; } \ No newline at end of file diff -r 252a2d9713a5 -r 8d9da911ed7d app/templates/projrev/proposal/submit.html --- a/app/templates/projrev/proposal/submit.html Thu Aug 06 12:17:29 2009 +0530 +++ b/app/templates/projrev/proposal/submit.html Thu Aug 06 18:15:57 2009 +0530 @@ -4,14 +4,32 @@

Submit your proposal

- -

Fill up the form below, and upload your proposal file by clicking on Browse.

+ + {% if created_now %} +

An MICR Code has been assigned and e-mailed to you. Please remember it for future reference.

+ {% else %}{% if micr_code %} +

Edit your details and upload new version of the proposal in the form below.

+ {% else %} +

Fill up the form below, and upload your proposal file by clicking on Browse.

+ {% endif %}{% endif %}

- {{ form.as_p }} -
- + {{ form.as_p }} + {% if proposal_path %} +

+ + {{ proposal_name }} +

+ {% endif %} + {% if micr_code %} +

+ + +

+ {% endif %} +
+

diff -r 252a2d9713a5 -r 8d9da911ed7d app/urls.py --- a/app/urls.py Thu Aug 06 12:17:29 2009 +0530 +++ b/app/urls.py Thu Aug 06 18:15:57 2009 +0530 @@ -21,7 +21,10 @@ (r'^create_account/$', 'app.projrev.views.login.create_account'), (r'^forgot_password/$', 'app.projrev.views.login.forgot_password'), (r'^logout/$', 'app.projrev.views.login.logout_view'), - (r'^proposal/submit/$', 'app.projrev.views.proposal.submit'), + (r'^proposal/submit/$', 'app.projrev.views.proposal.getMicr'), + (r'^proposal/submit/create/$', 'app.projrev.views.proposal.submit'), + (r'^proposal/withdraw/(?P[A-Z]{6}\d{9})/$', + 'app.projrev.views.proposal.withdraw'), (r'^proposal/submit/(?P[A-Z]{6}\d{9})/$', 'app.projrev.views.proposal.submit'), (r'^proposal/review/$', 'app.projrev.views.proposal.review'),