Merge 'redirects' app into 'pages'
parent
e8deebae0c
commit
6899b9b9f3
@ -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>
|
||||||
|
@ -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),
|
||||||
|
),
|
||||||
|
]
|
@ -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)
|
|
Loading…
Reference in New Issue