Skip to content

Commit

Permalink
Allow static page routes to redirect to a specific url
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemaddem committed Aug 3, 2021
1 parent f1db868 commit 72a0133
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
23 changes: 23 additions & 0 deletions pages/migrations/0008_auto_20210803_1845.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.12 on 2021-08-03 22:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pages', '0007_auto_20210727_1912'),
]

operations = [
migrations.AddField(
model_name='staticpage',
name='redirects',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='staticpage',
name='url',
field=models.URLField(default=''),
),
]
2 changes: 2 additions & 0 deletions pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class StaticPage(models.Model):
slug = models.SlugField(max_length=50)
page_name = models.CharField(max_length=50, blank=False, null=False)
content = RichTextField(default='')
redirects = models.BooleanField(default=False)
url = models.URLField(max_length=200, default='')


class FrontPageSlide(models.Model):
Expand Down
7 changes: 5 additions & 2 deletions pages/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.shortcuts import render
from django.shortcuts import render, redirect

from matches.models import Match
from news.models import Post
Expand Down Expand Up @@ -55,4 +55,7 @@ def notfound(request, exception):

def static_page(request, slug):
page = get_object_or_404(StaticPage, slug=slug)
return render(request, 'pages/static.html', {'page': page})
if page.redirects:
return redirect(page.url)
else:
return render(request, 'pages/static.html', {'page': page})
8 changes: 8 additions & 0 deletions project-templates/staff/pages/create_static_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
{{ form.page_name }}
<br />

<label>Redirect to external page?</label>
{{ form.redirects }}
<br />

<label>URL for redirect</label>
{{ form.url }}
<br />

<label>Content</label>
{{ form.content }}
<br />
Expand Down

0 comments on commit 72a0133

Please sign in to comment.