intial pages app with faq and about links
parent
d52461205d
commit
2b5ed73f9b
@ -0,0 +1,19 @@
|
||||
from django.contrib import admin
|
||||
from .models import Page
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def reimport(modeladmin, request, queryset):
|
||||
for page in queryset:
|
||||
path = Path(__file__).resolve().parent / "default_content" / f"{page.url}.html"
|
||||
if path.exists():
|
||||
page.content = path.read_text()
|
||||
page.save()
|
||||
|
||||
|
||||
@admin.register(Page)
|
||||
class PageAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("url",)
|
||||
fields = ("url", "content", "title", "visible")
|
||||
list_display = ("title", "url", "visible")
|
||||
actions = (reimport,)
|
@ -0,0 +1,29 @@
|
||||
from django.apps import AppConfig
|
||||
from pathlib import Path
|
||||
from django.db.models.signals import post_migrate
|
||||
|
||||
|
||||
def read_pages(sender, **kwargs):
|
||||
from .models import Page
|
||||
|
||||
print("pages init")
|
||||
content_path = Path(__file__).resolve().parent / "default_content"
|
||||
for file in content_path.iterdir():
|
||||
slug = file.stem
|
||||
p, created = Page.objects.get_or_create(url=slug)
|
||||
if not created:
|
||||
continue
|
||||
p.content = file.read_text()
|
||||
p.title = slug
|
||||
p.save()
|
||||
print(f"created new page for slug {slug}")
|
||||
|
||||
|
||||
class PagesConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "shiftregister.pages"
|
||||
|
||||
def ready(self):
|
||||
# we use thios signal so our code is not called before the schema is migrated
|
||||
# and not during makemigrations/migrate
|
||||
post_migrate.connect(read_pages, sender=self)
|
@ -0,0 +1 @@
|
||||
bla bla <b>bla!</b>
|
@ -0,0 +1,2 @@
|
||||
Brauche ich ein telefon? <br/>
|
||||
ja!
|
@ -0,0 +1,31 @@
|
||||
# Generated by Django 4.0.4 on 2022-04-28 15:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Page",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("url", models.SlugField(unique=True)),
|
||||
("content", models.TextField()),
|
||||
("visible", models.BooleanField(default=True)),
|
||||
("title", models.CharField(max_length=200)),
|
||||
],
|
||||
),
|
||||
]
|
@ -0,0 +1,11 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
class Page(models.Model):
|
||||
url = models.fields.SlugField(unique=True)
|
||||
content = models.TextField()
|
||||
visible = models.BooleanField(default=True)
|
||||
title = models.CharField(max_length=200)
|
||||
|
||||
def __str__(self):
|
||||
return f"Page {self.url}"
|
@ -0,0 +1,42 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment "" %}
|
||||
this is a copy of helper_base, maybe cross-app include it or use a more leightweight template?
|
||||
{% endcomment %}
|
||||
{% block title %}{{page.title}}{% endblock %}
|
||||
|
||||
{% block navbar %}
|
||||
<div class="navbar-start">
|
||||
{% if not helper%}
|
||||
<a class="navbar-item" href="{% url 'register' %}">Anmelden</a>
|
||||
{% else %}
|
||||
{% if not helper.number_validated %}
|
||||
<p class="navbar-item has-text-danger">Bestätige deine Telefonnummer über den Link in der SMS</p>
|
||||
{% endif %}
|
||||
{% if helper.important_shift %}
|
||||
<a class="navbar-item" href="{% url 'shift' helper.important_shift.pk %}">{%if helper.important_shift.is_running%}Laufende{% else %}Nächste{% endif %} Schicht ({{ helper.important_shift.start_at|date:"H:i" }})</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="navbar-end"></div>
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
<h3 class="title">{{ page.title }}</h3>
|
||||
{% autoescape off %}
|
||||
{{page.content}}
|
||||
{% endautoescape %}
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}
|
||||
{% if DEBUG %}
|
||||
Debug-Modus:
|
||||
{% if helper %}
|
||||
<a href="{% url 'token_logout' %}">logout</a>
|
||||
<a href="{{ helper.logintoken_set.first.get_absolute_url }}">login url</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -0,0 +1,8 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = "pages"
|
||||
urlpatterns = [
|
||||
path("<slug>", views.PageView.as_view(), name="view"),
|
||||
]
|
@ -0,0 +1,9 @@
|
||||
from django.views.generic import DetailView
|
||||
from django.shortcuts import render
|
||||
from .models import Page
|
||||
|
||||
# Create your views here.
|
||||
class PageView(DetailView):
|
||||
template_name = "page.html"
|
||||
queryset = Page.objects.filter(visible=True)
|
||||
slug_field = "url"
|
Loading…
Reference in New Issue