summaryrefslogtreecommitdiff
path: root/blog
diff options
context:
space:
mode:
authorJonathan DeMasi <jon.demasi@colorado.edu>2020-03-02 16:11:08 -0700
committerJonathan DeMasi <jon.demasi@colorado.edu>2020-03-02 16:11:08 -0700
commit16d9e16b204718fd476e738b8cc906fb7e919b56 (patch)
treedd65127824a3ab23379ef531047d2c848b247dbc /blog
parent4872b099ccd2ddd4e6baa31b7a2b3cf391237a7a (diff)
downloadjthanio-16d9e16b204718fd476e738b8cc906fb7e919b56.tar
jthanio-16d9e16b204718fd476e738b8cc906fb7e919b56.tar.gz
jthanio-16d9e16b204718fd476e738b8cc906fb7e919b56.tar.bz2
jthanio-16d9e16b204718fd476e738b8cc906fb7e919b56.tar.lz
jthanio-16d9e16b204718fd476e738b8cc906fb7e919b56.tar.xz
jthanio-16d9e16b204718fd476e738b8cc906fb7e919b56.tar.zst
jthanio-16d9e16b204718fd476e738b8cc906fb7e919b56.zip
add blog app
Diffstat (limited to 'blog')
-rw-r--r--blog/__init__.py0
-rw-r--r--blog/admin.py3
-rw-r--r--blog/apps.py5
-rw-r--r--blog/migrations/0001_initial.py41
-rw-r--r--blog/migrations/__init__.py0
-rw-r--r--blog/models.py50
-rw-r--r--blog/templates/blog/blog_index_page.html20
-rw-r--r--blog/templates/blog/blog_post.html17
-rw-r--r--blog/tests.py3
-rw-r--r--blog/views.py3
10 files changed, 142 insertions, 0 deletions
diff --git a/blog/__init__.py b/blog/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/blog/__init__.py
diff --git a/blog/admin.py b/blog/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/blog/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/blog/apps.py b/blog/apps.py
new file mode 100644
index 0000000..7930587
--- /dev/null
+++ b/blog/apps.py
@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class BlogConfig(AppConfig):
+ name = 'blog'
diff --git a/blog/migrations/0001_initial.py b/blog/migrations/0001_initial.py
new file mode 100644
index 0000000..f01069d
--- /dev/null
+++ b/blog/migrations/0001_initial.py
@@ -0,0 +1,41 @@
+# Generated by Django 3.0.3 on 2020-03-02 22:55
+
+from django.db import migrations, models
+import django.db.models.deletion
+import wagtail.core.fields
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ('wagtailcore', '0045_assign_unlock_grouppagepermission'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='BlogIndexPage',
+ fields=[
+ ('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')),
+ ('intro', wagtail.core.fields.RichTextField(blank=True)),
+ ],
+ options={
+ 'abstract': False,
+ },
+ bases=('wagtailcore.page',),
+ ),
+ migrations.CreateModel(
+ name='BlogPost',
+ fields=[
+ ('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')),
+ ('date', models.DateField(verbose_name='Post date')),
+ ('intro', models.CharField(max_length=250)),
+ ('body', wagtail.core.fields.RichTextField(blank=True)),
+ ],
+ options={
+ 'abstract': False,
+ },
+ bases=('wagtailcore.page',),
+ ),
+ ]
diff --git a/blog/migrations/__init__.py b/blog/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/blog/migrations/__init__.py
diff --git a/blog/models.py b/blog/models.py
new file mode 100644
index 0000000..34e6e24
--- /dev/null
+++ b/blog/models.py
@@ -0,0 +1,50 @@
+from django.db import models
+from wagtail.core.models import Page, Orderable
+from wagtail.core.fields import RichTextField
+from wagtail.admin.edit_handlers import FieldPanel, InlinePanel, MultiFieldPanelfrom wagtail.search import index
+
+from modelcluster.fields import ParentalKey
+from modelcluster.contrib.taggit import ClusterTaggableManager
+from taggit.models import TaggedItemBase
+
+class BlogIndexPage(Page):
+ intro = RichTextField(blank=True)
+
+ def get_context(self, request):
+ # Update context to include only published posts, ordered by reverse-chron
+ context = super().get_context(request)
+ blogpages = self.get_children().live().order_by('-first_published_at')
+ context['blogpages'] = blogpages
+ return context
+
+ content_panels = Page.content_panels + [
+ FieldPanel('intro', classname="full")
+ ]
+
+class BlogPageTag(TaggedItemBase):
+ content_object = ParentalKey(
+ 'BlogPage',
+ related_name='tagged_items',
+ on_delete=models.CASCADE
+ )
+
+
+class BlogPost(Page):
+ date = models.DateField("Post date")
+ intro = models.CharField(max_length=250)
+ body = RichTextField(blank=True)
+ tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
+
+ search_fields = Page.search_fields + [
+ index.SearchField('intro'),
+ index.SearchField('body'),
+ ]
+
+ content_panels = Page.content_panels + [
+ MultiFieldPanel([
+ FieldPanel('date'),
+ FieldPanel('tags'),
+ ], heading="Blog information"),
+ FieldPanel('intro'),
+ FieldPanel('body'),
+ ] \ No newline at end of file
diff --git a/blog/templates/blog/blog_index_page.html b/blog/templates/blog/blog_index_page.html
new file mode 100644
index 0000000..0e9c56e
--- /dev/null
+++ b/blog/templates/blog/blog_index_page.html
@@ -0,0 +1,20 @@
+{% extends "base.html" %}
+
+{% load wagtailcore_tags %}
+
+{% block body_class %}template-blogindexpage{% endblock %}
+
+{% block content %}
+ <h1>{{ page.title }}</h1>
+
+ <div class="intro">{{ page.intro|richtext }}</div>
+
+ {% for post in blogpages %}
+ {% with post=post.specific %}
+ <h2><a href="{% pageurl post %}">{{ post.title }}</a></h2>
+ <p>{{ post.intro }}</p>
+ {{ post.body|richtext }}
+ {% endwith %}
+{% endfor %}
+
+{% endblock %} \ No newline at end of file
diff --git a/blog/templates/blog/blog_post.html b/blog/templates/blog/blog_post.html
new file mode 100644
index 0000000..bf7da56
--- /dev/null
+++ b/blog/templates/blog/blog_post.html
@@ -0,0 +1,17 @@
+{% extends "base.html" %}
+
+{% load wagtailcore_tags %}
+
+{% block body_class %}template-blogpage{% endblock %}
+
+{% block content %}
+ <h1>{{ page.title }}</h1>
+ <p class="meta">{{ page.date }}</p>
+
+ <div class="intro">{{ page.intro }}</div>
+
+ {{ page.body|richtext }}
+
+ <p><a href="{{ page.get_parent.url }}">Return to blog</a></p>
+
+{% endblock %} \ No newline at end of file
diff --git a/blog/tests.py b/blog/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/blog/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/blog/views.py b/blog/views.py
new file mode 100644
index 0000000..91ea44a
--- /dev/null
+++ b/blog/views.py
@@ -0,0 +1,3 @@
+from django.shortcuts import render
+
+# Create your views here.