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 :).
This commit is contained in:
parent
0d2908ef30
commit
09654a5eac
2 changed files with 11 additions and 3 deletions
|
@ -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):
|
||||
|
|
|
@ -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'),
|
||||
|
|
Loading…
Reference in a new issue