From 09654a5eac60ae79d0171aa324c62bc65e50006b 2015-03-09 03:46:37 From: Bradley M. Kuhn Date: 2015-03-09 03:46:37 Subject: [PATCH] Fundraising goal lookup for template: 1st attempt This seems to be the best approach to pass a fundraising goal record to a template. While the static hack that tmarble implemented probably needs work anyway, this is probably the best way currently to interface certain general data that we seek to place on many different pages through the templates. I looked into a templatetags solution, but this seemed more straightforward and more fitting with Django principles (I think :). --- diff --git a/www/conservancy/static/views.py b/www/conservancy/static/views.py index b83b7fa31baaf97f9ef9f0e4f86c92f806731302..417666c8971fef645aa465c39f6156881b049c82 100644 --- a/www/conservancy/static/views.py +++ b/www/conservancy/static/views.py @@ -24,7 +24,7 @@ def handler404(request): def handler500(request): return handler(request, '500') -def index(request): +def index(request, *args, **kwargs): # return HttpResponse("Hello, static world: " + request.get_full_path()) path = request.get_full_path() path = path.lstrip('/') @@ -36,7 +36,7 @@ def index(request): # return HttpResponse("Sorry that's a 404: " + path) return handler404(request) template = loader.get_template(path) - context = RequestContext(request) + context = RequestContext(request, kwargs) return HttpResponse(template.render(context)) def debug(request): diff --git a/www/conservancy/urls.py b/www/conservancy/urls.py index 93d40582511030a88536d3dfe2d44143777f46c2..20f25c28d31b582417f5a983bd45f78026cb6be9 100644 --- a/www/conservancy/urls.py +++ b/www/conservancy/urls.py @@ -19,6 +19,7 @@ from django.conf.urls import patterns, url, include from django.contrib import admin +from conservancy.apps.fundgoal.models import FundraisingGoal as FundraisingGoal # import conservancy.settings from django.conf import settings @@ -36,6 +37,13 @@ handler404 = 'conservancy.static.views.handler404' admin.autodiscover() +def fundgoal_lookup(fundraiser): + try: + return FundraisingGoal.objects.get(fundraiser_code_name) + except FundraisingGoal.DoesNotExist: + # we have no object! do something + return None + urlpatterns = patterns('', (r'^$', 'conservancy.frontpage.view'), (r'^sponsors$', 'conservancy.frontpage.view'), @@ -55,7 +63,7 @@ urlpatterns = patterns('', (r'^donate', 'conservancy.static.views.index'), (r'^linux-compliance', 'conservancy.static.views.index'), (r'^members', 'conservancy.static.views.index'), - (r'^npoacct', 'conservancy.static.views.index'), + (r'^npoacct', 'conservancy.static.views.index', {'fundgoal' : fundgoal_lookup('npoacct')}), (r'^overview', 'conservancy.static.views.index'), (r'^privacy-policy', 'conservancy.static.views.index'), (r'^supporter', 'conservancy.static.views.index'),