Search Improvements#287
Conversation
There was a problem hiding this comment.
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
KeywordSearchablemixin + migration adds akeywordsfield to five record models, withkeyword_searchrefactored to read field/weight config from class-level constants (FIELDS,FK_FIELDS,WEIGHT_LOOKUP,SORT_FIELD) and a newhuman_readable_list_of_searchable_fieldsclassmethod. - Each affected admin gets a
searchable_fields_displayreadonly 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
preparedforverbose 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_safebypasses escaping. Even thoughverbose_namevalues 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. Usingformat_html_join("", "<li>{}</li>", ((f,) for f in fields))(and droppingmark_safe) would auto-escape each field name while still producing safe markup. The same issue exists in the identicalsearchable_fields_displaymethods inMediaAdmin,PlacesAdmin,ResourcesAdmin, andResourcesActivityEventsAdmin.
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.
There was a problem hiding this comment.
Your changes improve the readability, organization of this file, and simplify search related variables and functions.
Asana tasks:
Description
PR includes the following changes:
keywordsfield to Activities, Bibliographic Sources, Media, Places and Resourcesprepared_for, changed toprepared for.Screenshots