Skip to content

Commit 1ae2d98

Browse files
authored
Merge pull request #92 from springload/feature/article-tile-block-bed
Add tags and recent work tile blocks to Profile Page
2 parents fb094be + ba912f5 commit 1ae2d98

File tree

11 files changed

+5645
-22
lines changed

11 files changed

+5645
-22
lines changed

cdhweb/blog/migrations/0012_alter_blogpost_body.py

Lines changed: 698 additions & 0 deletions
Large diffs are not rendered by default.

cdhweb/events/migrations/0017_alter_event_body.py

Lines changed: 698 additions & 0 deletions
Large diffs are not rendered by default.

cdhweb/pages/migrations/0047_alter_contentpage_body_alter_homepage_body_and_more.py

Lines changed: 2052 additions & 0 deletions
Large diffs are not rendered by default.

cdhweb/people/migrations/0016_alter_peoplelandingpage_body_alter_profile_body_and_more.py

Lines changed: 1422 additions & 0 deletions
Large diffs are not rendered by default.

cdhweb/people/models.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
from django.urls import reverse
99
from django.utils import timezone
1010
from django.utils.functional import cached_property
11+
from modelcluster.contrib.taggit import ClusterTaggableManager
1112
from modelcluster.fields import ParentalKey
1213
from modelcluster.models import ClusterableModel
1314
from taggit.managers import TaggableManager
15+
from taggit.models import TaggedItemBase
1416
from wagtail.admin.panels import FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel
1517
from wagtail.fields import RichTextField
1618
from wagtail.models import Page
@@ -257,6 +259,14 @@ def order_by_position(self):
257259
).order_by("min_title", "min_start", "last_name")
258260

259261

262+
class PersonTag(TaggedItemBase):
263+
"""Tags for Profile Pages"""
264+
265+
content_object = ParentalKey(
266+
"people.Profile", on_delete=models.CASCADE, related_name="tagged_items"
267+
)
268+
269+
260270
class Person(ClusterableModel):
261271
# in cdhweb 2.x this was a proxy model for User;
262272
# in 3.x it is a distinct model with 1-1 optional relationship to User
@@ -481,6 +491,7 @@ class Profile(BasePage):
481491
related_name="+",
482492
) # no reverse relationship
483493
education = RichTextField(features=PARAGRAPH_FEATURES, blank=True)
494+
tags = ClusterTaggableManager(through=PersonTag, blank=True)
484495

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

496-
promote_panels = [
497-
MultiFieldPanel(
498-
[
499-
FieldPanel("short_title"),
500-
FieldPanel("feed_image"),
501-
],
502-
"Share Page",
503-
),
504-
] + BasePage.promote_panels
507+
promote_panels = (
508+
[
509+
MultiFieldPanel(
510+
[
511+
FieldPanel("short_title"),
512+
FieldPanel("feed_image"),
513+
],
514+
"Share Page",
515+
),
516+
]
517+
+ BasePage.promote_panels
518+
+ [FieldPanel("tags")]
519+
)
505520

506521
# index fields
507522
search_fields = BasePage.search_fields + [index.SearchField("education")]
@@ -515,11 +530,15 @@ def get_context(self, request):
515530
"""Add recent BlogPosts by this Person to their Profile."""
516531
context = super().get_context(request)
517532
# get 3 most recent published posts with this person as author;
533+
# get 3 most recent events with this person as a speaker;
534+
# get 3 most recent projects with this person as a member;
518535
# add to context and set open graph metadata
519536
context.update(
520537
{
521538
"opengraph_type": "profile",
522539
"recent_posts": self.person.posts.live().recent()[:3],
540+
"recent_events": self.person.events.live().recent()[:3],
541+
"recent_projects": self.person.members.live().recent()[:3],
523542
}
524543
)
525544
return context

cdhweb/projects/migrations/0019_alter_project_body_alter_project_members.py

Lines changed: 708 additions & 0 deletions
Large diffs are not rendered by default.

