2
0
Fork 0

Merge 'redirects' app into 'pages'

This commit is contained in:
Luca 2023-04-21 21:29:21 +02:00
parent e8deebae0c
commit 6899b9b9f3
23 changed files with 90 additions and 88 deletions

View File

@ -1,7 +1,7 @@
## The following requirements were added by pip freeze:
amqp==5.1.1
asgiref==3.5.0
async-timeout==4.0.2
beautifulsoup4==4.12.2
billiard==3.6.4.0
celery==5.2.6
certifi==2021.10.8
@ -12,14 +12,14 @@ click-plugins==1.1.1
click-repl==0.2.0
Deprecated==1.2.13
Django==4.0.4
git+https://github.com/kikeh/django-dynamic-preferences@375f1a54dba91f81880a86f4a44bc2c42ceab067#egg=django-dynamic-preferences
django-dynamic-preferences==1.15.0
django-phonenumber-field==6.1.0
icalendar==4.0.9
idna==3.3
kombu==5.2.4
librabbitmq==2.0.0
packaging==21.3
persisting-theory==0.2.1
persisting-theory==1.0
phonenumbers==8.12.47
prompt-toolkit==3.0.29
psycopg2-binary==2.9.3
@ -30,6 +30,7 @@ redis==4.2.2
requests==2.27.1
sentry-sdk==1.5.10
six==1.16.0
soupsieve==2.4.1
sqlparse==0.4.2
urllib3==1.26.9
vine==5.0.0

View File

@ -3,5 +3,5 @@ from django.urls import path
from . import views
urlpatterns = [
path("", views.metrics, name="metrics"),
path("metrics", views.metrics, name="metrics"),
]

View File

@ -13,7 +13,6 @@ def reimport(modeladmin, request, queryset):
@admin.register(Page)
class PageAdmin(admin.ModelAdmin):
readonly_fields = ("url",)
fields = ("url", "content", "title", "visible")
list_display = ("title", "url", "visible")
fields = ("url", "content", "title", "visible", "kind")
list_display = ("url", "title", "visible", "kind")
actions = (reimport,)

View File

@ -1,3 +1,4 @@
<title>Über diese Seite/Impressum</title>
<div class="content">
Wir speichern die folgenden Daten, wenn du dich bei uns registrierst:
<ul>

View File

@ -1,3 +1,4 @@
<title>Häufig gestellte Fragen</title>
<div class="content">
<h5 class="mb-2">Wann gibt es Schichten?</h5>
<p>

View File

@ -1 +1,2 @@
<title>Karte</title>
<h5 class="subtitle">Hier erscheint bald die Karte mit allen Schichtstandorten</h5>

View File

@ -1,3 +1,4 @@
from bs4 import BeautifulSoup
from django.core.management.base import BaseCommand, CommandError
from ...models import Page
from pathlib import Path
@ -20,7 +21,13 @@ class Command(BaseCommand):
p, created = Page.objects.get_or_create(url=slug)
if (not created) and (not options["force"]):
continue
p.content = file.read_text()
p.title = slug
soup = BeautifulSoup(file.read_text(), "html.parser")
if soup.title:
p.title = soup.title.string
soup.title.decompose()
else:
p.title = slug.title()
p.content = str(soup).strip()
p.save()
print(f"created new page for slug {slug}")
print(f'created new page "{p.title}" for slug {slug}')

View File

@ -0,0 +1,26 @@
# Generated by Django 4.0.4 on 2023-04-21 18:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("pages", "0001_initial"),
]
operations = [
migrations.AddField(
model_name="page",
name="kind",
field=models.CharField(
choices=[("redirect", "Redirect"), ("regular", "Regular page")],
default="regular",
max_length=8,
),
),
migrations.AlterField(
model_name="page",
name="title",
field=models.CharField(blank=True, max_length=200),
),
]

View File

