diff --git a/opentech/public/funds/migrations/0002_labindex_labpage.py b/opentech/public/funds/migrations/0002_labindex_labpage.py index 58c1f477330cd8c903db20d8a008086878cb49c5..ab9f9c903f5c6a9ffc2917fc9ee12c53879cea74 100644 --- a/opentech/public/funds/migrations/0002_labindex_labpage.py +++ b/opentech/public/funds/migrations/0002_labindex_labpage.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.8 on 2018-01-11 14:09 +# Generated by Django 1.11.8 on 2018-01-11 14:47 from __future__ import unicode_literals from django.db import migrations, models @@ -16,8 +16,8 @@ import wagtail.wagtailsnippets.blocks class Migration(migrations.Migration): dependencies = [ - ('wagtailcore', '0040_page_draft_title'), ('images', '0001_initial'), + ('wagtailcore', '0040_page_draft_title'), ('public_funds', '0001_initial'), ] @@ -47,7 +47,8 @@ class Migration(migrations.Migration): ('listing_title', models.CharField(blank=True, help_text='Override the page title used when this page appears in listings', max_length=255)), ('listing_summary', models.CharField(blank=True, help_text="The text summary used when this page appears in listings. It's also used as the description for search engines if the 'Search description' field above is not defined.", max_length=255)), ('introduction', models.TextField(blank=True)), - ('lab_link', models.URLField()), + ('lab_link', models.URLField(blank=True, verbose_name='External link')), + ('link_text', models.CharField(help_text='text to display on the button', max_length=255)), ('body', wagtail.wagtailcore.fields.StreamField((('heading', wagtail.wagtailcore.blocks.CharBlock(classname='full title', icon='title')), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailcore.blocks.StructBlock((('image', wagtail.wagtailimages.blocks.ImageChooserBlock()), ('caption', wagtail.wagtailcore.blocks.CharBlock(required=False))))), ('quote', wagtail.wagtailcore.blocks.StructBlock((('quote', wagtail.wagtailcore.blocks.CharBlock(classname='title')), ('attribution', wagtail.wagtailcore.blocks.CharBlock(required=False)), ('job_title', wagtail.wagtailcore.blocks.CharBlock(required=False))))), ('embed', wagtail.wagtailembeds.blocks.EmbedBlock()), ('call_to_action', wagtail.wagtailsnippets.blocks.SnippetChooserBlock('utils.CallToActionSnippet', template='blocks/call_to_action_block.html')), ('document', wagtail.wagtailcore.blocks.StructBlock((('document', wagtail.wagtaildocs.blocks.DocumentChooserBlock()), ('title', wagtail.wagtailcore.blocks.CharBlock(required=False))))), ('project_list', opentech.public.funds.blocks.ProjectsBlock()), ('reviewer_list', opentech.public.funds.blocks.ReviewersBlock())))), ('header_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage')), ('lab_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailcore.Page')), diff --git a/opentech/public/funds/models.py b/opentech/public/funds/models.py index 6c762f70edbce12558939b56fa015ab9069e75e7..bbb99dc065bdecb7f3d9fbc461c2efc08c458052 100644 --- a/opentech/public/funds/models.py +++ b/opentech/public/funds/models.py @@ -48,14 +48,14 @@ class FundIndex(BasePage): page = request.GET.get('page', 1) paginator = Paginator(funds, settings.DEFAULT_PER_PAGE) try: - news = paginator.page(page) + funds = paginator.page(page) except PageNotAnInteger: - news = paginator.page(1) + funds = paginator.page(1) except EmptyPage: - news = paginator.page(paginator.num_pages) + funds = paginator.page(paginator.num_pages) context = super().get_context(request, *args, **kwargs) - context.update(news=news) + context.update(subpages=funds) return context @@ -64,6 +64,13 @@ class LabPage(BasePage): parent_page_types = ['LabIndex'] introduction = models.TextField(blank=True) + icon = models.ForeignKey( + 'images.CustomImage', + null=True, + blank=True, + related_name='+', + on_delete=models.SET_NULL + ) lab_type = models.ForeignKey( 'wagtailcore.Page', blank=True, @@ -71,19 +78,26 @@ class LabPage(BasePage): on_delete=models.SET_NULL, related_name='+', ) - lab_link = models.URLField(blank=True, verbose_name="External link") + lab_link = models.URLField(blank=True, verbose_name='External link') + link_text = models.CharField(max_length=255, help_text='text to display on the button') body = StreamField(FundBlock()) content_panels = BasePage.content_panels + [ + FieldPanel('icon'), FieldPanel('introduction'), MultiFieldPanel([ # Limit to lab pages once created PageChooserPanel('lab_type'), FieldPanel('lab_link'), + FieldPanel('link_text'), ], heading='Link for lab application'), StreamFieldPanel('body'), ] + @property + def link_to_lab(self): + return self.lab_link or self.lab_type.get_url() + def clean(self): if self.lab_type and self.lab_link: raise ValidationError({ @@ -109,18 +123,18 @@ class LabIndex(BasePage): ] def get_context(self, request, *args, **kwargs): - funds = LabPage.objects.live().public().descendant_of(self) + labs = LabPage.objects.live().public().descendant_of(self) # Pagination page = request.GET.get('page', 1) - paginator = Paginator(funds, settings.DEFAULT_PER_PAGE) + paginator = Paginator(labs, settings.DEFAULT_PER_PAGE) try: - news = paginator.page(page) + labs = paginator.page(page) except PageNotAnInteger: - news = paginator.page(1) + labs = paginator.page(1) except EmptyPage: - news = paginator.page(paginator.num_pages) + labs = paginator.page(paginator.num_pages) context = super().get_context(request, *args, **kwargs) - context.update(news=news) + context.update(subpages=labs) return context diff --git a/opentech/public/funds/templates/public_funds/lab_index.html b/opentech/public/funds/templates/public_funds/lab_index.html new file mode 100644 index 0000000000000000000000000000000000000000..ce4f0b1db6ef2f27f9269c007d362c79d43b38d4 --- /dev/null +++ b/opentech/public/funds/templates/public_funds/lab_index.html @@ -0,0 +1 @@ +{% extends "standardpages/index_page.html" %} diff --git a/opentech/public/funds/templates/public_funds/lab_page.html b/opentech/public/funds/templates/public_funds/lab_page.html new file mode 100644 index 0000000000000000000000000000000000000000..2642ccfc89ba5f7287a0ffaaf9a2ff71d6ee6d13 --- /dev/null +++ b/opentech/public/funds/templates/public_funds/lab_page.html @@ -0,0 +1,17 @@ +{% extends "base.html" %} +{% load wagtailcore_tags wagtailimages_tags navigation_tags static %} + +{% block content %} + <div class="wrapper wrapper--flex"> + <section class="section section--main"> + <h1>{{ page.icon }}{{ page.title }}</h1> + <h5>{{ page.introduction }}</h5> + + {% include_block page.body %} + </section> + <section> + <a href="{{ page.link_to_lab }}">{{ page.link_text }}</a> + </section> + </div> + {% include "includes/relatedcontent.html" with related_pages=page.related_pages.all %} +{% endblock %}