Changeset - 5c4cc1e2e114
[Not reviewed]
0 11 1
Bradley Kuhn (bkuhn) - 6 years ago 2015-12-01 03:19:46
bkuhn@ebb.org
Add sitefundgoal to top level view context.

The base template now has access to the fund-raising goal that will be
displayed site-wide. The view here must provide it in the context for
access everywhere.

Furthermore, we need a local context processor to make sure it's in
context everywhere, and we have to make sure that context is properly
passed along.

This code is a bit cargo-culted in, based on what I read in various
places about adding the Request context.
12 files changed with 45 insertions and 13 deletions:
0 comments (0 inline, 0 general)
www/conservancy/apps/blog/views.py
Show inline comments
...
 
@@ -5,6 +5,7 @@ from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArc
 
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 
from conservancy.apps.staff.models import Person
 
from django.shortcuts import get_object_or_404, render_to_response
 
from django.template import RequestContext
 
from datetime import datetime
 

	
 
def OR_filter(field_name, objs):
...
 
@@ -73,7 +74,7 @@ def custom_index(request, queryset, *args, **kwargs):
 

	
 
    extra_context['blog_entries'] = blog_entries
 

	
 
    return render_to_response('blog/entry_list.html', extra_context)
 
    return render_to_response('blog/entry_list.html', extra_context, context_instance=RequestContext(request))
 

	
 
def techblog_redirect(request):
 
    """Redirect from the old 'techblog' to the new blog
...
 
@@ -112,7 +113,7 @@ def query(request):
 
                         key=last_name)
 
        tags = EntryTag.objects.all().order_by('label')
 
        return render_to_response('blog/query.html',
 
                                  {'authors': authors, 'tags': tags})
 
                                  {'authors': authors, 'tags': tags}, context_instance=RequestContext(request))
 

	
 
def relative_redirect(request, path):
 
    from django import http
www/conservancy/apps/contacts/views.py
Show inline comments
 
from django.shortcuts import render_to_response
 
from conservancy import context_processors as context_processors
 
from django.template import RequestContext
 
from django import forms
 
from conservancy.apps.contacts.models import ContactEntry
 
from django.forms import ModelForm
...
 
@@ -18,9 +20,9 @@ def subscribe(request):
 
        if form.is_valid():
 
            form.save()
 
            return render_to_response('contacts/subscribe_success.html',
 
                                      {'form': form.cleaned_data})
 
                                      {'form': form.cleaned_data}, context_instance=RequestContext(request))
 
    else:
 
        form = ContactEntryForm()
 

	
 
    return render_to_response('contacts/subscribe.html',
 
                              {'form': form})
 
                              {'form': form}, context_instance=RequestContext(request))
www/conservancy/apps/events/views.py
Show inline comments
 
# from django.views.generic.list_detail import object_list
 
from django.shortcuts import render_to_response
 
from conservancy import context_processors as context_processors
 
from django.template import RequestContext
 
from django.http import Http404, HttpResponse
 
from django.template import loader
 
from django.core.exceptions import ObjectDoesNotExist
...
 
@@ -20,7 +22,7 @@ def event_detail(request, year, slug, queryset, **kwargs):
 
        event = queryset.get(date__year=year, slug__exact=slug)
 
    except ObjectDoesNotExist:
 
        raise Http404, "Event does not exist"
 
    return render_to_response('events/event_detail.html', {'event': event})
 
    return render_to_response('events/event_detail.html', {'event': event}, context_instance=RequestContext(request))
 

	
 
def custom_index(request, queryset, *args, **kwargs):
 
    """Scrollable index of future and past events, with date index.
www/conservancy/apps/fundgoal/views.py
Show inline comments
 
from conservancy.apps.fundgoal.models import FundraisingGoal
 
from django.shortcuts import get_object_or_404, render_to_response
 
from conservancy import context_processors as context_processors
 
from django.template import RequestContext
 
from django.http import JsonResponse
 

	
 

	
www/conservancy/apps/news/views.py
Show inline comments
 
# from django.views.generic.list_detail import object_list
 
from django.views.generic import ListView
 
from django.template import RequestContext
 
from conservancy import context_processors as context_processors
 
from django.shortcuts import render_to_response
 
from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView
 
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
...
 
@@ -41,7 +43,7 @@ def listing(request, *args, **kwargs):
 
        # If page is out of range (e.g. 9999), deliver last page of results.
 
        news = paginator.page(paginator.num_pages)
 

	
 
    return render_to_response('news/pressrelease_list.html', {"news": news, "date_list" : date_list})
 
    return render_to_response('news/pressrelease_list.html', {"news": news, "date_list" : date_list}, context_instance=RequestContext(request))
 

	
 
