app/projrev/views/proposal.py
changeset 39 e7880a8f7e04
parent 38 3cb38edbe05f
child 40 7f6f4b8525b8
--- a/app/projrev/views/proposal.py	Mon Aug 10 19:38:53 2009 +0530
+++ b/app/projrev/views/proposal.py	Tue Aug 11 03:38:51 2009 +0530
@@ -97,9 +97,14 @@
       project.district = Project.getDistrict(cleaned_data['district'])
     else:
       # Generate MICR code
-      cleaned_data['micr_code'] = '%s%s%d' % (
-          cleaned_data['district'], cleaned_data['line_item'], 
-          int(time.time() * 1000) % 1000000000)
+      if cleaned_data['district']:
+        cleaned_data['micr_code'] = '%s%s%d' % (
+            cleaned_data['district'], cleaned_data['line_item'], 
+            int(time.time() * 1000) % 1000000000)
+      else:
+        cleaned_data['micr_code'] = '%s%s%s%d' % (
+            cleaned_data['state'], 'NN', 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'])
@@ -279,16 +284,18 @@
   context['form'] = rev_form
   context['project'] = project
 
-  proposal = project.proposal_set.all().order_by('-submitted_on')[0]
-
-  if proposal:
-    proposal_path = str(proposal.document)
+  proposals = project.proposal_set.all().order_by('-submitted_on')
+  if proposals:
+    proposal = proposals[0]
 
-    proposal_name = proposal_path.split('/')[-1]
+    if proposal:
+      proposal_path = str(proposal.document)
 
-    context['proposal_path'] = proposal_path
-    context['proposal_name'] = proposal_name
-    context['last_submitted'] = proposal.submitted_on
+      proposal_name = proposal_path.split('/')[-1]
+
+      context['proposal_path'] = proposal_path
+      context['proposal_name'] = proposal_name
+      context['last_submitted'] = proposal.submitted_on
 
   reviews = project.review_set.all().order_by('reviewed_on')
   if reviews:
@@ -318,16 +325,18 @@
 
   project = Project.objects.get(micr_code=micr_code)
 
-  proposal = project.proposal_set.all().order_by('-submitted_on')[0]
-
-  if proposal:
-    proposal_path = str(proposal.document)
+  proposals = project.proposal_set.all().order_by('-submitted_on')
+  if proposals:
+    proposal = proposals[0]
 
-    proposal_name = proposal_path.split('/')[-1]
+    if proposal:
+      proposal_path = str(proposal.document)
 
-    context['proposal_path'] = proposal_path
-    context['proposal_name'] = proposal_name
-    context['last_submitted'] = proposal.submitted_on
+      proposal_name = proposal_path.split('/')[-1]
+
+      context['proposal_path'] = proposal_path
+      context['proposal_name'] = proposal_name
+      context['last_submitted'] = proposal.submitted_on
 
   # Get all the reviews and put them to context.
   reviews = project.review_set.all().order_by('reviewed_on')