move about into context

This commit is contained in:
j 2023-07-26 11:50:09 +02:00
parent f129e7abb0
commit cca5833541
6 changed files with 60 additions and 28 deletions

View file

@ -14,10 +14,11 @@ from . import models
from . import tasks from . import tasks
from ..signalbot.rpc import send_reaction from ..signalbot.rpc import send_reaction
from .utils import render_to_json from .utils import render_to_json
from ..utils import default_context
def index(request): def index(request):
context = {"settings": settings} context = default_context(request)
week, archive = models.Item.public() week, archive = models.Item.public()
context['items'] = week context['items'] = week
context['archive'] = archive.exists() context['archive'] = archive.exists()
@ -25,7 +26,7 @@ def index(request):
def archive(request): def archive(request):
context = {"settings": settings} context = default_context(request)
qs = models.Item.public() qs = models.Item.public()
week, archive = models.Item.public() week, archive = models.Item.public()
context['items'] = archive context['items'] = archive
@ -33,7 +34,7 @@ def archive(request):
def item(request, id): def item(request, id):
context = {"settings": settings} context = default_context(request)
item = models.Item.objects.get(id=id) item = models.Item.objects.get(id=id)
context['item'] = item context['item'] = item
qs = item.comments.order_by('created') qs = item.comments.order_by('created')

View file

@ -2,12 +2,11 @@ from django.conf import settings
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from . import models from . import models
from ..utils import default_context
def page(request, slug): def page(request, slug):
page = get_object_or_404(models.Page, slug=slug) page = get_object_or_404(models.Page, slug=slug)
context = { context = default_context(request)
'settings': settings, context['page'] = page
'page': page,
}
return render(request, 'page.html', context) return render(request, 'page.html', context)

View file

@ -4,6 +4,7 @@ header, footer {
margin: auto; margin: auto;
} }
header { header {
width: 100%;
a { a {
color: yellow; color: yellow;
text-decoration: none; text-decoration: none;
@ -59,18 +60,31 @@ nav.overlay {
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 100vh; height: 100vh;
top: 42px; top: 0;
left: 0; left: 0;
right: 0; right: 0;
padding: 0;
border: 0;
max-width: 1000px; max-width: 1000px;
margin: auto; margin: auto;
background: rgb(16, 16, 16); background: rgb(16, 16, 16);
opacity: 0; opacity: 0;
z-index: 100; z-index: 100;
padding: 4px;
display: none; display: none;
&.active { &.active {
display: block; display: flex;
flex-direction: column;
opacity: 0.9; opacity: 0.9;
} }
.about {
padding: 4px;
padding-top: 8px;
padding-bottom: 8px;
flex-grow: 1;
white-space: pre-line;
}
.user {
padding: 4px;
padding-bottom: 8px;
}
} }

View file

@ -18,30 +18,37 @@
<span class="burger">[=]</span> <a href="/">{{ settings.SITENAME }}</a> <span class="burger">[=]</span> <a href="/">{{ settings.SITENAME }}</a>
</header> </header>
<nav class="overlay"> <nav class="overlay">
<a href="/about/">about</a><br> <header>
<span class="burger">[x]</span> <a href="/">{{ settings.SITENAME }}</a>
</header>
<div class="about">
{{ about.content | safe }}
</div>
<div class="user">
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<div>You are logged in as {{ request.user.username }}</div> <div>You are logged in as {{ request.user.username }}</div>
<a href="/logout/">logout</a><br> <a href="/logout/">logout</a>
{% else %} {% else %}
<a href="/login/">login</a><br> <a href="/login/">login</a>
{% endif %} {% endif %}
</div>
</nav> </nav>
<style> <style>
</style> </style>
<script> <script>
document.querySelector('.burger').addEventListener('click', event => { document.querySelectorAll('.burger').forEach(burger => {
event.preventDefault() burger.addEventListener('click', event => {
event.stopPropagation() event.preventDefault()
var overlay = document.querySelector('nav.overlay') event.stopPropagation()
if (overlay.classList.contains('active')) { var overlay = document.querySelector('nav.overlay')
overlay.classList.remove('active') if (overlay.classList.contains('active')) {
document.body.style.overflow = '' overlay.classList.remove('active')
document.querySelector('.burger').innerText = '[=]' document.body.style.overflow = ''
} else { } else {
overlay.classList.add('active') overlay.classList.add('active')
document.body.style.overflow = 'hidden' document.body.style.overflow = 'hidden'
document.querySelector('.burger').innerText = '[x]' }
} })
}) })
</script> </script>
{% endblock %} {% endblock %}

View file

@ -7,6 +7,7 @@ import django.contrib.auth
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from ..item.utils import render_to_json from ..item.utils import render_to_json
from ..utils import default_context
from brake.decorators import ratelimit from brake.decorators import ratelimit
@ -34,13 +35,13 @@ def register(request):
response['user'] = user.username response['user'] = user.username
return render_to_json(response) return render_to_json(response)
else: else:
context = {'settings': settings} context = default_context(request)
return render(request, 'register.html', context) return render(request, 'register.html', context)
@ratelimit(method="POST", block=True, rate="5/m") @ratelimit(method="POST", block=True, rate="5/m")
def login(request): def login(request):
context = {'settings': settings} context = default_context(request)
response = {} response = {}
request_type = 'json' request_type = 'json'
if request.method == "POST": if request.method == "POST":

10
app/utils.py Normal file
View file

@ -0,0 +1,10 @@
from django.conf import settings
from .page.models import Page
def default_context(request):
context = {}
context['settings'] = settings
context['about'] = Page.objects.filter(slug="about").first()
return context