From 09654a5eac60ae79d0171aa324c62bc65e50006b Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Sun, 8 Mar 2015 20:46:37 -0700 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 :). --- www/conservancy/static/views.py | 4 ++-- www/conservancy/urls.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/www/conservancy/static/views.py b/www/conservancy/static/views.py index b83b7fa3..417666c8 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 93d40582..20f25c28 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'),