diff --git a/home/blocks.py b/home/blocks.py index 5322e0b9d..42f30b08b 100644 --- a/home/blocks.py +++ b/home/blocks.py @@ -363,6 +363,76 @@ def get_context(self, value, parent_context=None): return context + +class AbstractArticleGroup(TemplateSelectStructBlock): + + template = blocks.ChoiceBlock( + choices=[ + ('infinitefeed/sidebar/sidebar_section_block.html', 'default'), + ] + ) + + def get_context(self, value, parent_context=None): + context = super().get_context(value, parent_context) + context["link"] = "" + context["article_groups"] = [] + return context + +class MidStreamGroupedArticlesTemplates(blocks.ChoiceBlock): + + choices=[ + ('section/objects/grouped_articles_timeline.html', 'Timeline'), + ] + + +class ManualArticleGroup(AbstractArticleGroup): + title = blocks.CharBlock( + required=False, + max_length=255, + ) + description = blocks.RichTextBlock(required=False) + link = blocks.URLBlock(required=False) + template = MidStreamGroupedArticlesTemplates() + highlight_colour = blocks.CharBlock( + required=False, + default='0071c9', + max_length=6, + help_text="Only applicable to some templates" + ) + hide_mobile = field_block.BooleanBlock( + required=False, + help_text="If checked, will hide on small devices", + default=False + ) + + article_groups = blocks.ListBlock( + blocks.StructBlock([ + ('title', blocks.CharBlock()), + ('description', blocks.CharBlock()), + ('articles', blocks.ListBlock( + blocks.StructBlock([ + ('alias', blocks.CharBlock(required=False)), + ('article', field_block.PageChooserBlock(page_type='article.ArticlePage', required=False)) + ]) + )) + ]) + ) + + + def get_context(self, value, parent_context=None): + context = super().get_context(value, parent_context=parent_context) + context['title'] = value['title'] + context['description'] = value['description'] + context['link'] = value['link'] + + for group_block in value['article_groups']: + group = {} + group["title"] = group_block["title"] + group["description"] = group_block["description"] + group["articles"] = [article for article in group_block["articles"]] + context['article_groups'].append(group) + + return context class SidebarArticleGatherer(ArticleGathererBlock): diff --git a/section/models.py b/section/models.py index 5a3d200f5..64737faf7 100644 --- a/section/models.py +++ b/section/models.py @@ -3,6 +3,7 @@ from article.models import ArticlePage from home import blocks as homeblocks +from article import blocks as article_blocks from django.core.cache import cache from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator @@ -189,6 +190,8 @@ class SectionPage(RoutablePageMixin, SectionablePage): ('landing', homeblocks.SpecialLandingPageBlock()), ('article_manual', homeblocks.ManualArticles()), ('article_gatherer_with_pinned', homeblocks.ArticleGathererWithPinnedBlock()), + ('grouped_articles_manual', homeblocks.ManualArticleGroup()), + ('header_menu', article_blocks.HeaderMenuBlock()), ], null=True, blank=True, diff --git a/section/templates/section/objects/grouped_articles_timeline.html b/section/templates/section/objects/grouped_articles_timeline.html new file mode 100644 index 000000000..4ddc8bcb8 --- /dev/null +++ b/section/templates/section/objects/grouped_articles_timeline.html @@ -0,0 +1,46 @@ +{% load humanize %} +{% load cache %} +{% load wagtailcore_tags %} +{% load wagtailimages_tags %} +{% load video_filters %} +{% load articletags %} + +