Changeset - 09654a5eac60
[Not reviewed]
0 2 0
Bradley Kuhn (bkuhn) - 9 years ago 2015-03-09 03:46:37
bkuhn@ebb.org
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 :).
2 files changed with 11 insertions and 3 deletions:
0 comments (0 inline, 0 general)
www/conservancy/static/views.py
Show inline comments
...
 
@@ -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):
www/conservancy/urls.py
Show inline comments
...
 
@@ -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'),
0 comments (0 inline, 0 general)