2
0
Fork 0

intial pages app with faq and about links

This commit is contained in:
Andreas (@xAndy) Zimmermann 2022-04-28 18:07:28 +02:00
parent d52461205d
commit 2b5ed73f9b
16 changed files with 160 additions and 1 deletions

View File

@ -31,6 +31,7 @@
{% endblock %}
{% block footer %}
<div class="content has-text-left"><a href="{% url 'pages:view' 'faq' %}">FAQ</a></div>
{% if DEBUG %}
Debug-Modus:
{% if helper %}

View File

View File

@ -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,)

View File

@ -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)

View File

@ -0,0 +1 @@
bla bla <b>bla!</b>

View File

@ -0,0 +1,2 @@
Brauche ich ein telefon? <br/>
ja!

View File

@ -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)),
],
),
]

View File

@ -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}"

View File

@ -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 %}

View File

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

View File

@ -0,0 +1,8 @@
from django.urls import path
from . import views
app_name = "pages"
urlpatterns = [
path("<slug>", views.PageView.as_view(), name="view"),
]

View File

@ -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"

View File

@ -38,9 +38,11 @@ ALLOWED_HOSTS = list(filter(lambda s: s != "", getenv("ALLOWED_HOSTS", "").split
# Application definition
INSTALLED_APPS = [
"dynamic_preferences",
"shiftregister.app.apps.AppConfig",
"shiftregister.importer.apps.ImporterConfig",
"shiftregister.team.apps.TeamConfig",
"shiftregister.pages.apps.PagesConfig",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
@ -48,7 +50,6 @@ INSTALLED_APPS = [
"django.contrib.messages",
"django.contrib.staticfiles",
"phonenumber_field",
"dynamic_preferences",
]
MIDDLEWARE = [

View File

@ -20,4 +20,5 @@ urlpatterns = [
path("", include("shiftregister.app.urls")),
path("team/", include("shiftregister.team.urls")),
path("admin/", admin.site.urls),
path("p/", include("shiftregister.pages.urls")),
]

View File

@ -37,6 +37,7 @@
<div class="container">
{% block footer %}
{% endblock %}
<div class="content has-text-right"><a href="{% url 'pages:view' 'about' %}">Über diese Seite/Impressum</a></div>
</div>
</footer>
<script>