website/www/conservancy/apps/events/views.py
Bradley M. Kuhn 5c4cc1e2e1 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.
2015-11-30 19:19:46 -08:00

61 lines
2.4 KiB
Python

# 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
from conservancy.apps.events.models import Event
# for debugging...
from django.http import HttpResponse
def event_detail(request, year, slug, queryset, **kwargs):
"""This view shows event detail.
Nothing special, but it is necessary because
django.views.generic.date_based.object_detail only works with
slugs that are unique and specified by day, but we make slugs
unique by year.
"""
try:
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}, context_instance=RequestContext(request))
def custom_index(request, queryset, *args, **kwargs):
"""Scrollable index of future and past events, with date index.
"""
future_events = None
if not request.GET.has_key("page"):
future_events = Event.future.all().order_by("date")
date_list = queryset.dates(kwargs['date_field'], 'year')
kwargs = dict(kwargs, extra_context={'date_list': date_list,
'future_events': future_events})
del kwargs['date_field']
del kwargs['allow_future']
# return object_list(request, queryset, *args, **kwargs)
return HttpResponse("FIXME: events must be updated like blog and news.")
def future_event_ics(request, queryset, *args, **kwargs):
"""ICS calendar view of future events
This view just renders information into a template that looks like
an ics file. If in the future we want a 'real' implementation of
this function, there is a python 'vobject' library that can be
used. Search google for details, or see
http://www.technobabble.dk/2008/mar/06/exposing-calendar-events-using-icalendar-django/
Hopefully at some point this functionality is integrated into
django.contrib.
"""
future_events = Event.future.all().order_by("date")
return HttpResponse(loader.render_to_string('events/calendar.ics',
{'events': future_events}),
mimetype='text/calendar')