bornhack-website/src/camps/context_processors.py

24 lines
702 B
Python
Raw Normal View History

from django.conf import settings
2016-05-06 20:33:59 +00:00
from .models import Camp
from django.utils import timezone
2016-05-06 20:33:59 +00:00
2016-12-28 23:15:13 +00:00
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)
"""
2016-12-28 23:15:13 +00:00
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'),
2016-12-28 23:15:13 +00:00
'camp': camp
}