added set_session, made hide_header work properly

This commit is contained in:
iou1name 2018-08-10 13:06:33 -04:00
parent 0f141f3525
commit abecc430a9
11 changed files with 53 additions and 8 deletions

View File

@ -1,36 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% endblock %} - Titivillus</title>
<link rel="stylesheet" type="text/css" href="{{ static('base.css') }}">
<script>
function toggleHeaderCookie(state) {
let xhr = new XMLHttpRequest();
xhr.open('GET', '{# url_for(".set_session", hide_header="on") #}', true);
xhr.send();
xhr.open('POST', '{{ url("set_session:index") }}', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('X-CSRFToken', '{{ csrf_token }}');
xhr.send('hide_header=' + state);
}
function toggleHeader() {
if (document.getElementById('header').style.display == 'initial') {
document.getElementById('header').style.display = 'none';
document.getElementById('headerHidden').style.display = 'initial';
//toggleHeaderCookie('on');
toggleHeaderCookie('on');
}
else {
document.getElementById('header').style.display = 'initial';
document.getElementById('headerHidden').style.display = 'none';
//toggleHeaderCookie('off');
toggleHeaderCookie('off');
}
}
</script>
{% block head %}{% endblock %}
</head>
<body>
<ul id="header" class="header" style="{# if session.get("hide_header") == True %}display:none;{% else %}display:initial;{% endif #}">
<ul id="header" class="header" style="{% if request.session.get("hide_header") == True %}display:none;{% else %}display:initial;{% endif %}">
<li><a onclick="toggleHeader();" href="javascript:void(0);"></a></li>
<li><a href="{{ url('homepage:index') }}">Home</a></li>
{% block header %}{% endblock %}
</ul>
<ul id="headerHidden" class="header" style="{# if session.get("hide_header") == True %}display:initial;{% else #}display:none;{# endif #}">
<ul id="headerHidden" class="header" style="{% if request.session.get("hide_header") == True %}display:initial;{% else %}display:none;{% endif %}">
<li><a onclick="toggleHeader();" href="javascript:void(0);"></a></li>
</ul>
<div id="content">{% block content %}{% endblock %} </div>

0
set_session/__init__.py Normal file
View File

3
set_session/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
set_session/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class SetSessionConfig(AppConfig):
name = 'set_session'

View File

3
set_session/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
set_session/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

12
set_session/urls.py Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env python3
"""
set_session app URL configuration.
"""
from django.urls import path
from . import views
app_name = 'set_session'
urlpatterns = [
path('', views.index, name='index'),
]

15
set_session/views.py Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python3
"""
/set_session app views.
"""
from django.http import HttpResponse
def index(request):
"""
A simple API endpoint for setting certain values in the users session.
"""
if request.POST.get('hide_header') == 'on':
request.session['hide_header'] = True
elif request.POST.get('hide_header') == 'off':
request.session['hide_header'] = False
return HttpResponse('true')

View File

@ -10,4 +10,5 @@ urlpatterns = [
path('admin/', admin.site.urls),
path('quest/', include('quest.urls')),
path('create_quest/', include('create_quest.urls')),
path('set_session/', include('set_session.urls')),
]