Skip to content

Commit

Permalink
Changed NewLabelMixin for PublishedDateMixin, to use published_date i…
Browse files Browse the repository at this point in the history
…nstead of newly_published_at
  • Loading branch information
jamesbiggs committed Dec 19, 2024
1 parent eab37e1 commit bd1d5b6
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 107 deletions.
2 changes: 1 addition & 1 deletion etna/api/tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def setUpTestData(cls):
PageTimePeriod(time_period=cls.postwar),
],
first_published_at=DATE_1,
newly_published_at=DATE_1,
published_date=DATE_1,
mark_new_on_next_publish=False,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Generated by Django 5.1.2 on 2024-12-19 16:48

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


class Migration(migrations.Migration):

dependencies = [
("articles", "0112_alter_articlepage_body_alter_focusedarticlepage_body"),
]

operations = [
migrations.RemoveField(
model_name="articlepage",
name="mark_new_on_next_publish",
),
migrations.RemoveField(
model_name="articlepage",
name="newly_published_at",
),
migrations.RemoveField(
model_name="focusedarticlepage",
name="mark_new_on_next_publish",
),
migrations.RemoveField(
model_name="focusedarticlepage",
name="newly_published_at",
),
migrations.RemoveField(
model_name="recordarticlepage",
name="mark_new_on_next_publish",
),
migrations.RemoveField(
model_name="recordarticlepage",
name="newly_published_at",
),
migrations.AddField(
model_name="articlepage",
name="published_date",
field=models.DateTimeField(
default=django.utils.timezone.now,
help_text="The date the page was published to the public.",
verbose_name="Published date",
),
),
migrations.AddField(
model_name="focusedarticlepage",
name="published_date",
field=models.DateTimeField(
default=django.utils.timezone.now,
help_text="The date the page was published to the public.",
verbose_name="Published date",
),
),
migrations.AddField(
model_name="recordarticlepage",
name="published_date",
field=models.DateTimeField(
default=django.utils.timezone.now,
help_text="The date the page was published to the public.",
verbose_name="Published date",
),
),
]
47 changes: 25 additions & 22 deletions etna/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
BasePageWithRequiredIntro,
ContentWarningMixin,
HeroImageMixin,
NewLabelMixin,
PublishedDateMixin,
RequiredHeroImageMixin,
)
from etna.core.serializers import (
Expand Down Expand Up @@ -171,9 +171,9 @@ def article_pages(self):
.live()
.order_by(
Coalesce(
"recordarticlepage__newly_published_at",
"focusedarticlepage__newly_published_at",
"articlepage__newly_published_at",
"recordarticlepage__published_date",
"focusedarticlepage__published_date",
"articlepage__published_date",
)
)
.reverse()
Expand Down Expand Up @@ -205,7 +205,7 @@ class ArticlePage(
TopicalPageMixin,
RequiredHeroImageMixin,
ContentWarningMixin,
NewLabelMixin,
PublishedDateMixin,
ArticleTagMixin,
BasePageWithRequiredIntro,
):
Expand Down Expand Up @@ -236,7 +236,7 @@ class Meta:
)

