-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
441 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Module for secret pages application.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Module for admin configuration for the secret pages application.""" | ||
|
||
from django.contrib import admin | ||
from secret_pages.models import SecretPage | ||
|
||
|
||
class SecretPageAdmin(admin.ModelAdmin): | ||
"""Configuration for displaying secret pages in admin.""" | ||
|
||
list_display = ('name', 'active', 'slug', 'template') | ||
ordering = ('name', 'active', 'slug', 'template') | ||
|
||
|
||
admin.site.register(SecretPage, SecretPageAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""Application configuration for secret pages application.""" | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class SecretPagesAppConfig(AppConfig): | ||
"""Application configuration for secret pages application.""" | ||
|
||
name = 'secret_pages' | ||
verbose_name = 'Secret Pages' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 2.1.5 on 2019-09-20 13:08 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='SecretPage', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=150, unique=True)), | ||
('slug', models.SlugField(unique=True)), | ||
('template', models.CharField(help_text='File extension (.html) is not required.', max_length=300)), | ||
('active', models.BooleanField(default=False)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Migration files for secret pages application.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Models for secret pages application.""" | ||
|
||
from django.db import models | ||
from django.conf import settings | ||
from django.template.loader import get_template, TemplateDoesNotExist | ||
from django.core.exceptions import ValidationError | ||
|
||
TEMPLATE_EXTENSION = '.html' | ||
|
||
|
||
class SecretPage(models.Model): | ||
"""Model for a secret page.""" | ||
|
||
name = models.CharField( | ||
unique=True, | ||
max_length=150, | ||
) | ||
slug = models.SlugField(unique=True) | ||
template = models.CharField( | ||
max_length=300, | ||
help_text="File extension (.html) is not required." | ||
) | ||
active = models.BooleanField(default=False) | ||
|
||
def clean(self): | ||
"""Check template exists and set to full path.""" | ||
if self.template.endswith(TEMPLATE_EXTENSION): | ||
self.template = self.template[:-len(TEMPLATE_EXTENSION)] | ||
template_path = settings.SECRET_PAGES_TEMPLATE_TEMPLATE.format(self.template) | ||
try: | ||
get_template(template_path) | ||
except TemplateDoesNotExist: | ||
raise ValidationError('Template "{}" cannot be found.'.format(template_path)) | ||
|
||
def __str__(self): | ||
"""Text representation of object. | ||
Returns: | ||
Name of secret page (str). | ||
""" | ||
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""URL routing for secret_pages application.""" | ||
|
||
from django.urls import path | ||
from secret_pages import views | ||
|
||
app_name = 'secret_pages' | ||
urlpatterns = [ | ||
path('<slug:slug>/', views.secret_page_view, name='page'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Views for general application.""" | ||
|
||
from django.shortcuts import render, get_object_or_404 | ||
from django.conf import settings | ||
from secret_pages.models import SecretPage | ||
|
||
|
||
def secret_page_view(request, slug): | ||
"""View of a secret page. | ||
Args: | ||
request (Request): Request from user. | ||
slug (str): Slug captured in URL. | ||
Returns: | ||
HTTP response. | ||
""" | ||
page = get_object_or_404( | ||
SecretPage, | ||
slug=slug, | ||
active=True, | ||
) | ||
template = settings.SECRET_PAGES_TEMPLATE_TEMPLATE.format(page.template) | ||
return render(request, template) |
Oops, something went wrong.