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
...
 
@@ -21,25 +21,25 @@ def handler403(request):
 
def handler404(request):
 
    return handler(request, '404')
 

	
 
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('/')
 
    if path[-1:] == '/':
 
        path += 'index.html'
 
    STATIC_ROOT = '/home/www/website/www/conservancy/static/'
 
    fullpath = STATIC_ROOT + path
 
    if not os.path.exists(fullpath):
 
        # 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):
 
    path = request.get_full_path()
 
    path = path.lstrip('/')
 
    return HttpResponse("Hello, static world: " + path)
www/conservancy/urls.py
Show inline comments
...
 
@@ -16,12 +16,13 @@
 
# You should have received a copy of the GNU Affero General Public License
 
# along with this program in a file in the toplevel directory called
 
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
 

	
 
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
 
from conservancy.feeds import BlogFeed, PressReleaseFeed, OmnibusFeed
 
# from django.views.static import serve
 
# from django.conf.urls.static import static
...
 
@@ -33,12 +34,19 @@ from conservancy.feeds import BlogFeed, PressReleaseFeed, OmnibusFeed
 
# handler403 = 'conservancy.static.views.handler403'
 
handler404 = 'conservancy.static.views.handler404'
 
# handler500 = 'conservancy.static.views.handler500'
 

	
 
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'),
 
    (r'^sponsors/$', 'conservancy.sponsors.view'),
 
    (r'^sponsors/index.html$', 'conservancy.sponsors.view'),
 
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
...
 
@@ -52,13 +60,13 @@ urlpatterns = patterns('',
 
    # formerly static templated things... (dirs with templates)
 
    (r'^error', 'conservancy.static.views.index'),
 
    (r'^about', 'conservancy.static.views.index'),
 
    (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'),
 
)
 

	
 
# urlpatterns += url(regex  = r'^%s(?P<path>.*)$' % conservancy.settings.STATIC_URL[1:],
0 comments (0 inline, 0 general)