@ -4,10 +4,22 @@ from django.db import models
class Page(models.Model):
REDIRECT = "redirect"
REGULAR = "regular"
KIND_CHOICES = [
(REDIRECT, "Redirect"),
(REGULAR, "Regular page"),
]
url = models.fields.SlugField(unique=True)
content = models.TextField()
visible = models.BooleanField(default=True)
title = models.CharField(max_length=200)
title = models.CharField(blank=True, max_length=200)
kind = models.CharField(choices=KIND_CHOICES, default=REGULAR, max_length=8)
def __str__(self):
return f"Page {self.url}"
return (
f"{self.get_kind_display()} {self.url}" + f" => {self.content}"
if self.kind == Page.REDIRECT
else ""
)

View File

@ -1,6 +1,6 @@
{% extends "base.html" %}
{% block title %}{{page.title}}{% endblock %}
{% block title %}{{ page.title }}{% endblock %}
{% block navbar %}
<div class="navbar-start">
@ -11,7 +11,7 @@
<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>
<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>

View File

@ -1,11 +1,30 @@
from django.views.generic import DetailView
from django.shortcuts import render
from django.shortcuts import redirect
from django.core.validators import URLValidator
from django.core.exceptions import ValidationError
from django.http import HttpResponseNotFound
from .models import Page
# Create your views here.
class PageView(DetailView):
template_name = "page.html"
queryset = Page.objects.filter(visible=True)
slug_field = "url"
template_name = "page.html"
def render_to_response(self, context, **response_kwargs):
page = self.object
if self.object.kind == Page.REDIRECT:
target = str(page.content)
validate_url = URLValidator()
try:
validate_url(page.content)
except ValidationError:
return HttpResponseNotFound()
return redirect(page.content, permanent=True)
return super().render_to_response(context, **response_kwargs)

View File

@ -1,6 +0,0 @@
from django.contrib import admin
from .models import Redirect
# Register your models here.
admin.site.register(Redirect)

View File

@ -1,6 +0,0 @@
from django.apps import AppConfig
class RedirectsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "shiftregister.redirects"

View File

@ -1,20 +0,0 @@
# Generated by Django 4.0.4 on 2022-05-26 13:04
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="Redirect",
fields=[
("slug", models.SlugField(primary_key=True, serialize=False)),
("target", models.URLField()),
],
),
]

View File

@ -1,11 +0,0 @@
from django.db import models
# Create your models here.
class Redirect(models.Model):
slug = models.SlugField(primary_key=True)
target = models.URLField()
def __str__(self):
return f"{self.slug} => {self.target}"

View File

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

View File

@ -1,8 +0,0 @@
from django.urls import path
from . import views
app_name = "redirects"
urlpatterns = [
path("<slug:slug>", views.redir, name="redir"),
]

View File

@ -1,9 +0,0 @@
from django.shortcuts import redirect, get_object_or_404
from .models import Redirect
# Create your views here.
def redir(request, slug):
obj = get_object_or_404(Redirect, pk=slug)
return redirect(obj.target)

View File

@ -45,7 +45,6 @@ INSTALLED_APPS = [
"shiftregister.pages.apps.PagesConfig",
"shiftregister.metrics.apps.MetricsConfig",
"shiftregister.signage.apps.SignageConfig",
"shiftregister.redirects.apps.RedirectsConfig",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",

View File

@ -4,8 +4,8 @@ from . import views
app_name = "signage"
urlpatterns = [
path("team/worklist", views.worklist, name="worklist"),
path("team/worklist/add/<int:shiftid>", views.add_teammember, name="work_add"),
path("team/worklist/remove/<int:pk>", views.remove_teammember, name="work_remove"),
path("team/terminal", views.terminal, name="terminal"),
path("worklist", views.worklist, name="worklist"),
path("worklist/add/<int:shiftid>", views.add_teammember, name="work_add"),
path("worklist/remove/<int:pk>", views.remove_teammember, name="work_remove"),
path("terminal", views.terminal, name="terminal"),
]

View File

@ -17,11 +17,10 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("", include("shiftregister.pages.urls")),
path("", include("shiftregister.metrics.urls")),
path("", include("shiftregister.app.urls")),
path("team/", include("shiftregister.team.urls")),
path("team/", include("shiftregister.signage.urls")),
path("admin/", admin.site.urls),
path("p/", include("shiftregister.pages.urls")),
path("r/", include("shiftregister.redirects.urls")),
path("metrics/", include("shiftregister.metrics.urls")),
path("", include("shiftregister.signage.urls")),
]