From ab0e7422a1a5794c7484f0a5793fb7768ab39688 Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 16:24:12 -0400 Subject: [PATCH 01/36] update gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5981ea26..aecaac7a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ /webpack-stats.json /.vscode/ .DS_Store -/pipeline-env/ \ No newline at end of file +/pipeline-env/ +**/__pycache__/** \ No newline at end of file From 386d0b631902b4bbe00939f2b6f29b7db57b416d Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 17:11:30 -0400 Subject: [PATCH 02/36] add adpage type, adpage column --- core/migrations/0005_adpage.py | 37 +++++ core/models.py | 164 ++++++++++++++++++++- home/migrations/0002_auto_20190924_2108.py | 20 +++ home/models.py | 20 +++ home/templates/home/home_page.html | 23 +++ pipeline/settings/dev.py | 2 +- 6 files changed, 263 insertions(+), 3 deletions(-) create mode 100644 core/migrations/0005_adpage.py create mode 100644 home/migrations/0002_auto_20190924_2108.py diff --git a/core/migrations/0005_adpage.py b/core/migrations/0005_adpage.py new file mode 100644 index 00000000..f8b97be5 --- /dev/null +++ b/core/migrations/0005_adpage.py @@ -0,0 +1,37 @@ +# Generated by Django 2.2.5 on 2019-09-24 21:08 + +from django.db import migrations, models +import django.db.models.deletion +import wagtail.contrib.routable_page.models +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.embeds.blocks +import wagtail.images.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0041_group_collection_permissions_verbose_name_plural'), + ('core', '0004_archivespage_body'), + ] + + operations = [ + migrations.CreateModel( + name='AdPage', + 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')), + ('headline', wagtail.core.fields.RichTextField()), + ('subdeck', wagtail.core.fields.RichTextField(blank=True, null=True)), + ('body', wagtail.core.fields.StreamField([('paragraph', wagtail.core.blocks.RichTextBlock()), ('photo', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock()), ('caption', wagtail.core.blocks.RichTextBlock(features=['italic'], required=False)), ('size', wagtail.core.blocks.ChoiceBlock(choices=[('small', 'Small'), ('medium', 'Medium'), ('large', 'Large')], help_text='Width of image in article.'))])), ('photo_gallery', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock()), ('caption', wagtail.core.blocks.RichTextBlock(features=['italic'], required=False))]), icon='image')), ('embed', wagtail.core.blocks.StructBlock([('embed', wagtail.embeds.blocks.EmbedBlock(help_text='URL to the content to embed.'))]))], blank=True)), + ('summary', wagtail.core.fields.RichTextField(blank=True, help_text='Displayed on the home page or other places to provide a taste of what the article is about.', null=True)), + ('featured_caption', wagtail.core.fields.RichTextField(blank=True, null=True)), + ('featured_image', models.ForeignKey(blank=True, help_text='Shown at the top of the article and on the home page.', null=True, on_delete=django.db.models.deletion.PROTECT, to='core.CustomImage')), + ('kicker', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='core.Kicker')), + ], + options={ + 'abstract': False, + }, + bases=(wagtail.contrib.routable_page.models.RoutablePageMixin, 'wagtailcore.page'), + ), + ] diff --git a/core/models.py b/core/models.py index 918b97a1..3c14b030 100644 --- a/core/models.py +++ b/core/models.py @@ -109,7 +109,7 @@ class StaffPage(Page): search_fields = [index.SearchField("first_name"), index.SearchField("last_name")] - parent_page_types = ["StaffIndexPage"] + parent_page_types = ["StaffIndexPage", "ArticlesIndexPage"] subpage_types = [] @property @@ -524,9 +524,169 @@ def get_meta_tags(self): return tags +class AdPage (RoutablePageMixin, Page): + headline = RichTextField(features=["italic"]) + subdeck = RichTextField(features=["italic"], null=True, blank=True) + kicker = models.ForeignKey(Kicker, null=True, blank=True, on_delete=models.PROTECT) + body = StreamField( + [ + ("paragraph", RichTextBlock()), + ("photo", PhotoBlock()), + ("photo_gallery", ListBlock(GalleryPhotoBlock(), icon="image")), + ("embed", EmbeddedMediaBlock()), + ], + blank=True, + ) + summary = RichTextField( + features=["italic"], + null=True, + blank=True, + help_text="Displayed on the home page or other places to provide a taste of what the article is about.", + ) + featured_image = models.ForeignKey( + CustomImage, + null=True, + blank=True, + on_delete=models.PROTECT, + help_text="Shown at the top of the article and on the home page.", + ) + featured_caption = RichTextField(features=["italic"], blank=True, null=True) + + content_panels = [ + MultiFieldPanel( + [FieldPanel("headline", classname="title"), FieldPanel("subdeck")] + ), + + FieldPanel("summary"), + StreamFieldPanel("body"), + ] + + search_fields = Page.search_fields + [ + index.SearchField("headline"), + index.SearchField("subdeck"), + index.SearchField("body"), + index.SearchField("summary"), + index.RelatedFields("kicker", [index.SearchField("title")]), + ] + + subpage_types = [] + + def clean(self): + super().clean() + + soup = BeautifulSoup(self.headline, "html.parser") + self.title = soup.text + + @route(r"^$") + def post_404(self, request): + """Return an HTTP 404 whenever the page is accessed directly. + + This is because it should instead by accessed by its date-based path, + i.e. `///`.""" + raise Http404 + + def set_url_path(self, parent): + """Make sure the page knows its own path. The published date might not be set, + so we have to take that into account and ignore it if so.""" + date = self.get_published_date() or timezone.now() + self.url_path = f"{parent.url_path}{date.year}/{date.month:02d}/{self.slug}/" + return self.url_path + + def serve_preview(self, request, mode_name): + request.is_preview = True + return self.serve(request) + + def get_context(self, request): + context = super().get_context(request) + context["authors"] = self.get_authors() + return context + + def get_authors(self): + return 'ads' + + def get_author_names(self): + return [a.name for a in self.get_authors()] + + def get_published_date(self): + return ( + self.go_live_at + or self.first_published_at + or getattr(self.get_latest_revision(), "created_at", None) + ) + + def get_text_html(self): + """Get the HTML that represents paragraphs within the article as a string.""" + builder = "" + for block in self.body: + if block.block_type == "paragraph": + builder += str(block.value) + return builder + + def get_plain_text(self): + builder = "" + soup = BeautifulSoup(self.get_text_html(), "html.parser") + for para in soup.findAll("p"): + builder += para.text + builder += " " + return builder[:-1] + + + def get_first_chars(self, n=100): + """Convert the body to HTML, extract the text, and then build + a string out of it until we have at least n characters. + If this isn't possible, then return None.""" + + text = self.get_plain_text() + if len(text) < n: + return None + + punctuation = {".", "!"} + for i in range(n, len(text)): + if text[i] in punctuation: + if i + 1 == len(text): + return text + elif text[i + 1] == " ": + return text[: i + 1] + + return None + + def get_meta_tags(self): + tags = {} + tags["og:type"] = "article" + tags["og:title"] = self.title + tags["og:url"] = self.full_url + tags["og:site_name"] = self.get_site().site_name + + # description: either the article's summary or first paragraph + if self.summary is not None: + tags["og:description"] = self.summary + tags["twitter:description"] = self.summary + else: + first_chars = self.get_first_chars() + if first_chars is not None: + tags["og:description"] = first_chars + tags["twitter:description"] = first_chars + + # image + if self.featured_image is not None: + # pylint: disable=E1101 + rendition = self.featured_image.get_rendition("min-1200x1200") + rendition_url = self.get_site().root_url + rendition.url + tags["og:image"] = rendition_url + tags["twitter:image"] = rendition_url + + tags["twitter:site"] = "@rpipoly" + tags["twitter:title"] = self.title + if "twitter:description" in tags and "twitter:image" in tags: + tags["twitter:card"] = "summary_large_image" + else: + tags["twitter:card"] = "summary" + + return tags + class ArticlesIndexPage(RoutablePageMixin, Page): - subpage_types = ["ArticlePage"] + subpage_types = ["ArticlePage", "StaffPage", "AdPage"] @route(r"^(\d{4})\/(\d{2})\/(.*)\/$") def post_by_date(self, request, year, month, slug, *args, **kwargs): diff --git a/home/migrations/0002_auto_20190924_2108.py b/home/migrations/0002_auto_20190924_2108.py new file mode 100644 index 00000000..53665598 --- /dev/null +++ b/home/migrations/0002_auto_20190924_2108.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.5 on 2019-09-24 21:08 + +from django.db import migrations +import wagtail.core.blocks +import wagtail.core.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='homepage', + name='featured_articles', + field=wagtail.core.fields.StreamField([('one_column', wagtail.core.blocks.StructBlock([('column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('one_ad_column', wagtail.core.blocks.StructBlock([('column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.AdPage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('two_columns', wagtail.core.blocks.StructBlock([('left_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('right_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('emphasize_column', wagtail.core.blocks.ChoiceBlock(choices=[('left', 'Left'), ('right', 'Right')], help_text='Which article, if either, should appear larger.', required=False))])), ('three_columns', wagtail.core.blocks.StructBlock([('left_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('middle_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('right_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('recent_articles', wagtail.core.blocks.StructBlock([('num_articles', wagtail.core.blocks.IntegerBlock(help_text='Number of recent articles to display.', label='Number of articles'))]))], null=True), + ), + ] diff --git a/home/models.py b/home/models.py index 4a502d7c..6d545a1e 100644 --- a/home/models.py +++ b/home/models.py @@ -17,6 +17,17 @@ class ArticleBlock(blocks.StructBlock): class Meta: template = "home/article_block.html" +class AdBlock(blocks.StructBlock): + article = blocks.PageChooserBlock(target_model="core.AdPage") + headline = blocks.RichTextBlock( + help_text="Optional. Will override the article's headline.", required=False + ) + # TODO: add a photo override block + # TODO: add a "hide photo" block + + class Meta: + template = "home/article_block.html" + class OneColumnBlock(blocks.StructBlock): column = ArticleBlock() @@ -24,6 +35,12 @@ class OneColumnBlock(blocks.StructBlock): def article_pks(self): return set(self.column.value.pk) # pylint: disable=E1101 +class OneColumnAdBlock(blocks.StructBlock): + column = AdBlock() + + def article_pks(self): + return set(self.column.value.pk) # pylint: disable=E1101 + class TwoColumnBlock(blocks.StructBlock): left_column = ArticleBlock() @@ -84,6 +101,7 @@ class HomePage(Page): featured_articles = StreamField( [ ("one_column", OneColumnBlock()), + ("one_ad_column", OneColumnAdBlock()), ("two_columns", TwoColumnBlock()), ("three_columns", ThreeColumnBlock()), ("recent_articles", RecentArticlesBlock()), @@ -98,6 +116,8 @@ def article_pks(self): for block in self.featured_articles: # pylint: disable=E1133 if block.block_type == "one_column": pks.add(block.value["column"]["article"].pk) + elif block.block_type == "one_ad_column": + pks.add(block.value["column"]["article"].pk) elif block.block_type == "two_columns": pks.add(block.value["left_column"]["article"].pk) pks.add(block.value["right_column"]["article"].pk) diff --git a/home/templates/home/home_page.html b/home/templates/home/home_page.html index 0fdc27ff..8eca3e04 100644 --- a/home/templates/home/home_page.html +++ b/home/templates/home/home_page.html @@ -56,6 +56,29 @@

{{ block.value.column.article.specific.summary|richtext }}
+ {% elif block.block_type == "one_ad_column" %} + {% elif block.block_type == "two_columns" %}
Date: Tue, 24 Sep 2019 18:04:57 -0400 Subject: [PATCH 03/36] add an ad block with target link --- core/models.py | 13 +++++++++++++ home/models.py | 21 ++------------------- home/templates/home/home_page.html | 22 +++++++--------------- 3 files changed, 22 insertions(+), 34 deletions(-) diff --git a/core/models.py b/core/models.py index 3c14b030..d70e0898 100644 --- a/core/models.py +++ b/core/models.py @@ -313,6 +313,19 @@ class PhotoBlock(StructBlock): class Meta: icon = "image" +class AdBlock(StructBlock): + image = ImageChooserBlock() + caption = RichTextBlock(features=["italic"], required=False) + link = URLBlock(label = "target", required="false") + size = ChoiceBlock( + choices=[("small", "Small"), ("medium", "Medium"), ("large", "Large")], + default="medium", + help_text="Width of image in ad.", + ) + + class Meta: + icon = "image" + class GalleryPhotoBlock(StructBlock): image = ImageChooserBlock() diff --git a/home/models.py b/home/models.py index 6d545a1e..31076534 100644 --- a/home/models.py +++ b/home/models.py @@ -3,7 +3,7 @@ from wagtail.admin.edit_handlers import StreamFieldPanel from wagtail.core import blocks -from core.models import ArticlePage, ArticlesIndexPage +from core.models import ArticlePage, ArticlesIndexPage, AdBlock class ArticleBlock(blocks.StructBlock): @@ -17,18 +17,6 @@ class ArticleBlock(blocks.StructBlock): class Meta: template = "home/article_block.html" -class AdBlock(blocks.StructBlock): - article = blocks.PageChooserBlock(target_model="core.AdPage") - headline = blocks.RichTextBlock( - help_text="Optional. Will override the article's headline.", required=False - ) - # TODO: add a photo override block - # TODO: add a "hide photo" block - - class Meta: - template = "home/article_block.html" - - class OneColumnBlock(blocks.StructBlock): column = ArticleBlock() @@ -38,9 +26,6 @@ def article_pks(self): class OneColumnAdBlock(blocks.StructBlock): column = AdBlock() - def article_pks(self): - return set(self.column.value.pk) # pylint: disable=E1101 - class TwoColumnBlock(blocks.StructBlock): left_column = ArticleBlock() @@ -101,7 +86,7 @@ class HomePage(Page): featured_articles = StreamField( [ ("one_column", OneColumnBlock()), - ("one_ad_column", OneColumnAdBlock()), + ("one_ad_column", AdBlock()), ("two_columns", TwoColumnBlock()), ("three_columns", ThreeColumnBlock()), ("recent_articles", RecentArticlesBlock()), @@ -116,8 +101,6 @@ def article_pks(self): for block in self.featured_articles: # pylint: disable=E1133 if block.block_type == "one_column": pks.add(block.value["column"]["article"].pk) - elif block.block_type == "one_ad_column": - pks.add(block.value["column"]["article"].pk) elif block.block_type == "two_columns": pks.add(block.value["left_column"]["article"].pk) pks.add(block.value["right_column"]["article"].pk) diff --git a/home/templates/home/home_page.html b/home/templates/home/home_page.html index 8eca3e04..06ad2110 100644 --- a/home/templates/home/home_page.html +++ b/home/templates/home/home_page.html @@ -58,22 +58,14 @@

{% elif block.block_type == "one_ad_column" %}
{{ block.value.column.article.specific.summary|richtext }}
From 37964cf2f60f258ae053fda717a62fdb20ee0395 Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 19:39:05 -0400 Subject: [PATCH 04/36] lint --- core/models.py | 10 +++++----- home/models.py | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/models.py b/core/models.py index d70e0898..694d3f8e 100644 --- a/core/models.py +++ b/core/models.py @@ -313,10 +313,11 @@ class PhotoBlock(StructBlock): class Meta: icon = "image" + class AdBlock(StructBlock): image = ImageChooserBlock() caption = RichTextBlock(features=["italic"], required=False) - link = URLBlock(label = "target", required="false") + link = URLBlock(label="target", required="false") size = ChoiceBlock( choices=[("small", "Small"), ("medium", "Medium"), ("large", "Large")], default="medium", @@ -537,7 +538,8 @@ def get_meta_tags(self): return tags -class AdPage (RoutablePageMixin, Page): + +class AdPage(RoutablePageMixin, Page): headline = RichTextField(features=["italic"]) subdeck = RichTextField(features=["italic"], null=True, blank=True) kicker = models.ForeignKey(Kicker, null=True, blank=True, on_delete=models.PROTECT) @@ -569,7 +571,6 @@ class AdPage (RoutablePageMixin, Page): MultiFieldPanel( [FieldPanel("headline", classname="title"), FieldPanel("subdeck")] ), - FieldPanel("summary"), StreamFieldPanel("body"), ] @@ -615,7 +616,7 @@ def get_context(self, request): return context def get_authors(self): - return 'ads' + return "ads" def get_author_names(self): return [a.name for a in self.get_authors()] @@ -643,7 +644,6 @@ def get_plain_text(self): builder += " " return builder[:-1] - def get_first_chars(self, n=100): """Convert the body to HTML, extract the text, and then build a string out of it until we have at least n characters. diff --git a/home/models.py b/home/models.py index 31076534..38c1008f 100644 --- a/home/models.py +++ b/home/models.py @@ -17,12 +17,14 @@ class ArticleBlock(blocks.StructBlock): class Meta: template = "home/article_block.html" + class OneColumnBlock(blocks.StructBlock): column = ArticleBlock() def article_pks(self): return set(self.column.value.pk) # pylint: disable=E1101 + class OneColumnAdBlock(blocks.StructBlock): column = AdBlock() From 752ec7706fc15afc81032ea376b43b9f74f8eb6c Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 19:42:11 -0400 Subject: [PATCH 05/36] remove unused types and migrations --- core/migrations/0005_adpage.py | 37 ----- core/models.py | 161 +-------------------- home/migrations/0002_auto_20190924_2108.py | 20 --- 3 files changed, 1 insertion(+), 217 deletions(-) delete mode 100644 core/migrations/0005_adpage.py delete mode 100644 home/migrations/0002_auto_20190924_2108.py diff --git a/core/migrations/0005_adpage.py b/core/migrations/0005_adpage.py deleted file mode 100644 index f8b97be5..00000000 --- a/core/migrations/0005_adpage.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 2.2.5 on 2019-09-24 21:08 - -from django.db import migrations, models -import django.db.models.deletion -import wagtail.contrib.routable_page.models -import wagtail.core.blocks -import wagtail.core.fields -import wagtail.embeds.blocks -import wagtail.images.blocks - - -class Migration(migrations.Migration): - - dependencies = [ - ('wagtailcore', '0041_group_collection_permissions_verbose_name_plural'), - ('core', '0004_archivespage_body'), - ] - - operations = [ - migrations.CreateModel( - name='AdPage', - 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')), - ('headline', wagtail.core.fields.RichTextField()), - ('subdeck', wagtail.core.fields.RichTextField(blank=True, null=True)), - ('body', wagtail.core.fields.StreamField([('paragraph', wagtail.core.blocks.RichTextBlock()), ('photo', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock()), ('caption', wagtail.core.blocks.RichTextBlock(features=['italic'], required=False)), ('size', wagtail.core.blocks.ChoiceBlock(choices=[('small', 'Small'), ('medium', 'Medium'), ('large', 'Large')], help_text='Width of image in article.'))])), ('photo_gallery', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock()), ('caption', wagtail.core.blocks.RichTextBlock(features=['italic'], required=False))]), icon='image')), ('embed', wagtail.core.blocks.StructBlock([('embed', wagtail.embeds.blocks.EmbedBlock(help_text='URL to the content to embed.'))]))], blank=True)), - ('summary', wagtail.core.fields.RichTextField(blank=True, help_text='Displayed on the home page or other places to provide a taste of what the article is about.', null=True)), - ('featured_caption', wagtail.core.fields.RichTextField(blank=True, null=True)), - ('featured_image', models.ForeignKey(blank=True, help_text='Shown at the top of the article and on the home page.', null=True, on_delete=django.db.models.deletion.PROTECT, to='core.CustomImage')), - ('kicker', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='core.Kicker')), - ], - options={ - 'abstract': False, - }, - bases=(wagtail.contrib.routable_page.models.RoutablePageMixin, 'wagtailcore.page'), - ), - ] diff --git a/core/models.py b/core/models.py index 694d3f8e..7b182f06 100644 --- a/core/models.py +++ b/core/models.py @@ -539,167 +539,8 @@ def get_meta_tags(self): return tags -class AdPage(RoutablePageMixin, Page): - headline = RichTextField(features=["italic"]) - subdeck = RichTextField(features=["italic"], null=True, blank=True) - kicker = models.ForeignKey(Kicker, null=True, blank=True, on_delete=models.PROTECT) - body = StreamField( - [ - ("paragraph", RichTextBlock()), - ("photo", PhotoBlock()), - ("photo_gallery", ListBlock(GalleryPhotoBlock(), icon="image")), - ("embed", EmbeddedMediaBlock()), - ], - blank=True, - ) - summary = RichTextField( - features=["italic"], - null=True, - blank=True, - help_text="Displayed on the home page or other places to provide a taste of what the article is about.", - ) - featured_image = models.ForeignKey( - CustomImage, - null=True, - blank=True, - on_delete=models.PROTECT, - help_text="Shown at the top of the article and on the home page.", - ) - featured_caption = RichTextField(features=["italic"], blank=True, null=True) - - content_panels = [ - MultiFieldPanel( - [FieldPanel("headline", classname="title"), FieldPanel("subdeck")] - ), - FieldPanel("summary"), - StreamFieldPanel("body"), - ] - - search_fields = Page.search_fields + [ - index.SearchField("headline"), - index.SearchField("subdeck"), - index.SearchField("body"), - index.SearchField("summary"), - index.RelatedFields("kicker", [index.SearchField("title")]), - ] - - subpage_types = [] - - def clean(self): - super().clean() - - soup = BeautifulSoup(self.headline, "html.parser") - self.title = soup.text - - @route(r"^$") - def post_404(self, request): - """Return an HTTP 404 whenever the page is accessed directly. - - This is because it should instead by accessed by its date-based path, - i.e. `///`.""" - raise Http404 - - def set_url_path(self, parent): - """Make sure the page knows its own path. The published date might not be set, - so we have to take that into account and ignore it if so.""" - date = self.get_published_date() or timezone.now() - self.url_path = f"{parent.url_path}{date.year}/{date.month:02d}/{self.slug}/" - return self.url_path - - def serve_preview(self, request, mode_name): - request.is_preview = True - return self.serve(request) - - def get_context(self, request): - context = super().get_context(request) - context["authors"] = self.get_authors() - return context - - def get_authors(self): - return "ads" - - def get_author_names(self): - return [a.name for a in self.get_authors()] - - def get_published_date(self): - return ( - self.go_live_at - or self.first_published_at - or getattr(self.get_latest_revision(), "created_at", None) - ) - - def get_text_html(self): - """Get the HTML that represents paragraphs within the article as a string.""" - builder = "" - for block in self.body: - if block.block_type == "paragraph": - builder += str(block.value) - return builder - - def get_plain_text(self): - builder = "" - soup = BeautifulSoup(self.get_text_html(), "html.parser") - for para in soup.findAll("p"): - builder += para.text - builder += " " - return builder[:-1] - - def get_first_chars(self, n=100): - """Convert the body to HTML, extract the text, and then build - a string out of it until we have at least n characters. - If this isn't possible, then return None.""" - - text = self.get_plain_text() - if len(text) < n: - return None - - punctuation = {".", "!"} - for i in range(n, len(text)): - if text[i] in punctuation: - if i + 1 == len(text): - return text - elif text[i + 1] == " ": - return text[: i + 1] - - return None - - def get_meta_tags(self): - tags = {} - tags["og:type"] = "article" - tags["og:title"] = self.title - tags["og:url"] = self.full_url - tags["og:site_name"] = self.get_site().site_name - - # description: either the article's summary or first paragraph - if self.summary is not None: - tags["og:description"] = self.summary - tags["twitter:description"] = self.summary - else: - first_chars = self.get_first_chars() - if first_chars is not None: - tags["og:description"] = first_chars - tags["twitter:description"] = first_chars - - # image - if self.featured_image is not None: - # pylint: disable=E1101 - rendition = self.featured_image.get_rendition("min-1200x1200") - rendition_url = self.get_site().root_url + rendition.url - tags["og:image"] = rendition_url - tags["twitter:image"] = rendition_url - - tags["twitter:site"] = "@rpipoly" - tags["twitter:title"] = self.title - if "twitter:description" in tags and "twitter:image" in tags: - tags["twitter:card"] = "summary_large_image" - else: - tags["twitter:card"] = "summary" - - return tags - - class ArticlesIndexPage(RoutablePageMixin, Page): - subpage_types = ["ArticlePage", "StaffPage", "AdPage"] + subpage_types = ["ArticlePage", "StaffPage"] @route(r"^(\d{4})\/(\d{2})\/(.*)\/$") def post_by_date(self, request, year, month, slug, *args, **kwargs): diff --git a/home/migrations/0002_auto_20190924_2108.py b/home/migrations/0002_auto_20190924_2108.py deleted file mode 100644 index 53665598..00000000 --- a/home/migrations/0002_auto_20190924_2108.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 2.2.5 on 2019-09-24 21:08 - -from django.db import migrations -import wagtail.core.blocks -import wagtail.core.fields - - -class Migration(migrations.Migration): - - dependencies = [ - ('home', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='homepage', - name='featured_articles', - field=wagtail.core.fields.StreamField([('one_column', wagtail.core.blocks.StructBlock([('column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('one_ad_column', wagtail.core.blocks.StructBlock([('column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.AdPage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('two_columns', wagtail.core.blocks.StructBlock([('left_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('right_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('emphasize_column', wagtail.core.blocks.ChoiceBlock(choices=[('left', 'Left'), ('right', 'Right')], help_text='Which article, if either, should appear larger.', required=False))])), ('three_columns', wagtail.core.blocks.StructBlock([('left_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('middle_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('right_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('recent_articles', wagtail.core.blocks.StructBlock([('num_articles', wagtail.core.blocks.IntegerBlock(help_text='Number of recent articles to display.', label='Number of articles'))]))], null=True), - ), - ] From 523d3ff7f69fcf21086baec3ccb5fe0db1b0b38a Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 19:45:27 -0400 Subject: [PATCH 06/36] migrations --- home/migrations/0002_auto_20190924_2345.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 home/migrations/0002_auto_20190924_2345.py diff --git a/home/migrations/0002_auto_20190924_2345.py b/home/migrations/0002_auto_20190924_2345.py new file mode 100644 index 00000000..c7d26d3e --- /dev/null +++ b/home/migrations/0002_auto_20190924_2345.py @@ -0,0 +1,21 @@ +# Generated by Django 2.2.5 on 2019-09-24 23:45 + +from django.db import migrations +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.images.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='homepage', + name='featured_articles', + field=wagtail.core.fields.StreamField([('one_column', wagtail.core.blocks.StructBlock([('column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('one_ad_column', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock()), ('caption', wagtail.core.blocks.RichTextBlock(features=['italic'], required=False)), ('link', wagtail.core.blocks.URLBlock(label='target', required='false')), ('size', wagtail.core.blocks.ChoiceBlock(choices=[('small', 'Small'), ('medium', 'Medium'), ('large', 'Large')], help_text='Width of image in ad.'))])), ('two_columns', wagtail.core.blocks.StructBlock([('left_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('right_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('emphasize_column', wagtail.core.blocks.ChoiceBlock(choices=[('left', 'Left'), ('right', 'Right')], help_text='Which article, if either, should appear larger.', required=False))])), ('three_columns', wagtail.core.blocks.StructBlock([('left_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('middle_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('right_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('recent_articles', wagtail.core.blocks.StructBlock([('num_articles', wagtail.core.blocks.IntegerBlock(help_text='Number of recent articles to display.', label='Number of articles'))]))], null=True), + ), + ] From f7c4316415b2e96480f517491096d4a367d4d00d Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 19:45:46 -0400 Subject: [PATCH 07/36] database --- pipeline/settings/dev.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/settings/dev.py b/pipeline/settings/dev.py index 5ff16658..9b0eac29 100644 --- a/pipeline/settings/dev.py +++ b/pipeline/settings/dev.py @@ -36,7 +36,7 @@ DATABASES = { "default": dj_database_url.config( - default="postgresql://postgres:postgres@127.0.0.1:5432/pq" + default="postgresql://postgres:postgres@127.0.0.1:5432/pipeline" ) } From cbb4a5b5db284b3a11251db62350825a75435d72 Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 19:50:07 -0400 Subject: [PATCH 08/36] lint --- home/migrations/0002_auto_20190924_2345.py | 210 ++++++++++++++++++++- 1 file changed, 203 insertions(+), 7 deletions(-) diff --git a/home/migrations/0002_auto_20190924_2345.py b/home/migrations/0002_auto_20190924_2345.py index c7d26d3e..2f0cc2e3 100644 --- a/home/migrations/0002_auto_20190924_2345.py +++ b/home/migrations/0002_auto_20190924_2345.py @@ -8,14 +8,210 @@ class Migration(migrations.Migration): - dependencies = [ - ('home', '0001_initial'), - ] + dependencies = [("home", "0001_initial")] operations = [ migrations.AlterField( - model_name='homepage', - name='featured_articles', - field=wagtail.core.fields.StreamField([('one_column', wagtail.core.blocks.StructBlock([('column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('one_ad_column', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock()), ('caption', wagtail.core.blocks.RichTextBlock(features=['italic'], required=False)), ('link', wagtail.core.blocks.URLBlock(label='target', required='false')), ('size', wagtail.core.blocks.ChoiceBlock(choices=[('small', 'Small'), ('medium', 'Medium'), ('large', 'Large')], help_text='Width of image in ad.'))])), ('two_columns', wagtail.core.blocks.StructBlock([('left_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('right_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('emphasize_column', wagtail.core.blocks.ChoiceBlock(choices=[('left', 'Left'), ('right', 'Right')], help_text='Which article, if either, should appear larger.', required=False))])), ('three_columns', wagtail.core.blocks.StructBlock([('left_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('middle_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('right_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('recent_articles', wagtail.core.blocks.StructBlock([('num_articles', wagtail.core.blocks.IntegerBlock(help_text='Number of recent articles to display.', label='Number of articles'))]))], null=True), - ), + model_name="homepage", + name="featured_articles", + field=wagtail.core.fields.StreamField( + [ + ( + "one_column", + wagtail.core.blocks.StructBlock( + [ + ( + "column", + wagtail.core.blocks.StructBlock( + [ + ( + "article", + wagtail.core.blocks.PageChooserBlock( + page_type=["core.ArticlePage"] + ), + ), + ( + "headline", + wagtail.core.blocks.RichTextBlock( + help_text="Optional. Will override the article's headline.", + required=False, + ), + ), + ] + ), + ) + ] + ), + ), + ( + "one_ad_column", + wagtail.core.blocks.StructBlock( + [ + ("image", wagtail.images.blocks.ImageChooserBlock()), + ( + "caption", + wagtail.core.blocks.RichTextBlock( + features=["italic"], required=False + ), + ), + ( + "link", + wagtail.core.blocks.URLBlock( + label="target", required="false" + ), + ), + ( + "size", + wagtail.core.blocks.ChoiceBlock( + choices=[ + ("small", "Small"), + ("medium", "Medium"), + ("large", "Large"), + ], + help_text="Width of image in ad.", + ), + ), + ] + ), + ), + ( + "two_columns", + wagtail.core.blocks.StructBlock( + [ + ( + "left_column", + wagtail.core.blocks.StructBlock( + [ + ( + "article", + wagtail.core.blocks.PageChooserBlock( + page_type=["core.ArticlePage"] + ), + ), + ( + "headline", + wagtail.core.blocks.RichTextBlock( + help_text="Optional. Will override the article's headline.", + required=False, + ), + ), + ] + ), + ), + ( + "right_column", + wagtail.core.blocks.StructBlock( + [ + ( + "article", + wagtail.core.blocks.PageChooserBlock( + page_type=["core.ArticlePage"] + ), + ), + ( + "headline", + wagtail.core.blocks.RichTextBlock( + help_text="Optional. Will override the article's headline.", + required=False, + ), + ), + ] + ), + ), + ( + "emphasize_column", + wagtail.core.blocks.ChoiceBlock( + choices=[("left", "Left"), ("right", "Right")], + help_text="Which article, if either, should appear larger.", + required=False, + ), + ), + ] + ), + ), + ( + "three_columns", + wagtail.core.blocks.StructBlock( + [ + ( + "left_column", + wagtail.core.blocks.StructBlock( + [ + ( + "article", + wagtail.core.blocks.PageChooserBlock( + page_type=["core.ArticlePage"] + ), + ), + ( + "headline", + wagtail.core.blocks.RichTextBlock( + help_text="Optional. Will override the article's headline.", + required=False, + ), + ), + ] + ), + ), + ( + "middle_column", + wagtail.core.blocks.StructBlock( + [ + ( + "article", + wagtail.core.blocks.PageChooserBlock( + page_type=["core.ArticlePage"] + ), + ), + ( + "headline", + wagtail.core.blocks.RichTextBlock( + help_text="Optional. Will override the article's headline.", + required=False, + ), + ), + ] + ), + ), + ( + "right_column", + wagtail.core.blocks.StructBlock( + [ + ( + "article", + wagtail.core.blocks.PageChooserBlock( + page_type=["core.ArticlePage"] + ), + ), + ( + "headline", + wagtail.core.blocks.RichTextBlock( + help_text="Optional. Will override the article's headline.", + required=False, + ), + ), + ] + ), + ), + ] + ), + ), + ( + "recent_articles", + wagtail.core.blocks.StructBlock( + [ + ( + "num_articles", + wagtail.core.blocks.IntegerBlock( + help_text="Number of recent articles to display.", + label="Number of articles", + ), + ) + ] + ), + ), + ], + null=True, + ), + ) ] From 2fc68e6eb33a83c1984c5c5cb04699d1c91db674 Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 19:57:52 -0400 Subject: [PATCH 09/36] remove something that shoudlnt be there --- core/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/models.py b/core/models.py index 7b182f06..311af0fd 100644 --- a/core/models.py +++ b/core/models.py @@ -109,7 +109,7 @@ class StaffPage(Page): search_fields = [index.SearchField("first_name"), index.SearchField("last_name")] - parent_page_types = ["StaffIndexPage", "ArticlesIndexPage"] + parent_page_types = ["StaffIndexPage"] subpage_types = [] @property @@ -540,7 +540,7 @@ def get_meta_tags(self): class ArticlesIndexPage(RoutablePageMixin, Page): - subpage_types = ["ArticlePage", "StaffPage"] + subpage_types = ["ArticlePage"] @route(r"^(\d{4})\/(\d{2})\/(.*)\/$") def post_by_date(self, request, year, month, slug, *args, **kwargs): From 15ac843b22c0b80a209844893464abbb795cc131 Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 20:11:59 -0400 Subject: [PATCH 10/36] remove unused fields --- home/templates/home/home_page.html | 3 --- pipeline/settings/dev.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/home/templates/home/home_page.html b/home/templates/home/home_page.html index 06ad2110..28be59c9 100644 --- a/home/templates/home/home_page.html +++ b/home/templates/home/home_page.html @@ -67,9 +67,6 @@

-
-
{{ block.value.column.article.specific.summary|richtext }}
-
{% elif block.block_type == "two_columns" %}
Date: Tue, 24 Sep 2019 20:14:33 -0400 Subject: [PATCH 11/36] undo --- pipeline/settings/dev.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/settings/dev.py b/pipeline/settings/dev.py index 5ff16658..9b0eac29 100644 --- a/pipeline/settings/dev.py +++ b/pipeline/settings/dev.py @@ -36,7 +36,7 @@ DATABASES = { "default": dj_database_url.config( - default="postgresql://postgres:postgres@127.0.0.1:5432/pq" + default="postgresql://postgres:postgres@127.0.0.1:5432/pipeline" ) } From 7755c3e9ebbab939f0c7f51aa887f9d33a6bb43e Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 22:35:17 -0400 Subject: [PATCH 12/36] make link not reqd --- core/models.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/core/models.py b/core/models.py index 311af0fd..7899b346 100644 --- a/core/models.py +++ b/core/models.py @@ -316,13 +316,7 @@ class Meta: class AdBlock(StructBlock): image = ImageChooserBlock() - caption = RichTextBlock(features=["italic"], required=False) - link = URLBlock(label="target", required="false") - size = ChoiceBlock( - choices=[("small", "Small"), ("medium", "Medium"), ("large", "Large")], - default="medium", - help_text="Width of image in ad.", - ) + link = URLBlock(label="target", required=False) class Meta: icon = "image" From d3f0884ae62f67de04b7648b6443d6915362d4a6 Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 22:48:47 -0400 Subject: [PATCH 13/36] optional link, add label --- core/models.py | 2 +- home/templates/home/home_page.html | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/models.py b/core/models.py index 7899b346..b57cf966 100644 --- a/core/models.py +++ b/core/models.py @@ -315,7 +315,7 @@ class Meta: class AdBlock(StructBlock): - image = ImageChooserBlock() + image = ImageChooserBlock(help_text="Image should be 22:7") link = URLBlock(label="target", required=False) class Meta: diff --git a/home/templates/home/home_page.html b/home/templates/home/home_page.html index 28be59c9..38f1fd16 100644 --- a/home/templates/home/home_page.html +++ b/home/templates/home/home_page.html @@ -62,9 +62,13 @@

ADVERTISEMENT {% image block.value.image width-1200 height-400 as photo %}
+ {% if block.value.link != "" %} + {% endif %} + {% if block.value.link != "" %} + {% endif %}

From 7841da39e419303c7c9680c94142cc75a20af29b Mon Sep 17 00:00:00 2001 From: Joseph Lyon Date: Tue, 24 Sep 2019 23:14:46 -0400 Subject: [PATCH 14/36] migrations --- home/migrations/0003_auto_20190925_0314.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 home/migrations/0003_auto_20190925_0314.py diff --git a/home/migrations/0003_auto_20190925_0314.py b/home/migrations/0003_auto_20190925_0314.py new file mode 100644 index 00000000..7655a12e --- /dev/null +++ b/home/migrations/0003_auto_20190925_0314.py @@ -0,0 +1,21 @@ +# Generated by Django 2.2.5 on 2019-09-25 03:14 + +from django.db import migrations +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.images.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0002_auto_20190924_2345'), + ] + + operations = [ + migrations.AlterField( + model_name='homepage', + name='featured_articles', + field=wagtail.core.fields.StreamField([('one_column', wagtail.core.blocks.StructBlock([('column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('one_ad_column', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(help_text='Image should be 22:7')), ('link', wagtail.core.blocks.URLBlock(label='target', required=False))])), ('two_columns', wagtail.core.blocks.StructBlock([('left_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('right_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('emphasize_column', wagtail.core.blocks.ChoiceBlock(choices=[('left', 'Left'), ('right', 'Right')], help_text='Which article, if either, should appear larger.', required=False))])), ('three_columns', wagtail.core.blocks.StructBlock([('left_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('middle_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))])), ('right_column', wagtail.core.blocks.StructBlock([('article', wagtail.core.blocks.PageChooserBlock(page_type=['core.ArticlePage'])), ('headline', wagtail.core.blocks.RichTextBlock(help_text="Optional. Will override the article's headline.", required=False))]))])), ('recent_articles', wagtail.core.blocks.StructBlock([('num_articles', wagtail.core.blocks.IntegerBlock(help_text='Number of recent articles to display.', label='Number of articles'))]))], null=True), + ), + ] From 93e7bbd2d2b7fb32ed734d4880b7a679a7825b22 Mon Sep 17 00:00:00 2001 From: Pragati Pant Date: Fri, 27 Sep 2019 15:25:53 -0400 Subject: [PATCH 15/36] Started work on a marquee banner. Right now it shows moving text and has basic outline. Needs to be styled better. --- core/models.py | 3 +++ home/models.py | 3 ++- home/templates/home/home_page.html | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/models.py b/core/models.py index b57cf966..8d9b5e0d 100644 --- a/core/models.py +++ b/core/models.py @@ -321,6 +321,9 @@ class AdBlock(StructBlock): class Meta: icon = "image" +class MarqueeBlock(StructBlock): + body=RichTextBlock(required=True) + class GalleryPhotoBlock(StructBlock): image = ImageChooserBlock() diff --git a/home/models.py b/home/models.py index 38c1008f..f01cc2a4 100644 --- a/home/models.py +++ b/home/models.py @@ -3,7 +3,7 @@ from wagtail.admin.edit_handlers import StreamFieldPanel from wagtail.core import blocks -from core.models import ArticlePage, ArticlesIndexPage, AdBlock +from core.models import ArticlePage, ArticlesIndexPage, AdBlock, MarqueeBlock class ArticleBlock(blocks.StructBlock): @@ -92,6 +92,7 @@ class HomePage(Page): ("two_columns", TwoColumnBlock()), ("three_columns", ThreeColumnBlock()), ("recent_articles", RecentArticlesBlock()), + ("marquee_banner", MarqueeBlock()), ], null=True, ) diff --git a/home/templates/home/home_page.html b/home/templates/home/home_page.html index 38f1fd16..2e5c6b69 100644 --- a/home/templates/home/home_page.html +++ b/home/templates/home/home_page.html @@ -33,7 +33,11 @@
{% for block in page.featured_articles %}
- {% if block.block_type == "one_column" %} + {% if block.block_type == "marquee_banner" %} +
+ {{block.value.body}} +
+ {% elif block.block_type == "one_column" %}