Skip to content

Commit

Permalink
Merge pull request #92 from springload/feature/article-tile-block-bed
Browse files Browse the repository at this point in the history
Add tags and recent work tile blocks to Profile Page
  • Loading branch information
sarahframe authored Jun 10, 2024
2 parents fb094be + ba912f5 commit 1ae2d98
Show file tree
Hide file tree
Showing 11 changed files with 5,645 additions and 22 deletions.
698 changes: 698 additions & 0 deletions cdhweb/blog/migrations/0012_alter_blogpost_body.py

Large diffs are not rendered by default.

698 changes: 698 additions & 0 deletions cdhweb/events/migrations/0017_alter_event_body.py

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

37 changes: 28 additions & 9 deletions cdhweb/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
from taggit.managers import TaggableManager
from taggit.models import TaggedItemBase
from wagtail.admin.panels import FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel
from wagtail.fields import RichTextField
from wagtail.models import Page
Expand Down Expand Up @@ -257,6 +259,14 @@ def order_by_position(self):
).order_by("min_title", "min_start", "last_name")


class PersonTag(TaggedItemBase):
"""Tags for Profile Pages"""

content_object = ParentalKey(
"people.Profile", on_delete=models.CASCADE, related_name="tagged_items"
)


class Person(ClusterableModel):
# in cdhweb 2.x this was a proxy model for User;
# in 3.x it is a distinct model with 1-1 optional relationship to User
Expand Down Expand Up @@ -481,6 +491,7 @@ class Profile(BasePage):
related_name="+",
) # no reverse relationship
education = RichTextField(features=PARAGRAPH_FEATURES, blank=True)
tags = ClusterTaggableManager(through=PersonTag, blank=True)

# admin edit configuration
content_panels = Page.content_panels + [
Expand All @@ -493,15 +504,19 @@ class Profile(BasePage):
parent_page_types = ["people.PeopleLandingPageArchived", "people.PeopleLandingPage"]
subpage_types = []

promote_panels = [
MultiFieldPanel(
[
FieldPanel("short_title"),
FieldPanel("feed_image"),
],
"Share Page",
),
] + BasePage.promote_panels
promote_panels = (
[
MultiFieldPanel(
[
FieldPanel("short_title"),
FieldPanel("feed_image"),
],
"Share Page",
),
]
+ BasePage.promote_panels
+ [FieldPanel("tags")]
)

# index fields
search_fields = BasePage.search_fields + [index.SearchField("education")]
Expand All @@ -515,11 +530,15 @@ def get_context(self, request):
"""Add recent BlogPosts by this Person to their Profile."""
context = super().get_context(request)
# get 3 most recent published posts with this person as author;
# get 3 most recent events with this person as a speaker;
# get 3 most recent projects with this person as a member;
# add to context and set open graph metadata
context.update(
{
"opengraph_type": "profile",
"recent_posts": self.person.posts.live().recent()[:3],
"recent_events": self.person.events.live().recent()[:3],
"recent_projects": self.person.members.live().recent()[:3],
}
)
return context
Expand Down

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion cdhweb/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def order_by_newest_grant(self):
"-last_start", "title"
)

def recent(self):
"""Order projects by date published."""
return self.order_by("-first_published_at")


# custom manager for wagtail pages, see:
# https://docs.wagtail.io/en/stable/topics/pages.html#custom-page-managers
Expand Down Expand Up @@ -110,7 +114,9 @@ class Project(BasePage, ClusterableModel, StandardHeroMixin):
help_text="Project is a long-term collaborative group associated with the CDH.",
)

members = models.ManyToManyField(Person, through="Membership")
members = models.ManyToManyField(
Person, through="Membership", related_name="members"
)
tags = ClusterTaggableManager(through=ProjectTag, blank=True)
# TODO attachments (#245)

Expand Down
2 changes: 1 addition & 1 deletion templates/cdhpages/blocks/standard_tile_block.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@

