added set_session, made hide_header work properly
This commit is contained in:
parent
0f141f3525
commit
abecc430a9
|
@ -3,7 +3,7 @@ By popular demand, I'm building a better anonkun. It doesn't do much right now t
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
Python 3.6+
|
Python 3.6+
|
||||||
PostgreSQL 10.4+
|
PostgreSQL 10.4+
|
||||||
Python packages: `django psycopg2 channels jinja2`
|
Python packages: `django psycopg2 channels jinja2`
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
|
@ -1,36 +1,39 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|
||||||
<title>{% block title %}{% endblock %} - Titivillus</title>
|
<title>{% block title %}{% endblock %} - Titivillus</title>
|
||||||
<link rel="stylesheet" type="text/css" href="{{ static('base.css') }}">
|
<link rel="stylesheet" type="text/css" href="{{ static('base.css') }}">
|
||||||
<script>
|
<script>
|
||||||
function toggleHeaderCookie(state) {
|
function toggleHeaderCookie(state) {
|
||||||
let xhr = new XMLHttpRequest();
|
let xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', '{# url_for(".set_session", hide_header="on") #}', true);
|
xhr.open('POST', '{{ url("set_session:index") }}', true);
|
||||||
xhr.send();
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||||
|
xhr.setRequestHeader('X-CSRFToken', '{{ csrf_token }}');
|
||||||
|
xhr.send('hide_header=' + state);
|
||||||
}
|
}
|
||||||
function toggleHeader() {
|
function toggleHeader() {
|
||||||
if (document.getElementById('header').style.display == 'initial') {
|
if (document.getElementById('header').style.display == 'initial') {
|
||||||
document.getElementById('header').style.display = 'none';
|
document.getElementById('header').style.display = 'none';
|
||||||
document.getElementById('headerHidden').style.display = 'initial';
|
document.getElementById('headerHidden').style.display = 'initial';
|
||||||
//toggleHeaderCookie('on');
|
toggleHeaderCookie('on');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
document.getElementById('header').style.display = 'initial';
|
document.getElementById('header').style.display = 'initial';
|
||||||
document.getElementById('headerHidden').style.display = 'none';
|
document.getElementById('headerHidden').style.display = 'none';
|
||||||
//toggleHeaderCookie('off');
|
toggleHeaderCookie('off');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
{% block head %}{% endblock %}
|
{% block head %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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 onclick="toggleHeader();" href="javascript:void(0);">⤒</a></li>
|
||||||
<li><a href="{{ url('homepage:index') }}">Home</a></li>
|
<li><a href="{{ url('homepage:index') }}">Home</a></li>
|
||||||
{% block header %}{% endblock %}
|
{% block header %}{% endblock %}
|
||||||
</ul>
|
</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>
|
<li><a onclick="toggleHeader();" href="javascript:void(0);">⤓</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div id="content">{% block content %}{% endblock %} </div>
|
<div id="content">{% block content %}{% endblock %} </div>
|
||||||
|
|
0
set_session/__init__.py
Normal file
0
set_session/__init__.py
Normal file
3
set_session/admin.py
Normal file
3
set_session/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
5
set_session/apps.py
Normal file
5
set_session/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class SetSessionConfig(AppConfig):
|
||||||
|
name = 'set_session'
|
0
set_session/migrations/__init__.py
Normal file
0
set_session/migrations/__init__.py
Normal file
3
set_session/models.py
Normal file
3
set_session/models.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
3
set_session/tests.py
Normal file
3
set_session/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
12
set_session/urls.py
Normal file
12
set_session/urls.py
Normal 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
15
set_session/views.py
Normal 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')
|
|
@ -7,7 +7,8 @@ from django.urls import include, path
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include('homepage.urls')),
|
path('', include('homepage.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('quest/', include('quest.urls')),
|
path('quest/', include('quest.urls')),
|
||||||
path('create_quest/', include('create_quest.urls')),
|
path('create_quest/', include('create_quest.urls')),
|
||||||
|
path('set_session/', include('set_session.urls')),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user