Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up "default-to-current" on the project landing page #140

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cdhweb/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,14 @@ class ProjectsLandingPage(StandardHeroMixin, Page):
subpage_types = [Project]

def get_child_queryset(self, request, filter_form):
clean_filters = filter_form.cleaned_data
# Sometimes we pass the empty form, which isn't cleanable

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the extra comments

clean_filters = getattr(filter_form, "cleaned_data", {})
query_string = clean_filters.pop("q", None)

# It's not currently possible to filter by
# RelatedFields, so because current-ness is part of
# Grants we need to apply this later
current_filter = clean_filters.pop("current")
# Grants we need to apply this later, defaults True
current_filter = clean_filters.pop("current", True)

# Use a Project queryset so we can apply type-specific filters
children = Project.objects.child_of(self).public().live()
Expand Down Expand Up @@ -427,7 +428,10 @@ def get_context(self, request, year=None, month=None):

context = super().get_context(request)
form_args = request.GET.dict()
form = ProjectFiltersForm(form_args)
if form_args:
form = ProjectFiltersForm(form_args)
else:
form = ProjectFiltersForm()

form.is_valid()
child_queryset = self.get_child_queryset(request, form)
Expand All @@ -443,6 +447,10 @@ def get_context(self, request, year=None, month=None):
context["featured_project"] = self.featured_project
child_queryset = child_queryset.exclude(pk=self.featured_project.pk)

child_queryset = child_queryset.prefetch_related(
"members", "method", "field", "role", "hero_image", "hero_image__renditions"
)

context["results"] = child_queryset
context["filter_form"] = form

Expand Down
Loading