From d90fa49df51a4de2832addf830aa8cd4b39b63c8 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Fri, 20 Nov 2026 12:29:05 -0700 Subject: [PATCH] Show the search box and filters on every park, range and wilderness page, however few trails it has The bar was written only for a set of ten trails or more (home.FILTER_MIN, added with the list and place filters on 2026-11-17), which left the Wind River Range (7 trails), Yosemite (9) and the Ansel Adams Wilderness (5) with neither a search box nor Filters. Place pages now always get it, and a set that nothing can narrow gets the search box alone, with no Filters button and no empty panel. State and province pages keep the ten-trail threshold for now. Co-Authored-By: Claude Sonnet 5.5 --- web/olt/home.py | 30 ++++++++++++++++++++++-------- web/olt/placepages.py | 2 +- web/olt/regions.py | 3 ++- web/tests/test_place_page.py | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/web/olt/home.py b/web/olt/home.py index 508acae..bedb0d0 100644 --- a/web/olt/home.py +++ b/web/olt/home.py @@ -234,7 +234,8 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals # The filters ------------------------------------------------------------------ # One bar and one set of panels, on the home page and on every other page that shows a set of at -# least FILTER_MIN trails (listing()). Everything is built from the page's own trails: a facet that +# least FILTER_MIN trails (listing()), and on every park, range and wilderness page whatever its +# size (the owner's rule: every set of trails gets the bar). Everything is built from the page's own trails: a facet that # cannot narrow them is left out, and an option none of them has is not written. The numbers written # here are for the whole set; app.js counts again from the rows on the page every time anything # changes, and hides an option that would show nothing (its counting is facetCounts(), which @@ -315,11 +316,13 @@ def _missing(records, key): f'{esc(facets.missing_text(without, key))} They are left out while this filter is on.

') -def finder_form(records, c=None, steps=None, where="all"): +def finder_form(records, c=None, steps=None, where="all", bare_if_empty=False): """The bar (search, Filters, Clear) and the panels: the first-rank filters, then Walking, Shape and GPX behind "More". records: the page's own trails. where: the Where filter's scope ("all", "g:" on a group's page, "" for none: a state's page). A facet is written only when it can - narrow these trails; each field carries data-facet, for app.js to hide it when it no longer can.""" + narrow these trails; each field carries data-facet, for app.js to hide it when it no longer can. + bare_if_empty: a set that nothing can narrow gets the search box alone, with no Filters + button and no empty panel.""" c = c or counts(records) steps = steps or length_steps(records) km_steps = length_steps(records, "km") @@ -398,6 +401,16 @@ def finder_form(records, c=None, steps=None, where="all"): {"".join(more)} """ if more else "" + if bare_if_empty and not first and not more: + return """""" return f"""
- {home.browse_view(home.listing(recs, top=2, where=kind.where, wholly=wholly), home.overview_map(recs, f"Map of the trails {phrase}", place=kind.box(info)), + {home.browse_view(home.listing(recs, top=2, where=kind.where, wholly=wholly, always=kind.always_filters), home.overview_map(recs, f"Map of the trails {phrase}", place=kind.box(info)), about=f"{summary.facts(recs, records, place=place)}{summary.details(recs)}", about_title=f"About the trails {phrase}")} {nav}{place_links} diff --git a/web/tests/test_place_page.py b/web/tests/test_place_page.py index 1543d9a..b1f402b 100644 --- a/web/tests/test_place_page.py +++ b/web/tests/test_place_page.py @@ -150,6 +150,38 @@ class LabelPrepositionAndTitleTest(unittest.TestCase): "Long Hikes in the Vancouver Island Ranges: 18 Trails") +class SmallPlaceHasTheBarTest(unittest.TestCase): + """The owner's rule: every set of trails gets the search box and the filters, at any size.""" + + def test_a_place_with_three_trails_has_the_search_box_and_the_finder(self): + built = built_with([entry_of("range", "wind-river-range", "Wind River Range", ["WY"])], n=3) + body = str(built["/ranges/wind-river-range/"].body) + self.assertIn('class="finder__bar"', body) + self.assertIn('id="q"', body) + self.assertIn("data-finder", body) + self.assertLess(body.index('class="finder__bar"'), body.index('
  • ")] + self.assertNotIn("data-facet", form) + self.assertNotIn("filters__toggle", form) + self.assertNotIn("Nothing here narrows", form) + + def test_a_place_whose_trails_differ_offers_those_filters_with_a_button(self): + entries = [entry_of("range", "wind-river-range", "Wind River Range", ["WY", "CO"])] + records = [rec(400 + i, f"Differ {i}", [("range", "wind-river-range")], km=50 + i * 120, + regs=("WY",) if i % 2 else ("CO",)) for i in range(1, 4)] + with tempfile.TemporaryDirectory() as d: + write_registry(d, entries) + body = str(placepages.build(records, S, d)[0].body) + form = body[body.index('
    ")] + self.assertIn('data-facet="where"', form) + self.assertIn("filters__toggle", form) + + class PlacePageTest(unittest.TestCase): @classmethod def setUpClass(cls):