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

Search content type #1561

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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 home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import models
from django.apps import apps
from django.shortcuts import redirect
from django.utils.functional import cached_property
from datetime import datetime
from pytz import timezone
from django.db.models import Q
Expand Down Expand Up @@ -368,9 +369,13 @@ class ProgramSimplePage(AbstractSimplePage):
parent_page_types = ['programs.Program', 'programs.Subprogram']
subpage_types = ['home.RedirectPage']

@cached_property
def program(self):
return self.get_parent().specific

def get_context(self, request):
context = super(ProgramSimplePage, self).get_context(request)
context['program'] = self.get_parent().specific
context['program'] = self.program

return context

Expand All @@ -388,7 +393,6 @@ class Meta:

def get_context(self, request):
context = super().get_context(request)
context['program'] = self.get_parent().specific

if getattr(request, 'is_preview', False):
program_context = context['program'].get_context(request)
Expand All @@ -406,9 +410,13 @@ class ProgramAboutPage(ProgramSimplePage):
class Meta:
verbose_name = 'Program About Page'

@cached_property
def program(self):
return Page.objects.ancestor_of(self).type(AbstractProgram).order_by('-depth').first().specific

def get_context(self, request):
context = super(ProgramSimplePage, self).get_context(request)
context['program'] = self.get_parent().get_parent().specific
context = super().get_context(request)
context['program'] = self.program
emilytoppm marked this conversation as resolved.
Show resolved Hide resolved

if getattr(request, 'is_preview', False):
program_context = context['program'].get_context(request)
Expand Down
11 changes: 8 additions & 3 deletions newamericadotorg/api/search/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from wagtail.images.views.serve import generate_image_url

from person.models import Person
from home.models import Post
from home.models import Post, Program
from event.models import Event

from newamericadotorg.api.helpers import get_content_type
Expand All @@ -23,13 +23,18 @@ def to_representation(self, obj):
data['last_name'] = obj.last_name
data['position'] = obj.position_at_new_america
elif isinstance(obj, Post) or type(obj) == Event:
data['story_image'] = generate_image_url(obj.story_image, 'max-300x240') if obj.story_image else None
data['date'] = obj.date
data['programs'] = PostProgramSerializer(obj.parent_programs, many=True).data

if isinstance(obj, Post):
data['authors'] = AuthorSerializer(obj.post_author, many=True, context=self.context).data

data['story_image'] = generate_image_url(obj.story_image, 'max-300x240') if getattr(obj, 'story_image', None) else None
kaedroho marked this conversation as resolved.
Show resolved Hide resolved

if hasattr(obj, 'parent_programs'):
data['programs'] = PostProgramSerializer(obj.parent_programs, many=True).data
else:
programs = Program.objects.ancestor_of(obj).order_by('-depth')
data['programs'] = PostProgramSerializer(programs, many=True).data

data['content_type'] = get_content_type(obj)
return data
Expand Down
10 changes: 4 additions & 6 deletions newamericadotorg/assets/react/components/ContentCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,10 @@ export const PublicationListItem = ({ post }) => (
)}
</div>
)}
{post.programs && (
<div className="h6 card__text__program caption margin-top-5 margin-top-md-15 margin-bottom-0">
{post.programs[0] ? post.programs[0].name : ''}{' '}
{post.content_type ? post.content_type.name : ''}
</div>
)}
<div className="h6 card__text__program caption margin-top-5 margin-top-md-15 margin-bottom-0">
{post.programs && post.programs[0] ? post.programs[0].name + ' ' : ''}
{post.content_type ? post.content_type.name : ''}
</div>
</div>
</div>
);