Titivillus/set_session/views.py

22 lines
498 B
Python

#!/usr/bin/env python3
"""
/set_session app views.
"""
from django.http import HttpResponse
from django.views.decorators.http import require_POST
@require_POST
def index(request):
"""
A simple API endpoint for setting certain values in the users session.
"""
for key, value in request.POST.items():
if key not in ['hide_header', 'hide_chat']:
continue
if value == 'on':
request.session[key] = True
elif value == 'off':
request.session[key] = False
return HttpResponse('true')