File diff 16b2165de7eb → fe64a26a72c0
conservancy/views.py
Show inline comments
 
import mimetypes
 

	
 
from django.conf import settings
 
from django.http import FileResponse, Http404, HttpResponseRedirect
 
from django.template.response import TemplateResponse
 
from django.http import FileResponse, Http404, HttpResponse, HttpResponseRedirect
 
from django.template import RequestContext, Template
 

	
 
from .local_context_processors import fundgoal_lookup
 

	
...
 
@@ -27,8 +27,7 @@ def index(request, *args, **kwargs):
 
    infrastructure. If it finds a file but it's not a template, it will serve
 
    the file as-is.
 
    """
 
    # The name "static" has no connection to Django staticfiles.
 
    base_path = settings.BASE_DIR / 'static'
 
    base_path = settings.BASE_DIR / 'content'
 
    path = request.path.lstrip('/')
 
    if path.endswith('/'):
 
        path += 'index.html'
...
 
@@ -43,11 +42,13 @@ def index(request, *args, **kwargs):
 
    if not is_template:
 
        return FileResponse(open(full_path, 'rb'))
 
    else:
 
        context = kwargs.copy()
 
        try:
 
            context['fundgoal'] = fundgoal_lookup(kwargs['fundraiser_sought'])
 
            kwargs['fundgoal'] = fundgoal_lookup(kwargs['fundraiser_sought'])
 
        except KeyError:
 
            pass
 
        # Maybe this should open() the template file directly so that these
 
        # don't have to be included in the global template TEMPLATES.DIRS?
 
        return TemplateResponse(request, path, context)
 
        # These template are intentionally not in the template loader path, so
 
        # we open them directly, rather than using the template loader.
 
        with open(full_path) as t:
 
            template = Template(t.read())
 
        context = RequestContext(request, kwargs)
 
        return HttpResponse(template.render(context))