app/projrev/views/proposal.py
changeset 38 3cb38edbe05f
parent 32 b39994cca761
child 39 e7880a8f7e04
--- a/app/projrev/views/proposal.py	Mon Aug 10 17:18:07 2009 +0530
+++ b/app/projrev/views/proposal.py	Mon Aug 10 19:38:53 2009 +0530
@@ -167,16 +167,18 @@
       prop_form = projrev_forms.ProposalForm(
           initial=initial_vals, instance=project)
 
-    proposal = project.proposal_set.all().order_by('-submitted_on')[0]
-
-    if proposal:
-      proposal_path = str(proposal.document)
+    proposals = project.proposal_set.all()
+    if proposals:
+      proposal = proposals.order_by('-submitted_on')[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
 
     if 'HTTP_REFERER' in request.META:
       referer = request.META['HTTP_REFERER'].split('/')
@@ -400,6 +402,33 @@
 
   return HttpResponse(None)
 
+def getNewDistrictsForState(request):
+  """Get initial district for state.
+  """
+
+  get_params = request.GET
+  if get_params:
+    st_code = get_params['_value']
+    dt_dict = Project.DISTRICT_CHOICES
+
+    # Get the Districts corresponding to the given State code.
+    dt_names = {}
+    count = 1
+    for dt_code in dt_dict:
+      if dt_code[:2] == st_code:
+        dt_names[dt_code] = dt_dict[dt_code]
+        count += 1
+
+    # Sort the List based on District Name.
+    dt_send = [{'': "---------"}]
+    dt_names_sorted = sorted(dt_names.items(), key=lambda (k,v): (v,k))
+    for dt_code, dt_name in dt_names_sorted:
+      dt_send.append({dt_code: dt_name})
+
+    return HttpResponse(json.dumps(dt_send))
+
+  return HttpResponse(None)
+
 @access.register('reviewer')
 @access.checkAccess
 def listMyReviews(request):