Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Adding and enabling Article-based Authors app.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Turner committed Sep 27, 2016
1 parent 866e5a1 commit 0eaad19
Show file tree
Hide file tree
Showing 19 changed files with 513 additions and 0 deletions.
1 change: 1 addition & 0 deletions icekit/authors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = '%s.apps.AppConfig' % __name__
17 changes: 17 additions & 0 deletions icekit/authors/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib import admin
from fluent_contents.admin import PlaceholderFieldAdmin
from icekit.articles.admin import ArticleAdminBase
from . import models


class AuthorAdmin(ArticleAdminBase, PlaceholderFieldAdmin):
"""
Administration configuration for `Author`.
"""
change_form_template = 'author/admin/change_form.html'
search_fields = ['slug', 'given_name', 'family_name']
raw_id_fields = ['portrait', ]
list_display = ArticleAdminBase.list_display + ('given_name', 'family_name')
ordering = ("family_name",)

admin.site.register(models.Author, AuthorAdmin)
5 changes: 5 additions & 0 deletions icekit/authors/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig
class AppConfig(AppConfig):
name = '.'.join(__name__.split('.')[:-1])
label = 'icekit_authors'
verbose_name = "Authors"
28 changes: 28 additions & 0 deletions icekit/authors/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import fluent_contents.extensions
import icekit.validators


class Migration(migrations.Migration):

dependencies = [
('icekit_plugins_image', '0006_auto_20160309_0453'),
]

operations = [
migrations.CreateModel(
name='Author',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('first_name', models.CharField(max_length=255)),
('last_name', models.CharField(max_length=255, blank=True)),
('slug', models.SlugField(unique=True)),
('url', models.CharField(max_length=255, help_text='The URL for the authors website.', validators=[icekit.validators.RelativeURLValidator()], blank=True)),
('introduction', fluent_contents.extensions.PluginHtmlField(help_text='An introduction about the author used on list pages.', verbose_name='introduction')),
('portrait', models.ForeignKey(null=True, blank=True, to='icekit_plugins_image.Image')),
],
),
]
40 changes: 40 additions & 0 deletions icekit/authors/migrations/0002_auto_20160831_1831.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('icekit_authors', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='author',
options={'permissions': (('can_publish', 'Can publish'),)},
),
migrations.AddField(
model_name='author',
name='publishing_is_draft',
field=models.BooleanField(db_index=True, default=True, editable=False),
),
migrations.AddField(
model_name='author',
name='publishing_linked',
field=models.OneToOneField(related_name='publishing_draft', on_delete=django.db.models.deletion.SET_NULL, editable=False, to='icekit_authors.Author', null=True),
),
migrations.AddField(
model_name='author',
name='publishing_modified_at',
field=models.DateTimeField(default=django.utils.timezone.now, editable=False),
),
migrations.AddField(
model_name='author',
name='publishing_published_at',
field=models.DateTimeField(null=True, editable=False),
),
]
24 changes: 24 additions & 0 deletions icekit/authors/migrations/0003_auto_20160901_1536.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('icekit_authors', '0002_auto_20160831_1831'),
]

operations = [
migrations.RenameField(
model_name='author',
old_name='last_name',
new_name='family_name',
),
migrations.RenameField(
model_name='author',
old_name='first_name',
new_name='given_name',
),
]
23 changes: 23 additions & 0 deletions icekit/authors/migrations/0004_auto_20160901_1743.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('icekit_authors', '0003_auto_20160901_1536'),
]

operations = [
migrations.AlterModelOptions(
name='author',
options={'ordering': ('family_name',)},
),
migrations.AlterField(
model_name='author',
name='slug',
field=models.SlugField(),
),
]
34 changes: 34 additions & 0 deletions icekit/authors/migrations/0005_authorlisting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.utils.timezone
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('icekit', '0006_auto_20150911_0744'),
('fluent_pages', '0001_initial'),
('icekit_authors', '0004_auto_20160901_1743'),
]