cdhweb/projects/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def order_by_newest_grant(self):
7373
"-last_start", "title"
7474
)
7575

76+
def recent(self):
77+
"""Order projects by date published."""
78+
return self.order_by("-first_published_at")
79+
7680

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

113-
members = models.ManyToManyField(Person, through="Membership")
117+
members = models.ManyToManyField(
118+
Person, through="Membership", related_name="members"
119+
)
114120
tags = ClusterTaggableManager(through=ProjectTag, blank=True)
115121
# TODO attachments (#245)
116122

templates/cdhpages/blocks/standard_tile_block.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222

2323
<div class="tiles__list">
2424
{% for tile in tiles %}
25-
{% include 'cdhpages/blocks/tile.html' with has_component_title=self.heading.heading %}
25+
{% include 'cdhpages/blocks/tile.html' with internal_page=tile.value.page tile_type=tile.block.name has_component_title=self.heading.heading %}
2626
{% endfor %}
2727
</div>

templates/cdhpages/blocks/tile.html

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{% load wagtailcore_tags wagtailimages_tags l10n %}
2-
3-
{% with tile.value.page as internal_page %}
42

53
<div
64
class="tile"
7-
href="{% if tile.block.name == 'internal_page_tile' %}{{ internal_page.url }}{% else %}{{ tile.value.external_link }}{% endif %}"
5+
href="{% if tile_type == 'internal_page_tile' %}{{ internal_page.url }}{% else %}{{ tile.value.external_link }}{% endif %}"
86
>
97
<div class="tile__text">
108
<a
119
class="tile__link"
12-
href="{% if tile.block.name == 'internal_page_tile' %}{{ internal_page.url }}{% else %}{{ tile.value.external_link }}{% endif %}"
10+
href="{% if tile_type == 'internal_page_tile' %}{{ internal_page.url }}{% else %}{{ tile.value.external_link }}{% endif %}"
1311
>
1412
<{% if has_component_title %}h3{% else %}h2{% endif %}>
15-
{% if tile.block.name == 'internal_page_tile' %}
13+
{% if tile_type == 'internal_page_tile' %}
1614
{{ internal_page.specific.short_title|default:internal_page.specific.title }}
1715
{% else %}
1816
{# External tile title #}
@@ -22,7 +20,7 @@
2220
</a>
2321

2422
{# Internal page deets #}
25-
{% if tile.block.name == 'internal_page_tile' %}
23+
{% if tile_type == 'internal_page_tile' %}
2624

2725
{{ internal_page.specific.description|richtext }}
2826

@@ -72,7 +70,7 @@
7270
{% endif %}
7371

7472
<div class="tile__img-wrapper">
75-
{% if tile.block.name == 'internal_page_tile' %}
73+
{% if tile_type == 'internal_page_tile' %}
7674
{% if internal_page.specific.feed_image %}
7775
{% image internal_page.specific.feed_image fill-900x493 format-webp as image %}
7876
<img src="{{ image.url }}" alt="{{ image.alt }}" />
@@ -92,8 +90,6 @@
9290
</div>
9391
</div>
9492

95-
{% endwith %}
96-
9793
{% comment %}
9894
{# TODO, do something with this maybe? Once blog/news exists #}
9995
{% if internal_page.specific.page_type == 'BlogPost' %}

templates/includes/person_hero.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
<h1>{{ self.title}}</h1>
77
<p class="person-hero__job">{{ person.current_title }}</p>
88
<div class="person-hero__education">{{ page.education|richtext }}</div>
9+
{% if self.tags %}
910
<div class="tag-list">
10-
<div class="tag">TODO tag 1</div>
11-
<div class="tag">TODO tag 2 etc</div>
11+
{% for tag in self.tags.all %}
12+
<div class="tag">{{ tag }}</div>
13+
{% endfor %}
1214
</div>
15+
{% endif %}
1316
</div>
1417
<div class="person-hero__contact">
1518
<ul class="person-hero__contact-links">

0 commit comments

Comments
 (0)