move about into context
This commit is contained in:
parent
f129e7abb0
commit
cca5833541
6 changed files with 60 additions and 28 deletions
|
@ -14,10 +14,11 @@ from . import models
|
|||
from . import tasks
|
||||
from ..signalbot.rpc import send_reaction
|
||||
from .utils import render_to_json
|
||||
from ..utils import default_context
|
||||
|
||||
|
||||
def index(request):
|
||||
context = {"settings": settings}
|
||||
context = default_context(request)
|
||||
week, archive = models.Item.public()
|
||||
context['items'] = week
|
||||
context['archive'] = archive.exists()
|
||||
|
@ -25,7 +26,7 @@ def index(request):
|
|||
|
||||
|
||||
def archive(request):
|
||||
context = {"settings": settings}
|
||||
context = default_context(request)
|
||||
qs = models.Item.public()
|
||||
week, archive = models.Item.public()
|
||||
context['items'] = archive
|
||||
|
@ -33,7 +34,7 @@ def archive(request):
|
|||
|
||||
|
||||
def item(request, id):
|
||||
context = {"settings": settings}
|
||||
context = default_context(request)
|
||||
item = models.Item.objects.get(id=id)
|
||||
context['item'] = item
|
||||
qs = item.comments.order_by('created')
|
||||
|
|
|
@ -2,12 +2,11 @@ from django.conf import settings
|
|||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
|
||||
from . import models
|
||||
from ..utils import default_context
|
||||
|
||||
|
||||
def page(request, slug):
|
||||
page = get_object_or_404(models.Page, slug=slug)
|
||||
context = {
|
||||
'settings': settings,
|
||||
'page': page,
|
||||
}
|
||||
context = default_context(request)
|
||||
context['page'] = page
|
||||
return render(request, 'page.html', context)
|
||||
|
|
|
@ -4,6 +4,7 @@ header, footer {
|
|||
margin: auto;
|
||||
}
|
||||
header {
|
||||
width: 100%;
|
||||
a {
|
||||
color: yellow;
|
||||
text-decoration: none;
|
||||
|
@ -59,18 +60,31 @@ nav.overlay {
|
|||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
top: 42px;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
max-width: 1000px;
|
||||
margin: auto;
|
||||
background: rgb(16, 16, 16);
|
||||
opacity: 0;
|
||||
z-index: 100;
|
||||
padding: 4px;
|
||||
display: none;
|
||||
&.active {
|
||||
display: block;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,30 +18,37 @@
|
|||
<span class="burger">[=]</span> <a href="/">{{ settings.SITENAME }}</a>
|
||||
</header>
|
||||
<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 %}
|
||||
<div>You are logged in as {{ request.user.username }}</div>
|
||||
<a href="/logout/">logout</a><br>
|
||||
<a href="/logout/">logout</a>
|
||||
{% else %}
|
||||
<a href="/login/">login</a><br>
|
||||
<a href="/login/">login</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</nav>
|
||||
<style>
|
||||
</style>
|
||||
<script>
|
||||
document.querySelector('.burger').addEventListener('click', event => {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
var overlay = document.querySelector('nav.overlay')
|
||||
if (overlay.classList.contains('active')) {
|
||||
overlay.classList.remove('active')
|
||||
document.body.style.overflow = ''
|
||||
document.querySelector('.burger').innerText = '[=]'
|
||||
} else {
|
||||
overlay.classList.add('active')
|
||||
document.body.style.overflow = 'hidden'
|
||||
document.querySelector('.burger').innerText = '[x]'
|
||||
}
|
||||
document.querySelectorAll('.burger').forEach(burger => {
|
||||
burger.addEventListener('click', event => {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
var overlay = document.querySelector('nav.overlay')
|
||||
if (overlay.classList.contains('active')) {
|
||||
overlay.classList.remove('active')
|
||||
document.body.style.overflow = ''
|
||||
} else {
|
||||
overlay.classList.add('active')
|
||||
document.body.style.overflow = 'hidden'
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -7,6 +7,7 @@ import django.contrib.auth
|
|||
from django.contrib.auth import get_user_model
|
||||
|
||||
from ..item.utils import render_to_json
|
||||
from ..utils import default_context
|
||||
|
||||
from brake.decorators import ratelimit
|
||||
|
||||
|
@ -34,13 +35,13 @@ def register(request):
|
|||
response['user'] = user.username
|
||||
return render_to_json(response)
|
||||
else:
|
||||
context = {'settings': settings}
|
||||
context = default_context(request)
|
||||
return render(request, 'register.html', context)
|
||||
|
||||
|
||||
@ratelimit(method="POST", block=True, rate="5/m")
|
||||
def login(request):
|
||||
context = {'settings': settings}
|
||||
context = default_context(request)
|
||||
response = {}
|
||||
request_type = 'json'
|
||||
if request.method == "POST":
|
||||
|
|
10
app/utils.py
Normal file
10
app/utils.py
Normal 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
|
Loading…
Reference in a new issue