Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Author pages #81

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
585360f
Add model for AuthorPage.
chigby Jun 8, 2016
3fb684d
Modified templates to start integrating author pages
Jun 8, 2016
78b3f68
restore base settings
nmorduch Jun 9, 2016
d22d7d7
Converted author profile snippets to pages
Jun 9, 2016
c7d9d53
Fixed broken links to author pages everywhere
Jun 13, 2016
19c9a77
Migrate author data to new schema.
chigby Jun 13, 2016
6038fc6
Added content and rudimentary design to author pages
Jun 15, 2016
18eb987
Made this migration resilient to missing pages.
chigby Jun 16, 2016
398015d
update .gitignore to include local.py
nmorduch Jun 16, 2016
c66ef54
add dump to gitignore
nmorduch Jun 28, 2016
a7ef6f5
Removed name field and added field for portfolio link
Jul 5, 2016
aa2b690
Attempted to style author pages
Jul 5, 2016
3f354db
Modified styles
Jul 5, 2016
bbca914
Added portfolio link to author page
Jul 5, 2016
70cf43b
Improved styles
Jul 6, 2016
86f0544
Added margin to photo on xs
Jul 6, 2016
9565141
Fixed blog page link and made image a link as well
Jul 6, 2016
17c0b07
Removed unnecessary CSS
Jul 6, 2016
658f7d6
Added space between media links
Jul 6, 2016
a88b684
Removed media links from blog author bio
Jul 6, 2016
0f943a7
Changed blog author bio images back to circles
Jul 6, 2016
4aba75d
Added banner images to author pages
Jul 6, 2016
70656bf
Added banner images migration
Jul 7, 2016
1795430
Added migration for removing name field from author pages
Jul 7, 2016
48a06c9
Merge pull request #84 from littleweaver/fix-82/banner-images
nmorduch Jul 27, 2016
fce8134
Make migrations work
nmorduch Jul 27, 2016
49b80b0
Migration was missing in last commit
nmorduch Jul 27, 2016
db5e4ff
minor design changes re authors
nmorduch Aug 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ db.sqlite3
/media/
/pillar/
*.pyc
littleweaverweb/settings/local.py
*.dump
88 changes: 88 additions & 0 deletions core/migrations/0046_author_pages_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from __future__ import unicode_literals

from django.utils.text import slugify
from django.db import migrations, models
import django.db.models.deletion
import wagtail.wagtailcore.fields


def migrate_data(apps, schema_editor):
from core.models import AuthorPage, AboutPage

BlogPage = apps.get_model("core", "BlogPage")
AuthorProfile = apps.get_model("core", "AuthorProfile")
try:
about_page = AboutPage.objects.get()
except (AboutPage.DoesNotExist, AboutPage.MultipleObjectsReturned):
# we can only programmatically migrate this data if there is
# exactly one about page
return

for snippet in AuthorProfile.objects.all():
page = AuthorPage(name=snippet.name,
title=snippet.name,
slug=slugify(snippet.name),
picture_id=snippet.picture.pk,
bio=snippet.bio,
is_member=snippet.is_member,
twitter_username=snippet.twitter_username,
github_username=snippet.github_username)
about_page.add_child(instance=page)
BlogPage.objects.filter(author_old=snippet).update(author=page)


class Migration(migrations.Migration):

# Not sure what the dependency should be for this...
# Probably fill in with the last most recent migration file?
dependencies = [
('core', '0045_auto_20160519_2307'),
]

operations = [
# Creates the AuthorPage in the database
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')),
('name', models.CharField(max_length=100)),
('bio', wagtail.wagtailcore.fields.RichTextField(blank=True)),
('is_member', models.BooleanField(default=False)),
('twitter_username', models.CharField(blank=True, max_length=15)),
('github_username', models.CharField(blank=True, max_length=30)),
('picture', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),

# Rename BlogPage.author to BlogPage.author_old
migrations.RenameField(
model_name='BlogPage',
old_name='author',
new_name='author_old',
),

# Create a new field in BlogPage called author, linked to AuthorPage
migrations.AddField(
model_name='BlogPage',
name='author',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.AuthorPage'),
),

# migrates AuthorProfileData to the AuthorPage
migrations.RunPython(migrate_data),

# Delete the BlogPage.author_old field
migrations.RemoveField(
model_name='BlogPage',
name='author_old',
),

# Delete AuthorProfile
migrations.DeleteModel(
name='AuthorProfile',
),
]
58 changes: 31 additions & 27 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.db import models

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
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
Expand Down Expand Up @@ -160,6 +162,32 @@ class WorkPage(Page):
], "Teaser Details"),
]

