Skip to content

Commit

Permalink
CHORE: Author Pages (#1245)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbiggs authored Oct 12, 2023
1 parent 345db3b commit 338b6b0
Show file tree
Hide file tree
Showing 17 changed files with 694 additions and 41 deletions.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"etna.alerts",
"etna.analytics",
"etna.articles",
"etna.authors",
"etna.categories",
"etna.ciim",
"etna.collections",
Expand Down
1 change: 0 additions & 1 deletion etna/articles/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Meta:
class FocusedArticlePageFactory(BasePageFactory):
hero_image = factory.SubFactory(ImageFactory)
hero_image_caption = "<p>Hero image caption</p>"
author = "John Doe"

class Meta:
model = app_models.FocusedArticlePage
35 changes: 35 additions & 0 deletions etna/articles/migrations/0098_alter_focusedarticlepage_author.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.5 on 2023-09-25 10:55

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


def convert_to_foreign_key(apps, schema_editor):
FocusedArticlePage = apps.get_model("articles", "FocusedArticlePage")

for page in FocusedArticlePage.objects.all():
if page.author:
page.author = None
page.save()


class Migration(migrations.Migration):
dependencies = [
("authors", "0002_authorindexpage_authorpage_authortag_delete_author"),
("articles", "0097_alter_articlepage_mark_new_on_next_publish_and_more"),
]

operations = [
migrations.RunPython(convert_to_foreign_key),
migrations.AlterField(
model_name="focusedarticlepage",
name="author",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="focused_articles",
to="authors.authorpage",
),
),
]
15 changes: 12 additions & 3 deletions etna/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from taggit.models import ItemBase, TagBase

from etna.authors.models import AuthorPageMixin
from etna.collections.models import TopicalPageMixin
from etna.core.models import (
BasePageWithIntro,
Expand Down Expand Up @@ -310,6 +311,7 @@ def latest_items(

class FocusedArticlePage(
TopicalPageMixin,
AuthorPageMixin,
HeroImageMixin,
ContentWarningMixin,
NewLabelMixin,
Expand All @@ -321,8 +323,12 @@ class FocusedArticlePage(
The FocusedArticlePage model.
"""

author = models.CharField(
max_length=100, blank=True, null=True, help_text="The author of this article."
author = models.ForeignKey(
"authors.AuthorPage",
blank=True,
null=True,
related_name="focused_articles",
on_delete=models.SET_NULL,
)

body = StreamField(
Expand All @@ -343,7 +349,6 @@ class Meta:
BasePageWithIntro.content_panels
+ HeroImageMixin.content_panels
+ [
FieldPanel("author"),
MultiFieldPanel(
[
FieldPanel("display_content_warning"),
Expand All @@ -361,6 +366,9 @@ class Meta:
+ BasePageWithIntro.promote_panels
+ ArticleTagMixin.promote_panels
+ [
FieldPanel(
"author", heading="Author", help_text="Add the author of this page"
),
TopicalPageMixin.get_topics_inlinepanel(),
TopicalPageMixin.get_time_periods_inlinepanel(),
]
Expand All @@ -376,6 +384,7 @@ class Meta:
index.SearchField("body"),
index.SearchField("topic_names", boost=1),
index.SearchField("time_period_names", boost=1),
index.SearchField("author_name", boost=1),
]
)

Expand Down
10 changes: 0 additions & 10 deletions etna/authors/blocks.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Generated by Django 4.2.5 on 2023-09-25 10:55

from django.db import migrations, models
import django.db.models.deletion
import etna.analytics.mixins
import modelcluster.fields
import uuid
import wagtail.fields
import wagtailmetadata.models


class Migration(migrations.Migration):
dependencies = [
("images", "0008_alter_customimagerendition_file"),
("wagtailcore", "0089_log_entry_data_json_null_to_object"),
("authors", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="AuthorIndexPage",
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",
),
),
(
"teaser_text",
models.TextField(
help_text="A short, enticing description of this page. This will appear in promos and under thumbnails around the site.",
max_length=160,
verbose_name="teaser text",
),
),
(
"uuid",
models.UUIDField(
default=uuid.uuid4,
editable=False,
unique=True,
verbose_name="UUID",
),
),
(
"search_image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="images.customimage",
verbose_name="Search image",
),
),
(
"teaser_image",
models.ForeignKey(
blank=True,
help_text="Image that will appear on thumbnails and promos around the site.",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="images.customimage",
),
),
],
options={
"abstract": False,
},
bases=(
wagtailmetadata.models.WagtailImageMetadataMixin,
etna.analytics.mixins.DataLayerMixin,
"wagtailcore.page",
models.Model,
),
),
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",
),
),
(
"teaser_text",
models.TextField(
help_text="A short, enticing description of this page. This will appear in promos and under thumbnails around the site.",
max_length=160,
verbose_name="teaser text",
),
),
(
"uuid",
models.UUIDField(
default=uuid.uuid4,
editable=False,
unique=True,
verbose_name="UUID",
),
),
("role", models.CharField(blank=True, max_length=100, null=True)),
("summary", wagtail.fields.RichTextField(blank=True, null=True)),
(
"image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="images.customimage",
),
),
(
"search_image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="images.customimage",
verbose_name="Search image",
),
),
(
"teaser_image",
models.ForeignKey(
blank=True,
help_text="Image that will appear on thumbnails and promos around the site.",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="images.customimage",
),
),
],
options={
"verbose_name": "Author page",
"verbose_name_plural": "Author pages",
},
bases=(
wagtailmetadata.models.WagtailImageMetadataMixin,
etna.analytics.mixins.DataLayerMixin,
"wagtailcore.page",
models.Model,
),
),
migrations.CreateModel(
name="AuthorTag",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"author",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="author_pages",
to="authors.authorpage",
verbose_name="author",
),
),
(
"page",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="author_tags",
to="wagtailcore.page",
),
),
],
),
migrations.DeleteModel(
name="Author",
),
]
Loading

0 comments on commit 338b6b0

Please sign in to comment.