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

Implement board member details as snippet #1189

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hancush
Copy link
Collaborator

@hancush hancush commented Dec 20, 2024

Overview

This PR adds a Django model for board member headshots and bios and registers as a snippet for editing in the CMS. It also deprecates the headshot_url property, instead creating a shared template block that renders the right thing given a person instance and, optionally, a way to request the original aspect ratio, instead of a square thumbnail.

Connects #1176

Demo

Screenshot 2024-12-20 at 12 15 58 PM Screenshot 2024-12-20 at 12 16 03 PM Screenshot 2024-12-20 at 12 16 15 PM Screenshot 2024-12-20 at 12 16 26 PM

Notes

I decided to go ahead and implement this as a snippet, since the modeladmin module is deprecated in the next version of Wagtail, so using snippets now makes our migration path easier moving forward. I'm wondering if we might want to do this in #1185, too. https://docs.wagtail.org/en/v5.2.1/reference/contrib/modeladmin/migrating_to_snippets.html

Testing Instructions

tktktktk

from lametro.models import LAMetroPerson, BoardMemberDetails


@receiver(post_save, sender=LAMetroPerson)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will handle instantiating details for new members moving forward. To backfill, we simply need to call save on all existing board members.

Comment on lines +51 to +57
_revisions = GenericRelation(
"wagtailcore.Revision", related_query_name="member_details"
)

@property
def revisions(self):
return self._revisions
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

council_post = self.person.latest_council_membership.post
context["qualifying_post"] = council_post.acting_label

context["preview"] = True
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The map and committee/board report modules require a bunch of extra context, so I use this to purposefully omit them from page previews. (I also added a note to the admin interface.)

@@ -0,0 +1,4 @@
{% load wagtailadmin_tags %}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

More or less stolen from the Wagtail source code, to make the status icon in the board member details snippet list link to the person detail page.

return user.has_perm(self._get_permission_name(action))


class BoardMemberFilterSet(django_filters.FilterSet):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a django-filter filter set, which I'm using to add custom filters for whether a person is a current board member and what body they belong to, on the board member detail snippet listing page.

Comment on lines +128 to +137
HelpPanel(
content=(
"<p>On this page, you can manage a board member's headshot and "
"bio. All other details and relationships, e.g., memberships, "
"should be managed in Legistar.</p>"
"<p><strong>Note:</strong> The page preview excludes "
"the map and committee and board report modules displayed "
"on the live page.</p>"
)
),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🙃

register_snippet(BoardMemberDetailsViewSet)


class UserBarLink:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I pulled some reusable things out of the model admin link so I could also use them for the snippet edit link.

Comment on lines +214 to +215
finder = AdminURLFinder()
return finder.get_edit_url(snippet)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants