Generate JSON output of a fundraiser data
Allow public interface to query the fundraiser data.
This commit is contained in:
		
							parent
							
								
									6563803287
								
							
						
					
					
						commit
						9dab283774
					
				
					 2 changed files with 18 additions and 0 deletions
				
			
		|  | @ -1,2 +1,19 @@ | ||||||
| from conservancy.apps.fundgoal.models import FundraisingGoal | from conservancy.apps.fundgoal.models import FundraisingGoal | ||||||
| from django.shortcuts import get_object_or_404, render_to_response | from django.shortcuts import get_object_or_404, render_to_response | ||||||
|  | from django.http import JsonResponse | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def view(request): | ||||||
|  |     """JSON version of request | ||||||
|  |     """ | ||||||
|  |     keysForJSON = [ 'fundraiser_goal_amount', 'fundraiser_so_far_amount', 'fundraiser_donation_count', | ||||||
|  |                     'fundraiser_donation_count_disclose_threshold' ] | ||||||
|  |     GET = obj.GET | ||||||
|  |     codeNames =  [] | ||||||
|  |     if 'code_name' in GET: codeNames += GET.getlist('code_name') | ||||||
|  | 
 | ||||||
|  |     returnDict = {} | ||||||
|  |     for code in FundraisingGoal.objects.filter(fundraiser_code_name__in=codeNames): | ||||||
|  |         for kk in keysForJSON: | ||||||
|  |             returnDict[code][kk] = getattr(code, kk) | ||||||
|  |     return JsonResponse( returnDict) | ||||||
|  |  | ||||||
|  | @ -61,6 +61,7 @@ urlpatterns = patterns('', | ||||||
|     (r'^overview', 'conservancy.static.views.index'), |     (r'^overview', 'conservancy.static.views.index'), | ||||||
|     (r'^privacy-policy', 'conservancy.static.views.index'), |     (r'^privacy-policy', 'conservancy.static.views.index'), | ||||||
|     (r'^supporter', 'conservancy.static.views.index'), |     (r'^supporter', 'conservancy.static.views.index'), | ||||||
|  |     (r'^fundraiser_data', 'conservancy.fundgoal.view'), | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| # urlpatterns += url(regex  = r'^%s(?P<path>.*)$' % conservancy.settings.STATIC_URL[1:], | # urlpatterns += url(regex  = r'^%s(?P<path>.*)$' % conservancy.settings.STATIC_URL[1:], | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn