diff --git a/opentech/public/funds/templates/public_funds/blocks/related_projects.html b/opentech/public/funds/templates/public_funds/blocks/related_projects.html index c3606bd6d83624f1918700d4a288be583bdd6748..e172378a281b6863376335a04e1b867f46b1470d 100644 --- a/opentech/public/funds/templates/public_funds/blocks/related_projects.html +++ b/opentech/public/funds/templates/public_funds/blocks/related_projects.html @@ -2,17 +2,15 @@ <div class="wrapper wrapper--breakout"> <div class="wrapper--media-boxes"> <div class="grid grid--two grid--medium-gap"> - {% for funding in page.projectfunding_set.unique %} - {% if funding.page.live %} - {% if forloop.counter0 == 10 %} - <input class="show-more--checkbox" type="checkbox" id="projects-toggle"> - <label class="link link--button link--button__center show-more--button" for="projects-toggle">Show more</label> - {% endif %} - {% if forloop.counter0 < 10 %} - {% include "public_funds/includes/project_listing.html" with project=funding.page %} - {% else %} - {% include "public_funds/includes/project_listing.html" with project=funding.page class="show-more--target" %} - {% endif %} + {% for project in page.projectfunding_set.projects %} + {% if forloop.counter0 == 10 %} + <input class="show-more--checkbox" type="checkbox" id="projects-toggle"> + <label class="link link--button link--button__center show-more--button" for="projects-toggle">Show more</label> + {% endif %} + {% if forloop.counter0 < 10 %} + {% include "public_funds/includes/project_listing.html" with project=project %} + {% else %} + {% include "public_funds/includes/project_listing.html" with project=project class="show-more--target" %} {% endif %} {% endfor %} </div> @@ -23,17 +21,15 @@ <div class="wrapper wrapper--breakout"> <div class="wrapper--media-boxes"> <div class="grid grid--two grid--medium-gap"> - {% for funding in page.funding_set.unique %} + {% for person in page.funding_set.people %} {% if forloop.counter0 == 10 %} <input class="show-more--checkbox" type="checkbox" id="fellows-toggle"> <label class="link link--button link--button__center show-more--button" for="fellows-toggle">Show more</label> {% endif %} - {% if funding.page.active and funding.page.live %} - {% if forloop.counter0 < 10 %} - {% include "public_funds/includes/reviewer_listing.html" with person=funding.page.specific %} - {% else %} - {% include "public_funds/includes/reviewer_listing.html" with person=funding.page.specific class="show-more--target"%} - {% endif %} + {% if forloop.counter0 < 10 %} + {% include "public_funds/includes/reviewer_listing.html" with person=person %} + {% else %} + {% include "public_funds/includes/reviewer_listing.html" with person=person class="show-more--target"%} {% endif %} {% endfor %} </div> diff --git a/opentech/public/funds/templates/public_funds/blocks/related_reviewers.html b/opentech/public/funds/templates/public_funds/blocks/related_reviewers.html index 667d495ec6e5c44e5e6c6e967da69dfc06e898e4..8ff35ff9da7e72694bddfddd3433e82c950d05fa 100644 --- a/opentech/public/funds/templates/public_funds/blocks/related_reviewers.html +++ b/opentech/public/funds/templates/public_funds/blocks/related_reviewers.html @@ -2,20 +2,16 @@ <div class="wrapper wrapper--breakout"> <div class="wrapper--media-boxes"> <div class="grid grid--two grid--medium-gap"> - {% for person in page.reviewers.all %} - {% with person_page=person.reviewer.specific %} - {% if person_page.active and person_page.live %} - {% if forloop.counter0 == 10 %} - <input class="show-more--checkbox" type="checkbox" id="reviewers-toggle"> - <label class="link link--button link--button__center show-more--button" for="reviewers-toggle">Show more</label> - {% endif %} - {% if forloop.counter0 < 10 %} - {% include "public_funds/includes/reviewer_listing.html" with person=person.reviewer.specific %} - {% else %} - {% include "public_funds/includes/reviewer_listing.html" with person=person.reviewer.specific class="show-more--target" %} - {% endif %} + {% for person in page.reviewers.people %} + {% if forloop.counter0 == 10 %} + <input class="show-more--checkbox" type="checkbox" id="reviewers-toggle"> + <label class="link link--button link--button__center show-more--button" for="reviewers-toggle">Show more</label> + {% endif %} + {% if forloop.counter0 < 10 %} + {% include "public_funds/includes/reviewer_listing.html" with person=person %} + {% else %} + {% include "public_funds/includes/reviewer_listing.html" with person=person class="show-more--target" %} {% endif %} - {% endwith %} {% endfor %} </div> </div> diff --git a/opentech/public/people/models.py b/opentech/public/people/models.py index 7a85671d438943900446726531baeeedad5559e8..4fbe6d31eb8e05d4ec27a69bb178746023bc39a5 100644 --- a/opentech/public/people/models.py +++ b/opentech/public/people/models.py @@ -5,7 +5,7 @@ from django.conf import settings from modelcluster.fields import ParentalKey -from wagtail.core.models import Orderable +from wagtail.core.models import Orderable, PageManager, PageQuerySet from wagtail.core.fields import StreamField from wagtail.admin.edit_handlers import ( FieldPanel, @@ -73,15 +73,15 @@ class PersonPagePersonType(models.Model): return self.person_type.title -class FundingQueryset(models.QuerySet): - def unique(self): - return self.order_by().distinct('page') +class FundingQuerySet(models.QuerySet): + def people(self): + return PersonPage.objects.filter(id__in=self.values_list('page__id')).live().active().public() class Funding(BaseFunding): page = ParentalKey('PersonPage', related_name='funding') - objects = FundingQueryset.as_manager() + objects = FundingQuerySet.as_manager() class PersonContactInfomation(Orderable): @@ -123,15 +123,27 @@ class PersonContactInfomation(Orderable): }) +class ReviewerQuerySet(models.QuerySet): + def people(self): + return PersonPage.objects.filter(id__in=self.values_list('reviewer__id')).live().active().public() + + class FundReviewers(RelatedPage): page = models.ForeignKey('wagtailcore.Page', null=True, blank=True, on_delete=models.SET_NULL, related_name='reviewers') reviewer = ParentalKey('PersonPage', related_name='funds_reviewed') + objects = ReviewerQuerySet.as_manager() + panels = [ PageChooserPanel('page', 'public_funds.FundPage'), ] +class PersonQuerySet(PageQuerySet): + def active(self): + return self.filter(active=True) + + class PersonPage(FundingMixin, BasePage): subpage_types = [] parent_page_types = ['PersonIndexPage'] @@ -154,6 +166,8 @@ class PersonPage(FundingMixin, BasePage): biography = StreamField(StoryBlock(), blank=True) email = models.EmailField(blank=True) + objects = PageManager.from_queryset(PersonQuerySet)() + search_fields = BasePage.search_fields + [ index.SearchField('introduction'), index.SearchField('biography') diff --git a/opentech/public/projects/models.py b/opentech/public/projects/models.py index d182c5a942add4c283e29c0913384163774afcfc..70e859544ffb898169470ac33f675e34093331bc 100644 --- a/opentech/public/projects/models.py +++ b/opentech/public/projects/models.py @@ -85,8 +85,8 @@ class ProjectPageRelatedPage(RelatedPage): class ProjectFundingQueryset(models.QuerySet): - def unique(self): - return self.order_by().distinct('page') + def projects(self): + return ProjectPage.objects.filter(id__in=self.values_list('page__id')).live().public() class ProjectFunding(BaseFunding):