from django.shortcuts import render_to_response
from django.template import RequestContext
import datetime
from django.http import Http404
from events.models import Event
from events.models import Calendar


def index(request):
    calendars = Calendar.objects.all()
    return render_to_response(
        'events/index.html',
        {'calendars': calendars},
        context_instance=RequestContext(request)
    )


def calendar_events(request, calendar_slug=None):
    events = Event.objects.filter(calendar__slug=calendar_slug).filter(end__gte=datetime.date.today()).order_by('start')
    calendars = Calendar.objects.all()
    calendar = calendars.get(slug=calendar_slug)
    if not calendar:
        raise Http404
    return render_to_response(
        'events/calendar_events.html',
        {'events': events, 'calendar': calendar, 'calendars': calendars},
        context_instance=RequestContext(request)
    )


def event_detail(request, calendar_slug=None, event_slug=None):
    calendars = Calendar.objects.all()
    try:
        event = Event.objects.get(slug=event_slug)
    except Event.DoesNotExist:
        raise Http404
    return render_to_response(
        'events/event_detail.html',
        {'event': event, 'calendars': calendars},
        context_instance=RequestContext(request)
    )

@@ -84,16 +84,61 @@
 Context%0A
+from django.core.urlresolvers import resolve%0A
 import d
@@ -301,24 +301,137 @@
 jects.all()%0A
+    current_app = resolve(request.path).namespace%0A    context = RequestContext(request, current_app=current_app)%0A
     return r
@@ -537,39 +537,23 @@
 nstance=
-RequestContext(request)
+context
 %0A    )%0A%0A
@@ -847,32 +847,145 @@
   raise Http404%0A
+    current_app = resolve(request.path).namespace%0A    context = RequestContext(request, current_app=current_app)%0A
     return rende
@@ -1137,39 +1137,23 @@
 nstance=
-RequestContext(request)
+context
 %0A    )%0A%0A
@@ -1365,24 +1365,137 @@
 ise Http404%0A
+    current_app = resolve(request.path).namespace%0A    context = RequestContext(request, current_app=current_app)%0A
     return r
@@ -1628,31 +1628,15 @@
 nce=
-RequestContext(request)
+context
 %0A   

Add current_app to context for django-cms v3 support