Skip to content

Search Improvements#287

Merged
paigewilliams merged 11 commits into
mainfrom
include-description-search
May 14, 2026
Merged

Search Improvements#287
paigewilliams merged 11 commits into
mainfrom
include-description-search

Conversation

@paigewilliams
Copy link
Copy Markdown
Collaborator

@paigewilliams paigewilliams commented May 13, 2026

Asana tasks:

Description

PR includes the following changes:

  • adds a keywords field to Activities, Bibliographic Sources, Media, Places and Resources
  • adds a "guide" section to the above records pages with a two column list of the searchable fields
  • fixes a bug where the verbose name of preparedfor was not super human readable withprepared_for, changed to prepared for.

Screenshots

Screenshot 2026-05-13 at 1 57 51 PM Screenshot 2026-05-13 at 2 03 28 PM Screenshot 2026-05-13 at 2 04 47 PM

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds full-text keyword search support to Activities, Bibliographic Sources, Media, Places, and Resources by introducing a new keywords TextField (via a KeywordSearchable abstract model), exposes a "Guide" section in each admin listing the human-readable searchable fields, and fixes the verbose name of Citations.preparedfor from prepared_for to prepared for.

Changes:

  • New KeywordSearchable mixin + migration adds a keywords field to five record models, with keyword_search refactored to read field/weight config from class-level constants (FIELDS, FK_FIELDS, WEIGHT_LOOKUP, SORT_FIELD) and a new human_readable_list_of_searchable_fields classmethod.
  • Each affected admin gets a searchable_fields_display readonly field and a "Guide" fieldset rendering the searchable field list as a two-column HTML list.
  • Fixture, tests, and migration updates covering the new keyword field/searches and the preparedfor verbose name change.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
TEKDB/TEKDB/models.py Adds KeywordSearchable abstract model, list_queryable_fields helper, and refactors five keyword_search methods to use class-level constants; updates Citations.preparedfor verbose name.
TEKDB/TEKDB/admin.py Adds duplicated searchable_fields_display method, keywords field, and "Guide" fieldset to five admin classes; imports mark_safe.
TEKDB/TEKDB/migrations/0028_alter_citations_preparedfor.py Migration for preparedfor verbose name change.
TEKDB/TEKDB/migrations/0029_..._keywords_and_more.py Migration adding keywords TextField to the five models.
TEKDB/TEKDB/fixtures/all_dummy_data.json Adds keywords (with foobarbaz sentinel) to test fixture records.
TEKDB/TEKDB/tests/test_models.py Adds test_matches_keywords_field and test_human_readable_list_of_searchable_fields tests for each model.
Comments suppressed due to low confidence (1)

TEKDB/TEKDB/admin.py:555

  • Building HTML by joining f-string fragments and wrapping the result in mark_safe bypasses escaping. Even though verbose_name values are currently developer-controlled, this is a fragile pattern: if any future field's verbose_name contains characters like <, >, or &, they will be rendered as raw HTML. Using format_html_join("", "<li>{}</li>", ((f,) for f in fields)) (and dropping mark_safe) would auto-escape each field name while still producing safe markup. The same issue exists in the identical searchable_fields_display methods in MediaAdmin, PlacesAdmin, ResourcesAdmin, and ResourcesActivityEventsAdmin.
    def searchable_fields_display(self, instance):
        fields = instance.__class__.human_readable_list_of_searchable_fields()
        items = mark_safe("".join(f"<li>{f}</li>" for f in fields))
        return format_html(
            "<ul style='margin:0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 20px;'>{}</ul>",
            items,
        )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TEKDB/TEKDB/admin.py
Comment thread TEKDB/TEKDB/admin.py Outdated
Comment thread TEKDB/TEKDB/models.py Outdated
Comment thread TEKDB/TEKDB/models.py
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Your changes improve the readability, organization of this file, and simplify search related variables and functions.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

thanks!

@paigewilliams paigewilliams merged commit a3b25f0 into main May 14, 2026
2 checks passed
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.

3 participants