From 585360fceb5fa63ed3dfdc9f5162d0bf0736e541 Mon Sep 17 00:00:00 2001 From: Cameron Higby-Naquin Date: Wed, 8 Jun 2016 10:46:39 -0400 Subject: [PATCH 01/27] Add model for AuthorPage. 1. Put a slug on author profiles so they can be looked up from a url. 2. Make an author page model that dynamically fetches author information based on the url. --- core/migrations/0046_auto_20160607_2126.py | 33 ++++++++++++++++++++++ core/models.py | 15 ++++++++++ 2 files changed, 48 insertions(+) create mode 100644 core/migrations/0046_auto_20160607_2126.py diff --git a/core/migrations/0046_auto_20160607_2126.py b/core/migrations/0046_auto_20160607_2126.py new file mode 100644 index 0000000..77ed71b --- /dev/null +++ b/core/migrations/0046_auto_20160607_2126.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-07 21:26 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import wagtail.contrib.wagtailroutablepage.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0028_merge'), + ('core', '0045_auto_20160519_2307'), + ] + + operations = [ + migrations.CreateModel( + name='AuthorPage', + 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')), + ], + options={ + 'abstract': False, + }, + bases=(wagtail.contrib.wagtailroutablepage.models.RoutablePageMixin, 'wagtailcore.page'), + ), + migrations.AddField( + model_name='authorprofile', + name='slug', + field=models.CharField(max_length=20, null=True), + ), + ] diff --git a/core/models.py b/core/models.py index 1c13ddb..b610efc 100644 --- a/core/models.py +++ b/core/models.py @@ -1,9 +1,11 @@ from django.db import models +from django.shortcuts import render from django.utils.six import text_type from modelcluster.fields import ParentalKey from modelcluster.contrib.taggit import ClusterTaggableManager from taggit.models import TaggedItemBase +from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route from wagtail.contrib.settings.models import BaseSetting, register_setting from wagtail.wagtailadmin.utils import send_mail from wagtail.wagtailcore import blocks @@ -161,6 +163,17 @@ class WorkPage(Page): ] +class AuthorPage(RoutablePageMixin, Page): + + @route(r'^name/([A-Za-z]+)/$') + def author_by_name(self, request, slug): + context = super(AuthorPage, self).get_context(request) + author = AuthorProfile.objects.get(slug=slug) + context['author'] = author + context['blog_posts'] = author.blogpage_set.order_by('-publication_date').all() + return render(request, self.template, context) + + class AboutPage(Page): body = RichTextField() banner_image = models.ForeignKey("wagtailimages.Image", null=True, blank=True, @@ -303,6 +316,7 @@ def get_context(self, request): @register_snippet class AuthorProfile(models.Model): name = models.CharField(max_length=100) + slug = models.CharField(max_length=20, null=True) picture = models.ForeignKey("wagtailimages.Image", blank=True, null=True, on_delete=models.SET_NULL, related_name='+') bio = RichTextField(blank=True) @@ -312,6 +326,7 @@ class AuthorProfile(models.Model): panels = [ FieldPanel('name'), + FieldPanel('slug'), ImageChooserPanel('picture'), FieldPanel('bio'), FieldPanel('is_member'), From 3fb684df184be69d61524c434cec9a1cde9c59db Mon Sep 17 00:00:00 2001 From: Cherie Yang Date: Wed, 8 Jun 2016 15:39:14 -0400 Subject: [PATCH 02/27] Modified templates to start integrating author pages --- core/models.py | 6 ++--- core/static/css/modules/_blog.sass | 3 +++ core/templates/core/_blog_author_bio.html | 2 ++ core/templates/core/_blog_summary_text.html | 2 ++ core/templates/core/about_page.html | 6 ++++- core/templates/core/blog_page.html | 4 +++- littleweaverweb/settings/base.py | 26 +++++++-------------- 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/core/models.py b/core/models.py index b610efc..dc030c3 100644 --- a/core/models.py +++ b/core/models.py @@ -1,6 +1,6 @@ from django.db import models -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.utils.six import text_type from modelcluster.fields import ParentalKey from modelcluster.contrib.taggit import ClusterTaggableManager @@ -165,10 +165,10 @@ class WorkPage(Page): class AuthorPage(RoutablePageMixin, Page): - @route(r'^name/([A-Za-z]+)/$') + @route(r'^([A-Za-z]+)/$') def author_by_name(self, request, slug): context = super(AuthorPage, self).get_context(request) - author = AuthorProfile.objects.get(slug=slug) + author = get_object_or_404(AuthorProfile, slug=slug) context['author'] = author context['blog_posts'] = author.blogpage_set.order_by('-publication_date').all() return render(request, self.template, context) diff --git a/core/static/css/modules/_blog.sass b/core/static/css/modules/_blog.sass index 30ab612..ba6a0c1 100644 --- a/core/static/css/modules/_blog.sass +++ b/core/static/css/modules/_blog.sass @@ -4,3 +4,6 @@ border-radius: $border-radius-sm .blog-post-title font-size: $font-size-base * 2.5 + +.entry-summary + margin-bottom: 1rem \ No newline at end of file diff --git a/core/templates/core/_blog_author_bio.html b/core/templates/core/_blog_author_bio.html index cf75b2d..24b161d 100644 --- a/core/templates/core/_blog_author_bio.html +++ b/core/templates/core/_blog_author_bio.html @@ -2,7 +2,9 @@ {% load wagtailcore_tags %}

+ {{ page.author.name }} + {% if page.author.github_username or page.author.twitter_username %} {% if page.author.github_username %} diff --git a/core/templates/core/_blog_summary_text.html b/core/templates/core/_blog_summary_text.html index dd08a22..7fb3e96 100644 --- a/core/templates/core/_blog_summary_text.html +++ b/core/templates/core/_blog_summary_text.html @@ -5,7 +5,9 @@

diff --git a/core/templates/core/blog_page.html b/core/templates/core/blog_page.html index 86a515b..c092c98 100644 --- a/core/templates/core/blog_page.html +++ b/core/templates/core/blog_page.html @@ -19,7 +19,9 @@

{{ page.title }}

{% if page.author %} - {{ page.author.name }} + + {{ page.author.name }} + {% endif %}