Skip to content
Snippets Groups Projects
Commit 8118a2eb authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Make the queryset of related objects work without checking the state in template

parent 47c90ea4
No related branches found
No related tags found
No related merge requests found
...@@ -2,17 +2,15 @@ ...@@ -2,17 +2,15 @@
<div class="wrapper wrapper--breakout"> <div class="wrapper wrapper--breakout">
<div class="wrapper--media-boxes"> <div class="wrapper--media-boxes">
<div class="grid grid--two grid--medium-gap"> <div class="grid grid--two grid--medium-gap">
{% for funding in page.projectfunding_set.unique %} {% for project in page.projectfunding_set.projects %}
{% if funding.page.live %} {% if forloop.counter0 == 10 %}
{% if forloop.counter0 == 10 %} <input class="show-more--checkbox" type="checkbox" id="projects-toggle">
<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>
<label class="link link--button link--button__center show-more--button" for="projects-toggle">Show more</label> {% endif %}
{% endif %} {% if forloop.counter0 < 10 %}
{% if forloop.counter0 < 10 %} {% include "public_funds/includes/project_listing.html" with project=project %}
{% include "public_funds/includes/project_listing.html" with project=funding.page %} {% else %}
{% else %} {% include "public_funds/includes/project_listing.html" with project=project class="show-more--target" %}
{% include "public_funds/includes/project_listing.html" with project=funding.page class="show-more--target" %}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
...@@ -23,17 +21,15 @@ ...@@ -23,17 +21,15 @@
<div class="wrapper wrapper--breakout"> <div class="wrapper wrapper--breakout">
<div class="wrapper--media-boxes"> <div class="wrapper--media-boxes">
<div class="grid grid--two grid--medium-gap"> <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 %} {% if forloop.counter0 == 10 %}
<input class="show-more--checkbox" type="checkbox" id="fellows-toggle"> <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> <label class="link link--button link--button__center show-more--button" for="fellows-toggle">Show more</label>
{% endif %} {% endif %}
{% if funding.page.active and funding.page.live %} {% if forloop.counter0 < 10 %}
{% if forloop.counter0 < 10 %} {% include "public_funds/includes/reviewer_listing.html" with person=person %}
{% include "public_funds/includes/reviewer_listing.html" with person=funding.page.specific %} {% else %}
{% else %} {% include "public_funds/includes/reviewer_listing.html" with person=person class="show-more--target"%}
{% include "public_funds/includes/reviewer_listing.html" with person=funding.page.specific class="show-more--target"%}
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
......
...@@ -2,20 +2,16 @@ ...@@ -2,20 +2,16 @@
<div class="wrapper wrapper--breakout"> <div class="wrapper wrapper--breakout">
<div class="wrapper--media-boxes"> <div class="wrapper--media-boxes">
<div class="grid grid--two grid--medium-gap"> <div class="grid grid--two grid--medium-gap">
{% for person in page.reviewers.all %} {% for person in page.reviewers.people %}
{% with person_page=person.reviewer.specific %} {% if forloop.counter0 == 10 %}
{% if person_page.active and person_page.live %} <input class="show-more--checkbox" type="checkbox" id="reviewers-toggle">
{% if forloop.counter0 == 10 %} <label class="link link--button link--button__center show-more--button" for="reviewers-toggle">Show more</label>
<input class="show-more--checkbox" type="checkbox" id="reviewers-toggle"> {% endif %}
<label class="link link--button link--button__center show-more--button" for="reviewers-toggle">Show more</label> {% if forloop.counter0 < 10 %}
{% endif %} {% include "public_funds/includes/reviewer_listing.html" with person=person %}
{% if forloop.counter0 < 10 %} {% else %}
{% include "public_funds/includes/reviewer_listing.html" with person=person.reviewer.specific %} {% include "public_funds/includes/reviewer_listing.html" with person=person class="show-more--target" %}
{% else %}
{% include "public_funds/includes/reviewer_listing.html" with person=person.reviewer.specific class="show-more--target" %}
{% endif %}
{% endif %} {% endif %}
{% endwith %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
......
...@@ -5,7 +5,7 @@ from django.conf import settings ...@@ -5,7 +5,7 @@ from django.conf import settings
from modelcluster.fields import ParentalKey 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.core.fields import StreamField
from wagtail.admin.edit_handlers import ( from wagtail.admin.edit_handlers import (
FieldPanel, FieldPanel,
...@@ -73,15 +73,15 @@ class PersonPagePersonType(models.Model): ...@@ -73,15 +73,15 @@ class PersonPagePersonType(models.Model):
return self.person_type.title return self.person_type.title
class FundingQueryset(models.QuerySet): class FundingQuerySet(models.QuerySet):
def unique(self): def people(self):
return self.order_by().distinct('page') return PersonPage.objects.filter(id__in=self.values_list('page__id')).live().active().public()
class Funding(BaseFunding): class Funding(BaseFunding):
page = ParentalKey('PersonPage', related_name='funding') page = ParentalKey('PersonPage', related_name='funding')
objects = FundingQueryset.as_manager() objects = FundingQuerySet.as_manager()
class PersonContactInfomation(Orderable): class PersonContactInfomation(Orderable):
...@@ -123,15 +123,27 @@ 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): class FundReviewers(RelatedPage):
page = models.ForeignKey('wagtailcore.Page', null=True, blank=True, on_delete=models.SET_NULL, related_name='reviewers') page = models.ForeignKey('wagtailcore.Page', null=True, blank=True, on_delete=models.SET_NULL, related_name='reviewers')
reviewer = ParentalKey('PersonPage', related_name='funds_reviewed') reviewer = ParentalKey('PersonPage', related_name='funds_reviewed')
objects = ReviewerQuerySet.as_manager()
panels = [ panels = [
PageChooserPanel('page', 'public_funds.FundPage'), PageChooserPanel('page', 'public_funds.FundPage'),
] ]
class PersonQuerySet(PageQuerySet):
def active(self):
return self.filter(active=True)
class PersonPage(FundingMixin, BasePage): class PersonPage(FundingMixin, BasePage):
subpage_types = [] subpage_types = []
parent_page_types = ['PersonIndexPage'] parent_page_types = ['PersonIndexPage']
...@@ -154,6 +166,8 @@ class PersonPage(FundingMixin, BasePage): ...@@ -154,6 +166,8 @@ class PersonPage(FundingMixin, BasePage):
biography = StreamField(StoryBlock(), blank=True) biography = StreamField(StoryBlock(), blank=True)
email = models.EmailField(blank=True) email = models.EmailField(blank=True)
objects = PageManager.from_queryset(PersonQuerySet)()
search_fields = BasePage.search_fields + [ search_fields = BasePage.search_fields + [
index.SearchField('introduction'), index.SearchField('introduction'),
index.SearchField('biography') index.SearchField('biography')
......
...@@ -85,8 +85,8 @@ class ProjectPageRelatedPage(RelatedPage): ...@@ -85,8 +85,8 @@ class ProjectPageRelatedPage(RelatedPage):
class ProjectFundingQueryset(models.QuerySet): class ProjectFundingQueryset(models.QuerySet):
def unique(self): def projects(self):
return self.order_by().distinct('page') return ProjectPage.objects.filter(id__in=self.values_list('page__id')).live().public()
class ProjectFunding(BaseFunding): class ProjectFunding(BaseFunding):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment