Changeset - ab2239009a1b
[Not reviewed]
0 2 0
Bradley Kuhn (bkuhn) - 9 years ago 2015-03-09 06:40:47
bkuhn@ebb.org
Rework again to see if I can get this corrected.
2 files changed with 14 insertions and 12 deletions:
0 comments (0 inline, 0 general)
www/conservancy/static/views.py
Show inline comments
...
 
@@ -16,42 +16,44 @@ def handler(request, errorcode):
 
def handler401(request):
 
    return handler(request, '401')
 

	
 
def handler403(request):
 
    return handler(request, '403')
 

	
 
def handler404(request):
 
    return handler(request, '404')
 

	
 
def handler500(request):
 
    return handler(request, '500')
 

	
 
def fundgoal_lookup(fundraiser_sought):
 
    try:
 
        return FundraisingGoal.objects.get(fundraiser_code_name=fundraiser_sought)
 
    except FundraisingGoal.DoesNotExist:
 
     # we have no object!  do something
 
        return None
 

	
 
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, kwargs)
 
    return HttpResponse(template.render(context))
 

	
 
def fundgoal_lookup(fundraiser_sought):
 
    try:
 
        return FundraisingGoal.objects.get(fundraiser_code_name=fundraiser_sought)
 
    except FundraisingGoal.DoesNotExist:
 
     # we have no object!  do something
 
        return None
 
    if kwargs.has_key('fundraiser_sought'):
 
        kwargs = kwargs.copy()
 
        kwargs['fundgoal'] = fundgoal_lookup(kwargs['fundraiser_sought'])
 

	
 
def index_with_fundraiser_data(request, *args, **kwargs):
 
    return index(request, { 'fundgoal' : fundgoal_lookup(kwargs['fundraiser_sought']) })
 
    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
...
 
@@ -44,28 +44,28 @@ urlpatterns = patterns('',
 
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
 
    (r'^admin/', admin.site.urls),
 
    (r'^feeds/blog/?$', BlogFeed()),
 
    (r'^feeds/news/?$', PressReleaseFeed()),
 
    (r'^feeds/omnibus/?$', OmnibusFeed()),
 
    (r'^feeds/?$', 'conservancy.feeds.view'),
 
    (r'^news(/|$)', include('conservancy.apps.news.urls')),
 
    (r'^blog(/|$)', include('conservancy.apps.blog.urls')),
 
    # 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_with_fundraiser_data',
 
    (r'^linux-compliance', 'conservancy.static.views.index',
 
                           {'fundraiser_sought' : 'vmware-match-0'}),
 
    (r'^members', 'conservancy.static.views.index'),
 
    (r'^npoacct', 'conservancy.static.views.index_with_fundraiser_data',
 
    (r'^npoacct', 'conservancy.static.views.index',
 
                  {'fundraiser_sought' : '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:],
 
# urlpatterns += url(regex  = r'^/overview',
 
#                    view   = 'django.views.static.serve',
 
#                    kwargs = {'document_root': conservancy.settings.STATIC_ROOT,
 
#                              'show_indexes' : True})
 
# urlpatterns += (r'^(?P<path>.*)$', 'django.views.static.serve', 
0 comments (0 inline, 0 general)