class AuthorPage(Page):
picture = models.ForeignKey("wagtailimages.Image", blank=True, null=True,
on_delete=models.SET_NULL, related_name='+')
bio = RichTextField(blank=True)
is_member = models.BooleanField(default=False)
name = models.CharField(max_length=200, blank=True)
twitter_username = models.CharField(max_length=15, blank=True)
github_username = models.CharField(max_length=30, blank=True)
# portfolio_link = models.CharField(max_length=50, blank=True)
# banner_image = models.ForeignKey("wagtailimages.Image", null=True, blank=True,
# on_delete=models.SET_NULL)

content_panels = Page.content_panels + [
ImageChooserPanel('picture'),
FieldPanel('bio'),
FieldPanel('is_member'),
FieldPanel('twitter_username'),
FieldPanel('github_username'),
# FieldPanel('portfolio_link'),
# ImageChooserPanel('banner_image'),
]

def get_context(self, request):
context = super(AuthorPage, self).get_context(request)
context['blog_entries'] = BlogPage.objects.filter(author=self)
return context

class AboutPage(Page):
body = RichTextField()
Expand All @@ -173,7 +201,7 @@ class AboutPage(Page):

def get_context(self, request):
context = super(AboutPage, self).get_context(request)
context['members'] = AuthorProfile.objects.filter(is_member=True).order_by('?')
context['members'] = AuthorPage.objects.filter(is_member=True).order_by('?')
return context


Expand Down Expand Up @@ -228,9 +256,8 @@ class TechnologySection(Orderable):
class BlogPageTag(TaggedItemBase):
content_object = ParentalKey('core.BlogPage', related_name='tagged_items')


class BlogPage(Page):
author = models.ForeignKey('core.AuthorProfile', null=True, blank=True,
author = models.ForeignKey('core.AuthorPage', null=True, blank=True,
on_delete=models.SET_NULL,)
publication_date = models.DateField(
help_text="Past or future date of publication")
Expand All @@ -252,7 +279,7 @@ class BlogPage(Page):
related_name="+")

content_panels = Page.content_panels + [
SnippetChooserPanel('author'),
PageChooserPanel('author'),
FieldPanel('publication_date'),
FieldPanel('summary'),
StreamFieldPanel('body'),
Expand Down Expand Up @@ -300,29 +327,6 @@ def get_context(self, request):
return context


@register_snippet
class AuthorProfile(models.Model):
name = models.CharField(max_length=100)
picture = models.ForeignKey("wagtailimages.Image", blank=True, null=True,
on_delete=models.SET_NULL, related_name='+')
bio = RichTextField(blank=True)
is_member = models.BooleanField(default=False)
twitter_username = models.CharField(max_length=15, blank=True)
github_username = models.CharField(max_length=30, blank=True)

panels = [
FieldPanel('name'),
ImageChooserPanel('picture'),
FieldPanel('bio'),
FieldPanel('is_member'),
FieldPanel('twitter_username'),
FieldPanel('github_username'),
]

def __str__(self): # __unicode__ on Python 2
return self.name


class EmailFormField(AbstractFormField):
page = ParentalKey('EmailFormPage', related_name='form_fields')

Expand Down
6 changes: 6 additions & 0 deletions core/static/css/modules/_base.sass
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ h1, h2, h3, h4, h5, h6
font-weight: $normal
color: $black-almost


.lead--except-sm
@extend .lead
+media-breakpoint-only(sm)
font-size: inherit

// Sticky Footer (https://getbootstrap.com/examples/sticky-footer/)
html
position: relative
Expand Down
4 changes: 4 additions & 0 deletions core/static/css/modules/_margins.sass
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
.m-r-1-sm-only
+media-breakpoint-only(sm)
margin-right: 1*$spacer-x

.m-b-2-xs-down
+media-breakpoint-only(xs)
margin-bottom: 2*$spacer-y
14 changes: 3 additions & 11 deletions core/templates/core/_blog_author_bio.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@
{% load wagtailcore_tags %}

<h4>
{{ page.author.name }}
{% if page.author.github_username or page.author.twitter_username %}
<small class="m-l-1">
{% if page.author.github_username %}
<a href="http://github.com/{{ page.author.github_username }}" class="link-no-underline fa fa-fw fa-github" title="Github profile"></a>
{% endif %}
{% if page.author.twitter_username %}
<a href="http://twitter.com/{{ page.author.twitter_username }}" class="link-no-underline fa fa-fw fa-twitter" title="Twitter profile"></a>
{% endif %}
</small>
{% endif %}
<a href="/about/{{ page.author.slug }}">
{{ page.author.title }}
</a>
</h4>
{% if page.author.bio %}
{{ page.author.bio|richtext }}
Expand Down
6 changes: 4 additions & 2 deletions core/templates/core/_blog_summary_text.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ <h2 class="blog-post-title card-title">
<div class="blog-post-byline-dateline m-b-1">
<span class="color-black-almost">
{% if entry.author %}
{{ entry.author.name }}
<a href="/about/{{ entry.author.slug }}">
{{ entry.author.title }}
</a>
{% endif %}
</span>
<span class="dateline">
<time datetime="{{ entry.publication_date|date:"c" }}">{{ entry.publication_date|date:"N n, Y" }}</time>
</span>
</div>
</header>
<div class="entry-summary">
<div class="m-b-1">
{{ entry.summary }}
</div>
<footer>
Expand Down
11 changes: 9 additions & 2 deletions core/templates/core/about_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ <h1 class="text-xs-center m-b-3">Our Team</h1>
<div class="grid-md-3 grid-sm-2">
{% for member in members %}
<div class="grid-item m-b-3">
{% if member.picture %}{% image member.picture fill-500x500 class="img-fluid img-circle" %}{% endif %}
<h3 class="text-xs-center m-t-1 color-gray">{{ member.name }}</h3>
{% if member.picture %}
<a href="/about/{{ member.slug }}">
{% image member.picture fill-500x500 class="img-fluid img-circle" %}{% endif %}
</a>
<h3 class="text-xs-center m-t-1">
<a href="/about/{{ member.slug }}" class="color-gray">
{{ member.title }}
</a>
</h3>
</div>
{% endfor %}
</div>
Expand Down
51 changes: 51 additions & 0 deletions core/templates/core/author_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% extends "core/layouts/small_header.html" %}
{% load wagtailcore_tags wagtailimages_tags %}

