Merge 'redirects' app into 'pages'

pull/1/head
Luca 2 years ago
parent e8deebae0c
commit 6899b9b9f3

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

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

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

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

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

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

@ -1,3 +1,4 @@
from bs4 import BeautifulSoup
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from ...models import Page from ...models import Page
from pathlib import Path from pathlib import Path
@ -20,7 +21,13 @@ class Command(BaseCommand):
p, created = Page.objects.get_or_create(url=slug) p, created = Page.objects.get_or_create(url=slug)
if (not created) and (not options["force"]): if (not created) and (not options["force"]):
continue 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() p.save()
print(f"created new page for slug {slug}") print(f'created new page "{p.title}" for slug {slug}')

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

@ -4,10 +4,22 @@ from django.db import models
class Page(models.Model): class Page(models.Model):
REDIRECT = "redirect"
REGULAR = "regular"
KIND_CHOICES = [
(REDIRECT, "Redirect"),
(REGULAR, "Regular page"),
]
url = models.fields.SlugField(unique=True) url = models.fields.SlugField(unique=True)
content = models.TextField() content = models.TextField()
visible = models.BooleanField(default=True) 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): 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 ""
)

@ -1,11 +1,30 @@
from django.views.generic import DetailView 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 from .models import Page
# Create your views here. # Create your views here.
class PageView(DetailView): class PageView(DetailView):
template_name = "page.html"
queryset = Page.objects.filter(visible=True) queryset = Page.objects.filter(visible=True)
slug_field = "url" 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)

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

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

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

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

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

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

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

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

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

@ -17,11 +17,10 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path("", include("shiftregister.pages.urls")),
path("", include("shiftregister.metrics.urls")),
path("", include("shiftregister.app.urls")), path("", include("shiftregister.app.urls")),
path("team/", include("shiftregister.team.urls")), path("team/", include("shiftregister.team.urls")),
path("team/", include("shiftregister.signage.urls")),
path("admin/", admin.site.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")),
] ]

Loading…
Cancel
Save