class NewsYearArchiveView(YearArchiveView):
 
    # queryset = Article.objects.all()
www/conservancy/apps/summit_registration/views.py
Show inline comments
 
from django.shortcuts import render_to_response
 
from conservancy import context_processors as context_processors
 
from django.template import RequestContext
 
from django import forms
 
from django.template import RequestContext
 
from conervancy.apps.summit_registration.models import SummitRegistration
 

	
 
def register(request):
...
 
@@ -20,9 +23,9 @@ def register(request):
 
        if form.is_valid():
 
            form.save()
 
            return render_to_response('summit_registration/register_success.html',
 
                                      {'form': form.cleaned_data})
 
                                      {'form': form.cleaned_data}, context_instance=RequestContext(request))
 
    else:
 
        form = SummitForm()
 

	
 
    return render_to_response('summit_registration/register.html',
 
                              {'form': form})
 
                              {'form': form}, context_instance=RequestContext(request))
www/conservancy/apps/supporters/views.py
Show inline comments
 
from conservancy.apps.supporters.models import Supporter
 
from django.shortcuts import get_object_or_404, render_to_response
 
from conservancy import context_processors as context_processors
 
from django.template import RequestContext
 

	
www/conservancy/feeds.py
Show inline comments
...
 
@@ -2,7 +2,8 @@ from django.contrib.syndication.views import Feed
 
from django.utils.feedgenerator import Rss201rev2Feed 
 
from conservancy.apps.news.models import PressRelease
 
from conservancy.apps.blog.models import Entry as BlogEntry
 

	
 
from conservancy import context_processors as context_processors
 
from django.template import RequestContext
 
from django.shortcuts import render_to_response
 
from django.conf import settings
 
from datetime import datetime
...
 
@@ -255,4 +256,4 @@ def view(request):
 
    """
 

	
 
    feeds = (PressReleaseFeed, BlogFeed, OmnibusFeed)
 
    return render_to_response("feeds.html", {'feeds': feeds})
 
    return render_to_response("feeds.html", {'feeds': feeds}, context_instance=RequestContext(request))
www/conservancy/frontpage.py
Show inline comments
 
from django.shortcuts import render_to_response
 
from conservancy import context_processors as context_processors
 
from django.template import RequestContext
 
from conservancy.apps.supporters.models import Supporter as Supporter
 
from conservancy.apps.news.models import PressRelease
 
from conservancy.apps.blog.models import Entry as BlogEntry
...
 
@@ -19,4 +21,4 @@ def view(request):
 
        'supporters_count': supporters_count,
 
        'blog' : blog
 
    }
 
    return render_to_response("frontpage.html", c)
 
    return render_to_response("frontpage.html", c, context_instance=RequestContext(request))
www/conservancy/local_context_processors.py
Show inline comments
 
new file 100644
 
from conservancy.apps.fundgoal.models import FundraisingGoal as FundraisingGoal
 

	
 
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 sitefundraiser(request):
 
    return {'sitefundgoal': fundgoal_lookup('supporterrun') }
www/conservancy/sponsors.py
Show inline comments
 
from django.shortcuts import render_to_response
 
from conservancy import context_processors as context_processors
 
from django.template import RequestContext
 
from conservancy.apps.supporters.models import Supporter as Supporter
 
from datetime import datetime, timedelta
 

	
...
 
@@ -18,4 +20,4 @@ def view(request):
 
        'supporters_count' : supporters_count,
 
        'anonymous_count' : anonymous_count
 
    }
 
    return render_to_response("sponsors.html", c)
 
    return render_to_response("sponsors.html", c, context_instance=RequestContext(request))
www/conservancy/static/views.py
Show inline comments
...
 
@@ -45,10 +45,12 @@ def index(request, *args, **kwargs):
 
        return handler404(request)
 
    template = loader.get_template(path)
 

	
 
    kwargs = kwargs.copy()
 
    if kwargs.has_key('fundraiser_sought'):
 
        kwargs = kwargs.copy()
 
        kwargs['fundgoal'] = fundgoal_lookup(kwargs['fundraiser_sought'])
 

	
 
    kwargs['sitefundgoal'] = fundgoal_lookup('supporterrun')
 

	
 
    context = RequestContext(request, kwargs)
 
    return HttpResponse(template.render(context))
 

	
0 comments (0 inline, 0 general)