Added footer line.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Fri, 07 Aug 2009 03:04:57 +0530
changeset 13 684540719344
parent 12 aac4944aca52
child 14 9d720dfded68
Added footer line.
app/projrev/views/helpers/forms.py
app/projrev/views/proposal.py
app/templates/projrev/proposal/submit.html
--- a/app/projrev/views/helpers/forms.py	Fri Aug 07 01:03:56 2009 +0530
+++ b/app/projrev/views/helpers/forms.py	Fri Aug 07 03:04:57 2009 +0530
@@ -16,7 +16,7 @@
   """Creates a form for the project.
   """
 
-  document = forms.FileField()
+  document = forms.FileField(required=False)
 
   class Meta:
     # We store most of the data in Project model. So even though the
--- a/app/projrev/views/proposal.py	Fri Aug 07 01:03:56 2009 +0530
+++ b/app/projrev/views/proposal.py	Fri Aug 07 03:04:57 2009 +0530
@@ -86,34 +86,43 @@
   if prop_form.is_valid():
     cleaned_data = prop_form.cleaned_data
 
-    # Generate MICR code
-    cleaned_data['micr_code'] = '%s%s%s%d' % (
-        cleaned_data['state'], cleaned_data['district'],
-        cleaned_data['line_item'], 
-        int(time.time() * 1000) % 1000000000)
+    if micr_code:
+      project = Project.objects.get(micr_code=micr_code)
+      project.line_item = Project.getLineItem(cleaned_data['line_item'])
+      project.institution = cleaned_data['institution']
+      project.state = Project.getState(cleaned_data['state'])
+      project.district = Project.getDistrict(cleaned_data['district'])
+    else:
+      # Generate MICR code
+      cleaned_data['micr_code'] = '%s%s%s%d' % (
+          cleaned_data['state'], cleaned_data['district'],
+          cleaned_data['line_item'], 
+          int(time.time() * 1000) % 1000000000)
 
-    cleaned_data['line_item'] = Project.getLineItem(cleaned_data['line_item'])
-    cleaned_data['state'] = Project.getState(cleaned_data['state'])
-    cleaned_data['district'] = Project.getDistrict(cleaned_data['district'])
+      cleaned_data['line_item'] = Project.getLineItem(cleaned_data['line_item'])
+      cleaned_data['state'] = Project.getState(cleaned_data['state'])
+      cleaned_data['district'] = Project.getDistrict(cleaned_data['district'])
+
+      prop_form.cleaned_data = cleaned_data
 
-    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()
 
-    # 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.micr_code = cleaned_data['micr_code']
 
     project.status = 'new'
-    project.micr_code = cleaned_data['micr_code']
-    micr_code = cleaned_data['micr_code']
+    micr_code = project.micr_code
 
     project.save()
 
-    # Create a proposal for the project.
-    proposal = project.proposal_set.create(
-        document=prop_form.cleaned_data['document'], 
-        submitted_by=request.user, rev_num = 0)
+    if prop_form.cleaned_data['document']:
+      # Create a proposal for the project.
+      proposal = project.proposal_set.create(
+          document=prop_form.cleaned_data['document'], 
+          submitted_by=request.user, rev_num = 0)
 
-    proposal.save()
+      proposal.save()
 
     return HttpResponseRedirect(
         reverse('app.projrev.views.proposal.submit', args=(micr_code,)))
@@ -139,13 +148,16 @@
     prop_form = projrev_forms.ProposalForm(
         initial=initial_vals, instance=project)
 
-    proposal_path = str(
-        project.proposal_set.all().order_by('-submitted_on')[0].document)
+    proposal = project.proposal_set.all().order_by('-submitted_on')[0]
+
+    if proposal:
+      proposal_path = str(proposal.document)
 
-    proposal_name = proposal_path.split('/')[-1]
+      proposal_name = proposal_path.split('/')[-1]
 
-    context['proposal_path'] = proposal_path
-    context['proposal_name'] = proposal_name
+      context['proposal_path'] = proposal_path
+      context['proposal_name'] = proposal_name
+      context['last_submitted'] = proposal.submitted_on 
 
     if 'HTTP_REFERER' in request.META:
       referer = request.META['HTTP_REFERER'].split('/')
@@ -158,6 +170,12 @@
         context['created_now'] = True
 
     context['micr_code'] = project.micr_code
+
+    reviews = project.review_set.all().order_by('-reviewed_on')
+    if reviews:
+      context['last_reviewed'] = reviews[0].reviewed_on
+      context['nr_reviews'] = len(reviews)
+ 
   else:
     prop_form = projrev_forms.ProposalForm()
 
@@ -221,7 +239,7 @@
   if not micr_code:
     template = 'projrev/proposal/list.html'
     context = {
-        'projects': Project.objects.all(),
+        'projects': Project.objects.all().exclude(status__exact='invalid'),
         'row_url': '/proposal/review/',
         }
 
--- a/app/templates/projrev/proposal/submit.html	Fri Aug 07 01:03:56 2009 +0530
+++ b/app/templates/projrev/proposal/submit.html	Fri Aug 07 03:04:57 2009 +0530
@@ -33,10 +33,28 @@
 		</p>		
 	</form>
 				
-	<p class="post-footer align-right">					
-		<span class="comments">Reviews (5)</span>
-		<span class="date">Last reviewed: Nov 11, 2006</span>
-		<span class="date">Last submitted: Nov 11, 2006</span>	
+	<p class="post-footer align-right">
+		<span class="comments">Reviews:
+		{% if nr_reviews %}
+		  {{ nr_reviews }}
+		{% else %}
+		  (<i>None</i>)
+		{% endif %}
+		</span>
+		<span class="date">Last reviewed:
+		{% if last_reviewed %}
+      {{ last_reviewed|date:"jS F Y H:i" }}
+    {% else %}
+      (<i>Not Reviewed</i>)
+    {% endif %}
+		</span>
+		<span class="date">Last submitted:
+		{% if last_submitted %}
+      {{ last_submitted|date:"jS F Y H:i" }}
+    {% else %}
+      (<i>New Submission</i>)
+    {% endif %} 
+		</span>	
 	</p>
 				
 </div>