promote_panels = (
NewLabelMixin.promote_panels
PublishedDateMixin.promote_panels
+ BasePageWithRequiredIntro.promote_panels
+ ArticleTagMixin.promote_panels
+ [
Expand All @@ -259,16 +259,17 @@ class Meta:
)

default_api_fields = BasePageWithRequiredIntro.default_api_fields + [
APIField("is_newly_published"),
PublishedDateMixin.get_is_newly_published_apifield(),
]

api_fields = (
BasePageWithRequiredIntro.api_fields
+ RequiredHeroImageMixin.api_fields
+ ContentWarningMixin.api_fields
+ NewLabelMixin.api_fields
+ ArticleTagMixin.api_fields
+ [
PublishedDateMixin.get_published_date_apifield(),
PublishedDateMixin.get_is_newly_published_apifield(),
APIField("body"),
APIField(
"similar_items",
Expand Down Expand Up @@ -358,17 +359,17 @@ def latest_items(
.prefetch_related("teaser_image__renditions")
)

return sorted(
latest_query_set, key=lambda x: x.newly_published_at, reverse=True
)[:3]
return sorted(latest_query_set, key=lambda x: x.published_date, reverse=True)[
:3
]


class FocusedArticlePage(
TopicalPageMixin,
AuthorPageMixin,
HeroImageMixin,
ContentWarningMixin,
NewLabelMixin,
PublishedDateMixin,
ArticleTagMixin,
BasePageWithRequiredIntro,
):
Expand Down Expand Up @@ -399,7 +400,7 @@ class Meta:
)

promote_panels = (
NewLabelMixin.promote_panels
PublishedDateMixin.promote_panels
+ BasePageWithRequiredIntro.promote_panels
+ ArticleTagMixin.promote_panels
+ [
Expand All @@ -424,16 +425,17 @@ class Meta:
)

default_api_fields = BasePageWithRequiredIntro.default_api_fields + [
APIField("is_newly_published"),
PublishedDateMixin.get_is_newly_published_apifield(),
]

api_fields = (
BasePageWithRequiredIntro.api_fields
+ HeroImageMixin.api_fields
+ ContentWarningMixin.api_fields
+ NewLabelMixin.api_fields
+ ArticleTagMixin.api_fields
+ [
PublishedDateMixin.get_is_newly_published_apifield(),
PublishedDateMixin.get_published_date_apifield(),
APIField("type_label"),
APIField("body"),
APIField(
Expand Down Expand Up @@ -525,9 +527,9 @@ def latest_items(
.prefetch_related("teaser_image__renditions")
)

return sorted(
latest_query_set, key=lambda x: x.newly_published_at, reverse=True
)[:3]
return sorted(latest_query_set, key=lambda x: x.published_date, reverse=True)[
:3
]


class PageGalleryImage(Orderable):
Expand Down Expand Up @@ -577,7 +579,7 @@ class Meta:
class RecordArticlePage(
TopicalPageMixin,
ContentWarningMixin,
NewLabelMixin,
PublishedDateMixin,
ArticleTagMixin,
BasePageWithRequiredIntro,
):
Expand Down Expand Up @@ -709,7 +711,7 @@ class Meta:
)

promote_panels = (
NewLabelMixin.promote_panels
PublishedDateMixin.promote_panels
+ BasePageWithRequiredIntro.promote_panels
+ ArticleTagMixin.promote_panels
+ [
Expand All @@ -731,15 +733,16 @@ class Meta:
)

default_api_fields = BasePageWithRequiredIntro.default_api_fields + [
APIField("is_newly_published"),
PublishedDateMixin.get_is_newly_published_apifield(),
]

api_fields = (
BasePageWithRequiredIntro.api_fields
+ ContentWarningMixin.api_fields
+ NewLabelMixin.api_fields
+ ArticleTagMixin.api_fields
+ [
PublishedDateMixin.get_is_newly_published_apifield(),
PublishedDateMixin.get_published_date_apifield(),
APIField("type_label"),
APIField("date_text"),
APIField("about", serializer=RichTextSerializer()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 5.1.2 on 2024-12-19 16:48

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


class Migration(migrations.Migration):

dependencies = [
("blog", "0006_alter_blogpostpage_body"),
]

operations = [
migrations.RemoveField(
model_name="blogindexpage",
name="hero_image",
),
migrations.RemoveField(
model_name="blogindexpage",
name="hero_image_caption",
),
migrations.AlterField(
model_name="blogpostpage",
name="published_date",
field=models.DateTimeField(
default=django.utils.timezone.now,
help_text="The date the page was published to the public.",
verbose_name="Published date",
),
),
]
37 changes: 15 additions & 22 deletions etna/blog/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from django.db import models
from django.utils import timezone
from django.utils.functional import cached_property

from wagtail.admin.panels import FieldPanel
from wagtail.api import APIField
from wagtail.fields import StreamField
Expand All @@ -10,8 +6,8 @@
BasePageWithRequiredIntro,
ContentWarningMixin,
HeroImageMixin,
PublishedDateMixin,
)
from etna.core.serializers import DateTimeSerializer, DefaultPageSerializer
from etna.people.models import AuthorPageMixin, ExternalAuthorMixin

from .blocks import BlogPostPageStreamBlock
Expand Down Expand Up @@ -55,16 +51,14 @@ class BlogPage(HeroImageMixin, BasePageWithRequiredIntro):

promote_panels = BasePageWithRequiredIntro.promote_panels

api_fields = (
BasePageWithRequiredIntro.api_fields
+ HeroImageMixin.api_fields
)
api_fields = BasePageWithRequiredIntro.api_fields + HeroImageMixin.api_fields


class BlogPostPage(
AuthorPageMixin,
ExternalAuthorMixin,
ContentWarningMixin,
PublishedDateMixin,
HeroImageMixin,
BasePageWithRequiredIntro,
):
Expand All @@ -79,12 +73,6 @@ class BlogPostPage(
BlogPostPageStreamBlock(),
)

published_date = models.DateTimeField(
verbose_name="Published date",
help_text="The date the blog post was published.",
default=timezone.now,
)

content_panels = (
BasePageWithRequiredIntro.content_panels
+ HeroImageMixin.content_panels
Expand All @@ -93,17 +81,21 @@ class BlogPostPage(
]
)

promote_panels = BasePageWithRequiredIntro.promote_panels + [
FieldPanel("published_date"),
AuthorPageMixin.get_authors_inlinepanel(),
ExternalAuthorMixin.get_authors_inlinepanel(),
]
promote_panels = (
BasePageWithRequiredIntro.promote_panels
+ PublishedDateMixin.promote_panels
+ [
AuthorPageMixin.get_authors_inlinepanel(),
ExternalAuthorMixin.get_authors_inlinepanel(),
]
)

default_api_fields = (
BasePageWithRequiredIntro.default_api_fields
+ AuthorPageMixin.default_api_fields
+ [
APIField("published_date", serializer=DateTimeSerializer()),
PublishedDateMixin.get_published_date_apifield(),
PublishedDateMixin.get_is_newly_published_apifield(),
APIField("last_published_at"),
]
)
Expand All @@ -115,7 +107,8 @@ class BlogPostPage(
+ AuthorPageMixin.api_fields
+ ExternalAuthorMixin.api_fields
+ [
APIField("published_date", serializer=DateTimeSerializer()),
PublishedDateMixin.get_published_date_apifield(),
PublishedDateMixin.get_is_newly_published_apifield(),
APIField("body"),
]
)
Expand Down
4 changes: 2 additions & 2 deletions etna/collections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def related_articles(self):
.prefetch_related("teaser_image__renditions")
)

return sorted(page_list, key=lambda x: x.newly_published_at, reverse=True)
return sorted(page_list, key=lambda x: x.published_date, reverse=True)

@cached_property
def related_highlight_gallery_pages(self):
Expand Down Expand Up @@ -583,7 +583,7 @@ def related_articles(self):
.prefetch_related("teaser_image__renditions")
)

return sorted(page_list, key=lambda x: x.newly_published_at, reverse=True)
return sorted(page_list, key=lambda x: x.published_date, reverse=True)

@cached_property
def related_highlight_gallery_pages(self):
Expand Down
Loading

0 comments on commit bd1d5b6

Please sign in to comment.