Skip to content

Commit 8447d7c

Browse files
committed
Initial Commit
0 parents  commit 8447d7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1043
-0
lines changed

.dockerignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Django project
2+
/media/
3+
/static/
4+
*.sqlite3
5+
6+
# Python and others
7+
__pycache__
8+
*.pyc
9+
.DS_Store
10+
*.swp
11+
/venv/
12+
/tmp/
13+
/.vagrant/
14+
/Vagrantfile.local
15+
node_modules/
16+
/npm-debug.log
17+
/.idea/
18+
.vscode
19+
coverage
20+
.python-version
21+
22+
# Distribution / packaging
23+
.Python
24+
env/
25+
build/
26+
develop-eggs/
27+
dist/
28+
downloads/
29+
eggs/
30+
.eggs/
31+
lib/
32+
lib64/
33+
parts/
34+
sdist/
35+
var/
36+
wheels/
37+
*.egg-info/
38+
.installed.cfg
39+
*.egg

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

Dockerfile

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Use an official Python runtime based on Debian 10 "buster" as a parent image.
2+
FROM python:3.8.1-slim-buster
3+
4+
# Add user that will be used in the container.
5+
RUN useradd wagtail
6+
7+
# Port used by this container to serve HTTP.
8+
EXPOSE 8000
9+
10+
# Set environment variables.
11+
# 1. Force Python stdout and stderr streams to be unbuffered.
12+
# 2. Set PORT variable that is used by Gunicorn. This should match "EXPOSE"
13+
# command.
14+
ENV PYTHONUNBUFFERED=1 \
15+
PORT=8000
16+
17+
# Install system packages required by Wagtail and Django.
18+
RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \
19+
build-essential \
20+
libpq-dev \
21+
libmariadbclient-dev \
22+
libjpeg62-turbo-dev \
23+
zlib1g-dev \
24+
libwebp-dev \
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
# Install the application server.
28+
RUN pip install "gunicorn==20.0.4"
29+
30+
# Install the project requirements.
31+
COPY requirements.txt /
32+
RUN pip install -r /requirements.txt
33+
34+
# Use /app folder as a directory where the source code is stored.
35+
WORKDIR /app
36+
37+
# Set this directory to be owned by the "wagtail" user. This Wagtail project
38+
# uses SQLite, the folder needs to be owned by the user that
39+
# will be writing to the database file.
40+
RUN chown wagtail:wagtail /app
41+
42+
# Copy the source code of the project into the container.
43+
COPY --chown=wagtail:wagtail . .
44+
45+
# Use user "wagtail" to run the build commands below and the server itself.
46+
USER wagtail
47+
48+
# Collect static files.
49+
RUN python manage.py collectstatic --noinput --clear
50+
51+
# Runtime command that executes when "docker run" is called, it does the
52+
# following:
53+
# 1. Migrate the database.
54+
# 2. Start the application server.
55+
# WARNING:
56+
# Migrating database at the same time as starting the server IS NOT THE BEST
57+
# PRACTICE. The database should be migrated manually or using the release
58+
# phase facilities of your hosting platform. This is used only so the
59+
# Wagtail instance can be started with a simple "docker run" command.
60+
CMD set -xe; python manage.py migrate --noinput; gunicorn mysite.wsgi:application

blog/__init__.py

Whitespace-only changes.
162 Bytes
Binary file not shown.
203 Bytes
Binary file not shown.

blog/__pycache__/apps.cpython-310.pyc

437 Bytes
Binary file not shown.
1.4 KB
Binary file not shown.

blog/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

blog/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BlogConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'blog'

blog/migrations/0001_initial.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 4.1.2 on 2022-10-30 06:23
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
import wagtail.fields
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
initial = True
11+
12+
dependencies = [
13+
('wagtailcore', '0077_alter_revision_user'),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='BlogIndexPage',
19+
fields=[
20+
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
21+
('intro', wagtail.fields.RichTextField(blank=True)),
22+
],
23+
options={
24+
'abstract': False,
25+
},
26+
bases=('wagtailcore.page',),
27+
),
28+
]

blog/migrations/0002_blogpage.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 4.1.2 on 2022-10-30 09:28
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
import wagtail.fields
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('wagtailcore', '0077_alter_revision_user'),
12+
('blog', '0001_initial'),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='BlogPage',
18+
fields=[
19+
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
20+
('date', models.DateField(verbose_name='Post date')),
21+
('intro', models.CharField(max_length=250)),
22+
('body', wagtail.fields.RichTextField(blank=True)),
23+
],
24+
options={
25+
'abstract': False,
26+
},
27+
bases=('wagtailcore.page',),
28+
),
29+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 4.1.2 on 2022-10-30 09:50
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('wagtailimages', '0024_index_image_file_hash'),
11+
('blog', '0002_blogpage'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='blogpage',
17+
name='caption',
18+
field=models.CharField(blank=True, max_length=250),
19+
),
20+
migrations.AddField(
21+
model_name='blogpage',
22+
name='image',
23+
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='wagtailimages.image'),
24+
),
25+
]

blog/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