operations = [
migrations.CreateModel(
name='AuthorListing',
fields=[
('urlnode_ptr', models.OneToOneField(primary_key=True, auto_created=True, parent_link=True, to='fluent_pages.UrlNode', serialize=False)),
('publishing_is_draft', models.BooleanField(db_index=True, default=True, editable=False)),
('publishing_modified_at', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
('publishing_published_at', models.DateTimeField(null=True, editable=False)),
('layout', models.ForeignKey(null=True, related_name='icekit_authors_authorlisting_related', blank=True, to='icekit.Layout')),
('publishing_linked', models.OneToOneField(null=True, editable=False, related_name='publishing_draft', to='icekit_authors.AuthorListing', on_delete=django.db.models.deletion.SET_NULL)),
],
options={
'db_table': 'pagetype_icekit_authors_authorlisting',
'verbose_name': 'Author listing',
},
bases=('fluent_pages.htmlpage', models.Model),
),
]
25 changes: 25 additions & 0 deletions icekit/authors/migrations/0006_auto_20160927_1835.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('icekit_authors', '0005_authorlisting'),
]

operations = [
migrations.AddField(
model_name='author',
name='title',
field=models.CharField(max_length=255, default='Untitled'),
preserve_default=False,
),
migrations.AlterField(
model_name='author',
name='slug',
field=models.SlugField(max_length=255),
),
]
Empty file.
99 changes: 99 additions & 0 deletions icekit/authors/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""
Model declaration for the `author` app.
"""
import re
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from fluent_contents.extensions import PluginHtmlField
from fluent_contents.models import PlaceholderField
from icekit.articles.abstract_models import ListingPage, ArticleBase
from icekit.validators import RelativeURLValidator


class AuthorListing(ListingPage):
"""
Author listing page to be mounted in fluent pages page tree.
"""
class Meta:
verbose_name = 'Author listing'

def get_items(self):
"""
:return: all published authors
"""
return Author.objects.published()

def get_visible_items(self):
"""
:return: all authors that can be viewed by the current user
"""
return Author.objects.visible()


class Author(ArticleBase):
"""
An author model for use with article pages and assigning attribution.
"""
given_name = models.CharField(
max_length=255,
)

family_name = models.CharField(
max_length=255,
blank=True,
)

portrait = models.ForeignKey(
'icekit_plugins_image.Image',
blank=True,
null=True,
)

url = models.CharField(
max_length=255,
blank=True,
help_text=_('The URL for the authors website.'),
validators=[RelativeURLValidator(), ]
)

introduction = PluginHtmlField(
_('introduction'),
help_text=_('An introduction about the author used on list pages.')
)

content = PlaceholderField(
'author_content'
)

@property
def url_link_text(self):
"""
Return a cleaned-up version of the URL of an author's website,
to use as a label for a link.
TODO: make a template filter
:return: String.
"""
url_link_text = re.sub('^https?://', '', self.url)
return url_link_text.strip('/')

def contributions(self):
"""
:return: List of all content that should show for this author.
"""
return []

@property
def parent(self):
try:
return AuthorListing.objects.draft()[0]
except IndexError:
raise IndexError("You need to create a Author Listing Page")

def get_layout_template_name(self):
return "author/detail.html"

class Meta:
ordering = ('family_name', )
10 changes: 10 additions & 0 deletions icekit/authors/page_type_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from fluent_pages.extensions import page_type_pool
from icekit.page_types.layout_page.admin import LayoutPageAdmin

from icekit.articles.page_type_plugins import ListingPagePlugin
from .models import AuthorListing


@page_type_pool.register
class AuthorListingPlugin(ListingPagePlugin):
model = AuthorListing
20 changes: 20 additions & 0 deletions icekit/authors/search_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from haystack import indexes
from . import models


class AuthorIndex(indexes.SearchIndex, indexes.Indexable):
"""
Search index for `Author`.
"""
text = indexes.CharField(document=True, use_template=True)
name = indexes.CharField(model_attr='get_full_name', boost=2.0)
url = indexes.CharField(model_attr='get_absolute_url')
has_url = indexes.BooleanField(model_attr='get_absolute_url')
# We add this for autocomplete.
content_auto = indexes.EdgeNgramField(model_attr='get_full_name')

def get_model(self):
"""
Get the model for the search index.
"""
return models.Author
25 changes: 25 additions & 0 deletions icekit/authors/templates/author/admin/change_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "admin/change_form.html" %}

{% load wysiwyg %}

{% block extrahead %}

{{ block.super }}

{% wysiwyg_setup %}

{% endblock %}

{% block extrastyle %}

{{ block.super }}

{% endblock %}

{% block content %}

{{ block.super }}

{% wysiwyg_editor "id_introduction" %}

{% endblock %}
Loading

0 comments on commit 0eaad19

Please sign in to comment.