class GenericPage(TranslatablePage): """ Generic page class which allows rich text and quote components to be added. Similar page to GenericPageWithSubNav but does not include the sub-navigation component. """ parent_page_types = [ "base.HomePage", "base.GenericPageWithSubNav", "base.GenericPage" ] subpage_types = [ "base.GenericPageWithSubNav", "base.GenericPage", "sponsors.SponsorsPage" ] introduction = RichTextField(blank=True, default="") body = StreamField([ ("rich_text_section", blocks.RichTextWithTitleBlock()), ("quote_section", blocks.QuoteBlock()), ], null=True, blank=True) content_panels = TranslatablePage.content_panels + [ FieldPanel("introduction"), StreamFieldPanel("body"), ]
class GenericPageWithSubNav(TranslatablePage): """ Generic page class which allows rich text and quote components to be added. Can only be added under the homepage but can be nested itself. Page includes a sub navigation on the left of the layout for quick links to content on the page. This is auto genereated based on the body components. """ parent_page_types = [ "base.HomePage", "base.GenericPageWithSubNav", "base.GenericPage" ] subpage_types = [ "base.GenericPageWithSubNav", "base.GenericPage", "sponsors.SponsorsPage" ] navigation_title = models.CharField(max_length=120, null=True, blank=True, help_text=_("Title for Navigation")) body = StreamField([ ("rich_text_section", blocks.RichTextWithTitleBlock()), ("quote_section", blocks.QuoteBlock()), ], null=True, blank=True) content_panels = TranslatablePage.content_panels + [ FieldPanel("navigation_title"), StreamFieldPanel("body"), ]
class CaseStudyPage(TranslatablePage): """ A TranslatablePage class used for case studies pages. """ parent_page_types = ["case_studies.CaseStudiesListingPage"] subpage_types = [] introduction = models.CharField(max_length=240) header_image = models.ForeignKey( 'wagtailimages.Image', null=True, related_name='+', on_delete=models.SET_NULL, help_text=_("Image dimensions should be 1912px wide × 714px high")) header_image_description = models.CharField(max_length=240) publication_date = models.DateField() collaborator = models.CharField(max_length=120) read_time = models.IntegerField( help_text=_("Time taken (in minutes) to read the case study")) section_tags = ClusterTaggableManager( through=CaseStudyGuidelinesSectionTag, blank=True) body = StreamField([ ("rich_text_section", blocks.RichTextWithTitleBlock()), ("simple_rich_text_section", blocks.SimpleRichTextBlock()), ("quote_section", blocks.QuoteBlock()), ], null=True, blank=True) content_panels = TranslatablePage.content_panels + [ ImageChooserPanel("header_image"), FieldPanel('header_image_description'), FieldPanel('publication_date'), FieldPanel('read_time'), FieldPanel('collaborator'), FieldPanel('section_tags'), FieldPanel('introduction'), StreamFieldPanel("body"), ] search_fields = TranslatablePage.search_fields + [ index.SearchField('title'), index.SearchField('body'), ] def get_context(self, request, *args, **kwards): context = super().get_context(request, *args, **kwards) siblings = CaseStudyPage.objects.filter( language__code=request.LANGUAGE_CODE).order_by( '-publication_date').live() case_study_list = list(siblings.values_list('pk', flat=True)) if self.pk in case_study_list: current_idx = case_study_list.index(self.pk) case_study_length = len(case_study_list) - 1 # 0 based index if current_idx + 1 <= case_study_length: context['next_page'] = siblings[current_idx + 1] if current_idx - 1 >= 0: context['prev_page'] = siblings[current_idx - 1] return context def save(self, *args, **kwards): try: clear_case_study_cache(self.language.code) except Exception: logging.error('Error deleting CaseStudyPage cache') pass return super().save(*args, **kwards)
def test_quote_block_template(self): self.assertEquals(ictgs_blocks.QuoteBlock().get_template(), 'streams/quote_block.html')
def test_do_dont_block_input_types_count(self): child_blocks = ictgs_blocks.QuoteBlock().child_blocks self.assertEquals(len(child_blocks), 2)
def test_quote_block_input_types(self): child_blocks = ictgs_blocks.QuoteBlock().child_blocks assert type(child_blocks['quote']) is blocks.CharBlock assert type(child_blocks['attribution']) is blocks.CharBlock