bornhack-website/camps/context_processors.py
2017-01-20 16:18:10 +01:00

24 lines
702 B
Python

from django.conf import settings
from .models import Camp
from django.utils import timezone
def camp(request):
"""
if we have a camp_slug url component then get the "current" Camp object.
Return it after adding the slug to request.session along with a "camps"
queryset containing all camps (used to build the menu and such)
"""
if 'camp_slug' in request.resolver_match.kwargs:
camp = Camp.objects.get(slug=request.resolver_match.kwargs['camp_slug'])
request.session['campslug'] = camp.slug
else:
request.session['campslug'] = None
camp = None
return {
'camps': Camp.objects.all().order_by('-camp'),
'camp': camp
}