364 return render_to_response(template, RequestContext(request, context)) |
365 return render_to_response(template, RequestContext(request, context)) |
365 |
366 |
366 def getDistrictsForState(request): |
367 def getDistrictsForState(request): |
367 """View function that sends the districts for the given state code via AJAXy. |
368 """View function that sends the districts for the given state code via AJAXy. |
368 """ |
369 """ |
369 import json |
370 |
370 get_params = request.GET |
371 get_params = request.GET |
371 st_code = get_params['_value'] |
372 if get_params: |
372 dt_dict = Project.DISTRICT_CHOICES |
373 st_code = get_params['_value'] |
373 |
374 dt_dict = Project.DISTRICT_CHOICES |
374 # Get the Districts corresponding to the given State code. |
375 |
375 dt_names = {} |
376 # Get the Districts corresponding to the given State code. |
376 count = 1 |
377 dt_names = {} |
377 for dt_code in dt_dict: |
378 count = 1 |
378 if dt_code[:2] == st_code: |
379 for dt_code in dt_dict: |
379 dt_names[dt_code] = dt_dict[dt_code] |
380 if dt_code[:2] == st_code: |
380 count += 1 |
381 dt_names[dt_code] = dt_dict[dt_code] |
381 |
382 count += 1 |
382 # Sort the List based on District Name. |
383 |
383 dt_send = [{'': "---------" }] |
384 # Sort the List based on District Name. |
384 dt_names_sorted = sorted(dt_names.items(), key=lambda (k,v): (v,k)) |
385 dt_send = [{'': "---------" }] |
385 for dt_code, dt_name in dt_names_sorted: |
386 dt_names_sorted = sorted(dt_names.items(), key=lambda (k,v): (v,k)) |
386 dt_send.append({dt_code: dt_name}) |
387 for dt_code, dt_name in dt_names_sorted: |
387 |
388 dt_send.append({dt_code: dt_name}) |
388 return HttpResponse(json.dumps(dt_send)) |
389 |
|
390 return HttpResponse(json.dumps(dt_send)) |
|
391 |
|
392 return HttpResponse(None) |