{% block main %}

{% image page.banner_image fill-1650x500 as banner_image %}
<div class="banner-image" style="background-image:url({{ banner_image.url }});background-position:top center;">
<div class="container banner-image-text">
<h1 class="color-white">{{ page.title }}</h1>
</div>
</div>

<div class="pane--light-gray p-y-3">
<div class="container">
<div class="col-sm-4 col-sm-push-8 col-md-3 col-md-push-7 m-b-2-xs-down">
{% image page.picture fill-500x500 class="img-fluid img-circle" %}
</div>
<div class="col-sm-8 col-sm-pull-4 col-md-5 col-md-offset-2 col-md-pull-3">
<div class="lead--except-sm">
{{ page.bio|richtext }}
</div>
<ul class="list-inline">
{% if page.github_username %}
<li class="list-inline-item m-r-2"><a href="http://github.com/{{ page.github_username }}" class="link-no-underline" title="Github profile">Github</a></li>
{% endif %}
{% if page.twitter_username %}
<li class="list-inline-item m-r-2"><a href="http://twitter.com/{{ page.twitter_username }}" class="link-no-underline" title="Twitter profile">Twitter</a></li>
{% endif %}
{% if page.portfolio_link %}
<li class="list-inline-item m-r-2"><a href="{{ page.portfolio_link }}" class="link-no-underline" title="Portfolio">Portfolio</a></li>
{% endif %}
</ul>
</div>
</div>
</div>

<div class="container p-y-3">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1>Blog Entries</h1>

{% for entry in blog_entries %}
<div class="m-t-3">
{% include "core/_blog_summary_text.html" %}
</div>
{% endfor %}
</div>
</div>
</div>

{% endblock %}
8 changes: 6 additions & 2 deletions core/templates/core/blog_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ <h1 class="color-black-almost">{{ page.title }}</h1>
<div>
<span class="color-black-almost">
{% if page.author %}
{{ page.author.name }}
<a href="/about/{{ page.author.slug }}">
{{ page.author.title }}
</a>
{% endif %}
</span>
<span class="dateline">
Expand Down Expand Up @@ -58,7 +60,9 @@ <h1 class="color-black-almost">{{ page.title }}</h1>
<div class="media-left p-r-1">
{% if page.author.picture %}
{% image page.author.picture fill-150x150 as author_image %}
<img src="{{ author_image.url }}" alt="{{ page.author.picture.title }}" width=100 height=100 class="media-object img-circle"/>
<a href="/about/{{ page.author.slug }}">
<img src="{{ author_image.url }}" alt="{{ page.author.picture.title }}" width=100 class="img-circle media-object"/>
</a>
{% endif %}
</div>
<div class="media-body">
Expand Down