Skip to content

Commit 79f41f9

Browse files
committed
[Update]Initial commit
0 parents  commit 79f41f9

Some content is hidden

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

64 files changed

+1838
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.log
2+
*.pot
3+
*.pyc
4+
__pycache__/
5+
local_settings.py
6+
db.sqlite3
7+
*.python
8+
/media
9+
/static
10+
/venv

Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM python:3.6
2+
LABEL maintainer="[email protected]"
3+
4+
ENV PYTHONUNBUFFERED 1
5+
ENV DJANGO_ENV dev
6+
7+
COPY ./requirements.txt /code/requirements.txt
8+
RUN pip install -r /code/requirements.txt
9+
RUN pip install gunicorn
10+
11+
COPY . /code/
12+
WORKDIR /code/
13+
14+
RUN python manage.py migrate
15+
16+
RUN useradd wagtail
17+
RUN chown -R wagtail /code
18+
USER wagtail
19+
20+
EXPOSE 8000
21+
CMD exec gunicorn nescoder.wsgi:application --bind 0.0.0.0:8000 --workers 3

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Nescode Member's Website in Wagtail Framework

blog/__init__.py

Whitespace-only changes.

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

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

blog/migrations/0001_initial.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Generated by Django 2.0.8 on 2018-09-21 09:49
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
import wagtail.core.blocks
6+
import wagtail.core.fields
7+
import wagtail.embeds.blocks
8+
import wagtail.images.blocks
9+
10+
11+
class Migration(migrations.Migration):
12+
13+
initial = True
14+
15+
dependencies = [
16+
('wagtailimages', '0021_image_file_hash'),
17+
('wagtailcore', '0040_page_draft_title'),
18+
]
19+
20+
operations = [
21+
migrations.CreateModel(
22+
name='BlogIndex',
23+
fields=[
24+
('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')),
25+
('banner_intro', models.CharField(blank=True, max_length=50)),
26+
('introduction', models.CharField(blank=True, help_text='Text to Describe the Page', max_length=200)),
27+
('banner_image', models.ForeignKey(blank=True, help_text='Banner Image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
28+
('index_image', models.ForeignKey(blank=True, help_text='Image for Blog', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
29+
],
30+
options={
31+
'abstract': False,
32+
},
33+
bases=('wagtailcore.page',),
34+
),
35+
migrations.CreateModel(
36+
name='BlogPage',
37+
fields=[
38+
('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')),
39+
('banner_intro', models.CharField(blank=True, max_length=50)),
40+
('introduction', models.TextField(blank=True, help_text='Text to Describe the Page')),
41+
('blog_introduction', models.CharField(blank=True, max_length=500)),
42+
('blog_title', models.CharField(blank=True, max_length=255)),
43+
('body', wagtail.core.fields.StreamField([('heading_block', wagtail.core.blocks.StructBlock([('heading_text', wagtail.core.blocks.CharBlock(classname='title', required=True)), ('size', wagtail.core.blocks.ChoiceBlock(blank=True, choices=[('', 'Select a header size'), ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4')], required=False))])), ('paragraph_block', wagtail.core.blocks.RichTextBlock(icon='fa-paragraph', required=False, template='blocks/paragraph_block.html')), ('image_block', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=True)), ('caption', wagtail.core.blocks.CharBlock(required=False)), ('attribution', wagtail.core.blocks.CharBlock(required=False))])), ('block_quote', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock()), ('attribute_name', wagtail.core.blocks.CharBlock(blank=True, label='e.g. Mary Berry', required=False))])), ('embed_block', wagtail.embeds.blocks.EmbedBlock(help_text='Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks', icon='fa-s15', template='blocks/embed_block.html'))], blank=True, verbose_name='Page Body')),
44+
('date_published', models.DateField(blank=True, null=True, verbose_name='Date Article Published')),
45+
('banner_image', models.ForeignKey(blank=True, help_text='Banner Image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
46+
('blog_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
47+
],
48+
options={
49+
'abstract': False,
50+
},
51+
bases=('wagtailcore.page',),
52+
),
53+
]

blog/migrations/__init__.py

Whitespace-only changes.

blog/models.py

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
from django.db import models
2+
3+
from modelcluster.fields import ParentalKey
4+
5+
from wagtail.admin.edit_handlers import ( FieldPanel,
6+
InlinePanel,
7+
StreamFieldPanel,
8+
)
9+
from wagtail.images.edit_handlers import ImageChooserPanel
10+
from wagtail.snippets.edit_handlers import SnippetChooserPanel
11+
from wagtail.core.fields import StreamField
12+
from wagtail.core.models import Page, Orderable
13+
from wagtail.search import index
14+
15+
from home.blocks import BaseStreamBlock
16+
17+
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
18+
19+
20+
# Create your models here.
21+
class BlogPage(Page):
22+
"""
23+
Blog Details Page
24+
"""
25+
banner_image = models.ForeignKey(
26+
'wagtailimages.Image',
27+
blank=True,
28+
null=True,
29+
on_delete=models.SET_NULL,
30+
related_name='+',
31+
help_text='Banner Image'
32+
)
33+
banner_intro = models.CharField(max_length=50, blank=True)
34+
introduction = models.TextField(blank=True,
35+
help_text='Text to Describe the Page'
36+
)
37+
blog_introduction = models.CharField(max_length=500, blank=True)
38+
blog_title = models.CharField(blank=True,
39+
max_length=255
40+
)
41+
blog_image = models.ForeignKey(
42+
'wagtailimages.Image',
43+
null=True,
44+
blank=True,
45+
on_delete=models.SET_NULL,
46+
related_name='+',
47+
)
48+
body = StreamField(
49+
BaseStreamBlock(), verbose_name='Page Body',
50+
blank=True
51+
)
52+
date_published = models.DateField("Date Article Published",
53+
blank=True, null=True)
54+
55+
content_panels = Page.content_panels + [
56+
ImageChooserPanel('banner_image'),
57+
FieldPanel('banner_intro'),
58+
FieldPanel('introduction', classname='full'),
59+
FieldPanel('blog_introduction'),
60+
FieldPanel('blog_title', classname='full'),
61+
ImageChooserPanel('blog_image'),
62+
StreamFieldPanel('body'),
63+
FieldPanel('date_published'),
64+
# InlinePanel('blog_person_relationship',
65+
# label='Author',
66+
# panels=None,
67+
# min_num=1)
68+
]
69+
70+
search_fields = Page.search_fields + [
71+
index.SearchField('body'),
72+
]
73+
74+
# def author(self):
75+
# authors = [
76+
# n.people for n in self.blog_person_relationship
77+
# ]
78+
# return authors
79+
80+
# Specifies parent to BlogPage as being BlogIndexPages
81+
parent_page_types = ['BlogIndex']
82+
83+
class BlogIndex(Page):
84+
banner_image = models.ForeignKey(
85+
'wagtailimages.Image',
86+
blank=True,
87+
null=True,
88+
on_delete=models.SET_NULL,
89+
related_name='+',
90+
help_text='Banner Image'
91+
)
92+
banner_intro = models.CharField(max_length=50, blank=True)
93+
introduction = models.CharField(
94+
max_length=200,
95+
help_text='Text to Describe the Page',
96+
blank=True,
97+
)
98+
index_image = models.ForeignKey(
99+
'wagtailimages.Image',
100+
null=True,
101+
blank=True,
102+
on_delete=models.SET_NULL,
103+
related_name='+',
104+
help_text='Image for Blog'
105+
)
106+
107+
content_panels = Page.content_panels + [
108+
ImageChooserPanel('banner_image'),
109+
FieldPanel('banner_intro'),
110+
FieldPanel('introduction'),
111+
ImageChooserPanel('index_image'),
112+
]
113+
114+
# Speficies that only BlogPage objects can live under this index page
115+
subpage_types = ['BlogPage']
116+
117+
def children(self):
118+
return self.get_children().specific().live()
119+
120+
def get_context(self,request):
121+
context = super(BlogIndex, self).get_context(request)
122+
context['posts'] = BlogPage.objects.descendant_of(
123+
self).live().order_by('-date_published')
124+
125+
all_pages = BlogPage.objects.live()
126+
paginator = Paginator(all_pages,5) # 5 index per page
127+
page = request.GET.get('page')
128+
129+
try:
130+
pages = paginator.page(page)
131+
except PageNotAnInteger:
132+
# If page is not an integer, deliver first page.
133+
pages = paginator.page(1)
134+
except EmptyPage:
135+
# If page is out of range (e.g. 9999), deliver last page of results.
136+
pages = paginator.page(paginator.num_pages)
137+
138+
context['pages'] = pages
139+
140+
return context

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.

home/__init__.py

Whitespace-only changes.

home/blocks.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from wagtail.images.blocks import ImageChooserBlock
2+
from wagtail.embeds.blocks import EmbedBlock
3+
from wagtail.core.blocks import (
4+
CharBlock, ChoiceBlock, RichTextBlock, StreamBlock, StructBlock, TextBlock,
5+
)
6+
7+
8+
class ImageBlock(StructBlock):
9+
"""
10+
Custom `StructBlock` for utilizing images with associated caption and
11+
attribution data
12+
"""
13+
image = ImageChooserBlock(required=True)
14+
caption = CharBlock(required=False)
15+
attribution = CharBlock(required=False)
16+
17+
class Meta:
18+
icon = 'image'
19+
template = "blocks/image_block.html"
20+
21+
22+
class HeadingBlock(StructBlock):
23+
"""
24+
Custom `StructBlock` that allows the user to select h2 - h4 sizes for headers
25+
"""
26+
heading_text = CharBlock(classname="title", required=True)
27+
size = ChoiceBlock(choices=[
28+
('', 'Select a header size'),
29+
('h2', 'H2'),
30+
('h3', 'H3'),
31+
('h4', 'H4')
32+
], blank=True, required=False)
33+
34+
class Meta:
35+
icon = "title"
36+
template = "blocks/heading_block.html"
37+
38+
39+
class BlockQuote(StructBlock):
40+
"""
41+
Custom `StructBlock` that allows the user to attribute a quote to the author
42+
"""
43+
text = TextBlock()
44+
attribute_name = CharBlock(
45+
blank=True, required=False, label='e.g. Mary Berry')
46+
47+
class Meta:
48+
icon = "fa-quote-left"
49+
template = "blocks/blockquote.html"
50+
51+
52+
# StreamBlocks
53+
class BaseStreamBlock(StreamBlock):
54+
"""
55+
Define the custom blocks that `StreamField` will utilize
56+
"""
57+
heading_block = HeadingBlock()
58+
paragraph_block = RichTextBlock(
59+
icon="fa-paragraph",
60+
required=False,
61+
template="blocks/paragraph_block.html",
62+
63+
)
64+
image_block = ImageBlock()
65+
block_quote = BlockQuote()
66+
embed_block = EmbedBlock(
67+
help_text='Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks',
68+
icon="fa-s15",
69+
template="blocks/embed_block.html")

home/migrations/0001_initial.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
('page_ptr', models.OneToOneField(on_delete=models.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
16+
],
17+
options={
18+
'abstract': False,
19+
},
20+
bases=('wagtailcore.page',),
21+
),
22+
]
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
# Create a new homepage
21+
homepage = HomePage.objects.create(
22+
title="Home",
23+
draft_title="Home",
24+
slug='home',
25+
content_type=homepage_content_type,
26+
path='00010001',
27+
depth=2,
28+
numchild=0,
29+
url_path='/home/',
30+
)
31+
32+
# Create a site with the new homepage set as the root
33+
Site.objects.create(
34+
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+
dependencies = [
53+
('home', '0001_initial'),
54+
]
55+
56+
operations = [
57+
migrations.RunPython(create_homepage, remove_homepage),
58+
]

0 commit comments

Comments
 (0)