<div class="tiles__list">
{% for tile in tiles %}
{% include 'cdhpages/blocks/tile.html' with has_component_title=self.heading.heading %}
{% include 'cdhpages/blocks/tile.html' with internal_page=tile.value.page tile_type=tile.block.name has_component_title=self.heading.heading %}
{% endfor %}
</div>
14 changes: 5 additions & 9 deletions templates/cdhpages/blocks/tile.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{% load wagtailcore_tags wagtailimages_tags l10n %}

{% with tile.value.page as internal_page %}

<div
class="tile"
href="{% if tile.block.name == 'internal_page_tile' %}{{ internal_page.url }}{% else %}{{ tile.value.external_link }}{% endif %}"
href="{% if tile_type == 'internal_page_tile' %}{{ internal_page.url }}{% else %}{{ tile.value.external_link }}{% endif %}"
>
<div class="tile__text">
<a
class="tile__link"
href="{% if tile.block.name == 'internal_page_tile' %}{{ internal_page.url }}{% else %}{{ tile.value.external_link }}{% endif %}"
href="{% if tile_type == 'internal_page_tile' %}{{ internal_page.url }}{% else %}{{ tile.value.external_link }}{% endif %}"
>
<{% if has_component_title %}h3{% else %}h2{% endif %}>
{% if tile.block.name == 'internal_page_tile' %}
{% if tile_type == 'internal_page_tile' %}
{{ internal_page.specific.short_title|default:internal_page.specific.title }}
{% else %}
{# External tile title #}
Expand All @@ -22,7 +20,7 @@
</a>

{# Internal page deets #}
{% if tile.block.name == 'internal_page_tile' %}
{% if tile_type == 'internal_page_tile' %}

{{ internal_page.specific.description|richtext }}

Expand Down Expand Up @@ -72,7 +70,7 @@
{% endif %}

<div class="tile__img-wrapper">
{% if tile.block.name == 'internal_page_tile' %}
{% if tile_type == 'internal_page_tile' %}
{% if internal_page.specific.feed_image %}
{% image internal_page.specific.feed_image fill-900x493 format-webp as image %}
<img src="{{ image.url }}" alt="{{ image.alt }}" />
Expand All @@ -92,8 +90,6 @@
</div>
</div>

{% endwith %}

{% comment %}
{# TODO, do something with this maybe? Once blog/news exists #}
{% if internal_page.specific.page_type == 'BlogPost' %}
Expand Down
7 changes: 5 additions & 2 deletions templates/includes/person_hero.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
<h1>{{ self.title}}</h1>
<p class="person-hero__job">{{ person.current_title }}</p>
<div class="person-hero__education">{{ page.education|richtext }}</div>
{% if self.tags %}
<div class="tag-list">
<div class="tag">TODO tag 1</div>
<div class="tag">TODO tag 2 etc</div>
{% for tag in self.tags.all %}
<div class="tag">{{ tag }}</div>
{% endfor %}
</div>
{% endif %}
</div>
<div class="person-hero__contact">
<ul class="person-hero__contact-links">
Expand Down
21 changes: 21 additions & 0 deletions templates/people/person_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,26 @@
</div>
</div>
</div>
{% if recent_projects %}
<h3>Recent Projects</h3>
{% for project in recent_projects %}
{% include 'cdhpages/blocks/tile.html' with internal_page=project tile_type='internal_page_tile' %}
{% endfor %}
{% endif %}

{% if recent_events %}
<h3>Recent Events</h3>
{% for event in recent_events %}
{% include 'cdhpages/blocks/tile.html' with internal_page=event tile_type='internal_page_tile' %}
{% endfor %}
{% endif %}

{# TODO - when blog page exists #}
{% if recent_posts %}
<h3>Recent Posts</h3>
{% for post in recent_posts %}
{% include 'cdhpages/blocks/tile.html' with internal_page=post tile_type='internal_page_tile' %}
{% endfor %}
{% endif %}

{% endblock %}

0 comments on commit 1ae2d98

Please sign in to comment.