blog/models.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from wagtail.models import Page
2+
from wagtail.fields import RichTextField
3+
from wagtail.admin.panels import FieldPanel
4+
from django.db import models
5+
6+
7+
class BlogIndexPage(Page):
8+
intro = RichTextField(blank=True)
9+
10+
content_panels = Page.content_panels + [
11+
FieldPanel('intro')
12+
]
13+
14+
def get_context(self, request):
15+
# Update context to include only published posts, ordered by reverse-chron
16+
context = super().get_context(request)
17+
blogpages = self.get_children().live().order_by('-first_published_at')
18+
context['blogpages'] = blogpages
19+
return context
20+
21+
class BlogPage(Page):
22+
date = models.DateField("Post date")
23+
intro = models.CharField(max_length=250)
24+
body = RichTextField(blank=True)
25+
image = models.ForeignKey(
26+
'wagtailimages.Image', on_delete=models.CASCADE, related_name='+',blank=True,null=True
27+
)
28+
caption = models.CharField(blank=True, max_length=250)
29+
30+
content_panels = Page.content_panels + [
31+
FieldPanel('date'),
32+
FieldPanel('intro'),
33+
FieldPanel('body',classname="full"),
34+
FieldPanel('image'),
35+
FieldPanel('caption'),
36+
]
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% extends "base.html" %}
2+
3+
{% load wagtailcore_tags %}
4+
5+
{% block body_class %}template-blogindexpage{% endblock %}
6+
7+
{% block content %}
8+
<h1>{{ page.title }}</h1>
9+
10+
<div class="intro">{{ page.intro|richtext }}</div>
11+
12+
{% for post in page.get_children %}
13+
<h2><a href="{% pageurl post %}">{{ post.title }}</a></h2>
14+
{{ post.specific.intro }}
15+
<a href="{% pageurl post %}">Read More</a>
16+
{% endfor %}
17+
18+
{% endblock %}

blog/templates/blog/blog_page.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% extends "base.html" %}
2+
3+
{% load wagtailcore_tags wagtailimages_tags %}
4+
5+
{% block body_class %}template-blogpage{% endblock %}
6+
7+
{% block content %}
8+
{% image page.image fill-320x240 %}
9+
<p>{{ page.caption }}</p>
10+
<h1>{{ page.title }}</h1>
11+
<p class="meta">{{ page.date }}</p>
12+
13+
<div class="intro">{{ page.intro }}</div>
14+
15+
{{ page.body|richtext }}
16+
17+
<p><a href="{{ page.get_parent.url }}">Return to blog</a></p>
18+
19+
{% endblock %}

blog/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

blog/views.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

db.sqlite3

892 KB
Binary file not shown.

home/__init__.py

Whitespace-only changes.
162 Bytes
Binary file not shown.
593 Bytes
Binary file not shown.

home/migrations/0001_initial.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
from django.db import migrations, models
3+
4+
5+
class Migration(migrations.Migration):
6+
7+
dependencies = [
8+
("wagtailcore", "0040_page_draft_title"),
9+
]
10+
11+
operations = [
12+
migrations.CreateModel(
13+
name="HomePage",
14+
fields=[
15+
(
16+
"page_ptr",
17+
models.OneToOneField(
18+
on_delete=models.CASCADE,
19+
parent_link=True,
20+
auto_created=True,
21+
primary_key=True,
22+
serialize=False,
23+
to="wagtailcore.Page",
24+
),
25+
),
26+
],
27+
options={
28+
"abstract": False,
29+
},
30+
bases=("wagtailcore.page",),
31+
),
32+
]
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# -*- coding: utf-8 -*-
2+
from django.db import migrations
3+
4+
5+
def create_homepage(apps, schema_editor):
6+
# Get models
7+
ContentType = apps.get_model("contenttypes.ContentType")
8+
Page = apps.get_model("wagtailcore.Page")
9+
Site = apps.get_model("wagtailcore.Site")
10+
HomePage = apps.get_model("home.HomePage")
11+
12+
# Delete the default homepage
13+
# If migration is run multiple times, it may have already been deleted
14+
Page.objects.filter(id=2).delete()
15+
16+
# Create content type for homepage model
17+
homepage_content_type, __ = ContentType.objects.get_or_create(
18+
model="homepage", app_label="home"
19+
)
20+
21+
# Create a new homepage
22+
homepage = HomePage.objects.create(
23+
title="Home",
24+
draft_title="Home",
25+
slug="home",
26+
content_type=homepage_content_type,
27+
path="00010001",
28+
depth=2,
29+
numchild=0,
30+
url_path="/home/",
31+
)
32+
33+
# Create a site with the new homepage set as the root
34+
Site.objects.create(hostname="localhost", root_page=homepage, is_default_site=True)
35+
36+
37+
def remove_homepage(apps, schema_editor):
38+
# Get models
39+
ContentType = apps.get_model("contenttypes.ContentType")
40+
HomePage = apps.get_model("home.HomePage")
41+
42+
# Delete the default homepage
43+
# Page and Site objects CASCADE
44+
HomePage.objects.filter(slug="home", depth=2).delete()
45+
46+
# Delete content type for homepage model
47+
ContentType.objects.filter(model="homepage", app_label="home").delete()
48+
49+
50+
class Migration(migrations.Migration):
51+
52+
run_before = [
53+
("wagtailcore", "0053_locale_model"),
54+
]
55+
56+
dependencies = [
57+
("home", "0001_initial"),
58+
]
59+
60+
operations = [
61+
migrations.RunPython(create_homepage, remove_homepage),
62+
]

0 commit comments

Comments
 (0)