Skip to content

Commit

Permalink
Integrate wagtailautocomplete for person lookups #150
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Aug 9, 2023
1 parent 2b7be76 commit 6f40cb3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cdhweb/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from wagtail.admin.panels import FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel
from wagtail.models import Orderable, Page, PageManager, PageQuerySet
from wagtail.search import index
from wagtailautocomplete.edit_handlers import AutocompletePanel

from cdhweb.pages.models import BasePage, LinkPage, PagePreviewDescriptionMixin
from cdhweb.people.models import Person
Expand Down Expand Up @@ -79,7 +80,10 @@ class BlogPost(BasePage, ClusterableModel, PagePreviewDescriptionMixin):
content_panels = Page.content_panels + [
FieldRowPanel((FieldPanel("featured_image"), FieldPanel("featured"))),
FieldPanel("description"),
MultiFieldPanel((InlinePanel("authors", label="Author"),), heading="Authors"),
MultiFieldPanel(
[InlinePanel("authors", [AutocompletePanel("person")], label="Author")],
heading="Authors",
),
FieldPanel("body"),
FieldPanel("attachments"),
]
Expand Down
4 changes: 3 additions & 1 deletion cdhweb/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from wagtail.admin.panels import FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel
from wagtail.models import Page, PageManager, PageQuerySet
from wagtail.search import index
from wagtailautocomplete.edit_handlers import AutocompletePanel

from cdhweb.pages.models import BasePage, ContentPage, LinkPage
from cdhweb.people.models import Person
Expand Down Expand Up @@ -185,7 +186,8 @@ class Event(BasePage, ClusterableModel):
FieldRowPanel((FieldPanel("sponsor"), FieldPanel("attendance")), "Tracking"),
FieldRowPanel((FieldPanel("thumbnail"), FieldPanel("image")), "Images"),
MultiFieldPanel(
(InlinePanel("speakers", label="Speaker"),), heading="Speakers"
(InlinePanel("speakers", [AutocompletePanel("person")], label="Speaker"),),
heading="Speakers",
),
FieldPanel("body"),
FieldPanel("attachments"),
Expand Down
12 changes: 12 additions & 0 deletions cdhweb/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@ def profile_url(self):
if website:
return website.url

def autocomplete_label(self):
"""label when chosen with wagtailautocomplete"""
return str(self)

@staticmethod
def autocomplete_custom_queryset_filter(search_term):
"""custom lookup for wagtailautocomplete; searches on first and last name"""
return Person.objects.filter(
models.Q(first_name__icontains=search_term)
| models.Q(last_name__icontains=search_term)
)


@receiver(pre_delete, sender=Person)
def cleanup_profile(sender, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion cdhweb/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from wagtail.admin.panels import FieldPanel, FieldRowPanel, InlinePanel
from wagtail.models import Page, PageManager, PageQuerySet
from wagtail.search import index
from wagtailautocomplete.edit_handlers import AutocompletePanel

from cdhweb.pages.models import BasePage, DateRange, LandingPage, LinkPage, RelatedLink
from cdhweb.people.models import Person
Expand Down Expand Up @@ -155,7 +156,7 @@ class Project(BasePage, ClusterableModel):
"memberships",
panels=[
FieldRowPanel((FieldPanel("start_date"), FieldPanel("end_date"))),
FieldPanel("person"),
AutocompletePanel("person"),
FieldPanel("role"),
],
label="Members",
Expand Down
1 change: 1 addition & 0 deletions cdhweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"wagtail.contrib.modeladmin",
"wagtail",
"wagtailmenus",
"wagtailautocomplete",
"modelcluster",
"taggit",
"adminsortable2",
Expand Down
3 changes: 3 additions & 0 deletions cdhweb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from wagtail.contrib.sitemaps import views as sitemap_views
from wagtail.documents import urls as wagtaildocs_urls
from wagtail.models import Page
from wagtailautocomplete.urls.admin import urlpatterns as autocomplete_admin_urls

from cdhweb.blog.sitemaps import BlogListSitemap
from cdhweb.context_processors import favicon_path
Expand All @@ -32,6 +33,8 @@


urlpatterns = [
# wagtail autocompletes; must come before admin urls
re_path(r"^cms/autocomplete/", include(autocomplete_admin_urls)),
# admin site
path("admin/", admin.site.urls),
# special paths
Expand Down
3 changes: 2 additions & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ django-fullurl
django-apptemplates
wagtailmenus>=3.1
opencv-python
bleach
bleach
wagtail-autocomplete

0 comments on commit 6f40cb3

Please sign in to comment.