\n{trail.brief(r)}\n' for r in routes)
- listing = home.results(groups=[(None, routes, regions.route_guides)], routes_list=True, top=2,
+ listing = home.listing(groups=[(None, routes, regions.route_guides)], routes_list=True, top=2,
by=lambda r: with_html(g, r, by_name))
route_title = "About the route" if n == 1 else "About each route"
bio = about_html(g)
diff --git a/web/olt/home.py b/web/olt/home.py
index 6994820..37235f4 100644
--- a/web/olt/home.py
+++ b/web/olt/home.py
@@ -239,17 +239,13 @@ 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()), 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
+# One bar and one set of panels, on the home page and on every other page that shows a set of
+# trails (listing()), 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
# web/tests/test_filter_counts.py runs under node against counts made here from the records).
-FILTER_MIN = 10
-
-
def _length_options(steps, selected_any_last, unit="mi"):
opts = [f'' for n in steps]
if selected_any_last:
@@ -443,15 +439,13 @@ def finder_form(records, c=None, steps=None, where="all", bare_if_empty=False):
"""
-def listing(recs=None, *, where="all", groups=None, always=False, **kw):
- """The rows of a page that shows a set of trails, with the filter bar over them when the set
- has at least FILTER_MIN trails (else results() alone); with always, whatever its size (the
- bar then holds only the filters that have something to offer). where: the Where filter's
- scope (finder_form). The other arguments are results()'s."""
+def listing(recs=None, *, where="all", groups=None, **kw):
+ """The rows of a page that shows a set of trails, with the filter bar over them whatever the size
+ of the set (the bar holds only the filters that have something to offer, and the search box
+ alone where nothing can narrow the set). where: the Where filter's scope (finder_form). The
+ other arguments are results()'s."""
trails = [r for g in groups for r in g[1]] if groups is not None else list(recs)
- if len(trails) < FILTER_MIN and not always:
- return results(recs, groups=groups, **kw)
- return Markup(f"""
- {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)),
+ {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)),
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/golden/state-pages.json b/web/tests/golden/state-pages.json
index 1863e2c..6d57e57 100644
--- a/web/tests/golden/state-pages.json
+++ b/web/tests/golden/state-pages.json
@@ -1,14 +1,14 @@
{
"/regions/": "e70a9608ef0ee6a97d0591ad582abff1b165371dee5111e3277df06a53a554e1",
- "/regions/atlantic-canada/": "6af5c4a79cac82eb0a4342297fd4f6755890e98597a98f219087c56432f06243",
- "/regions/ca-on/": "12b5726d800090233f082a572cf1472f152552cef8fa5019f49b83e32e337eef",
- "/regions/central-canada/": "fa6f8bbe466b5978f1edda22371b6aab8546efa567eee0d0405c717e278b8a3e",
- "/regions/mountain-west/": "c079eb93a55c2279f24083983230057940eb032cb034057c822c52230ce22e05",
- "/regions/north/": "fdfd201ae1e42b8fd17dd055815d4b06392a8ddb6ac3e72a06f15ec2b333fb56",
- "/regions/us-co/": "45cb1b92fd22ffc35f82a26fe2c71b66836b0624bf0e195f9c4926dfab6a8900",
- "/regions/us-co/loops/": "8883c9aac63f100196f9e853d6738a42b8199f1250c10ec34d1d0cfe8c998e7d",
- "/regions/us-co/with-gpx/": "abc3f7e44cbcbf8d6cce3b5d5065e6e7c085ec5a4033842af8909077f87e1e18",
+ "/regions/atlantic-canada/": "5146b4b9d1940a268cfd2345f1eee2263fd6c7e2dfd28adfdffc3fff0e698c93",
+ "/regions/ca-on/": "d4e543c6f163ba188a34444b42c494a3dbbd26c02f2b141339bbc230cd91f84e",
+ "/regions/central-canada/": "d7478ad682d715705770d35cc902c80c40d27719e7f9f5a1d99ec702d3f7a43e",
+ "/regions/mountain-west/": "6151f5a28d366fb48aab7027f08cea6da425201d0e7327780a01dd77cedc7bc7",
+ "/regions/north/": "85ba3ea850c2df690e311cf09257f2548ed888c07c319a01fd30d5e19cdf1fd4",
+ "/regions/us-co/": "97daaf3511578896b222570cba630da2d8ca0571504ce43b3685dbe532e40f56",
+ "/regions/us-co/loops/": "03896834b5369655f7b5f26634b6d23c834b17f1a25b0ec328d44934e20e2dfa",
+ "/regions/us-co/with-gpx/": "d82eace3d70eb9b1ef1346f5a3470199bd6a00e6e104fe661bfeb80199af96b8",
"/regions/us-hi/": "1e5681ffbd50e382db7d69528fde602069006bf0cddad494d817369224bd96ad",
- "/regions/us-ut/": "065bcc01e14eb588dc1b118c466f44474fca0172c30037fb193d83a044624100",
- "/regions/western-canada/": "91b40d35dd3d1a093d38d01bbfcf1ef536221a69631fc58e46732da81d0582c3"
+ "/regions/us-ut/": "906db4153def35fa5418d0b86dba908fd27396bbc2098978ee169516e1b39785",
+ "/regions/western-canada/": "1b102ed9d47283869fdf8c8d54229d245f2113fd53c7e8ec2ecc118fd4da3b64"
}
diff --git a/web/tests/test_filter_bar.py b/web/tests/test_filter_bar.py
index 84e9fb1..1911f9a 100644
--- a/web/tests/test_filter_bar.py
+++ b/web/tests/test_filter_bar.py
@@ -1,7 +1,7 @@
"""The filter bar on every page that shows a set of trails, and the numbers beside its choices.
The bar (olt/home.py listing(), finder_form()) is the home page's, on each list, place and the Routes
-page whose set has at least home.FILTER_MIN trails, built from that page's own trails. app.js counts
+page, whatever the number of trails, built from that page's own trails. app.js counts
the choices again from the rows on the page every time anything changes (FacetCount, between the
facet-counts markers); this file runs that counting under node, on the rows the home page writes,
and checks it against counts made here straight from the records. Pages are rendered one at a time;
@@ -68,22 +68,36 @@ class WhichPagesHaveTheBarTest(unittest.TestCase):
lst = browse.by_key(key)
return regions.list_page(lst, self.shown[key], len(self.records), SITE, records=self.records)[2]
- def test_a_list_page_a_place_page_a_part_of_the_country_and_routes_have_it(self):
- self.assertGreaterEqual(len(self.shown["loops"]), home.FILTER_MIN)
- self.assertTrue(form_of(self.list_body("loops")))
+ def test_a_list_page_a_place_page_a_part_of_the_country_and_routes_have_it(self):
+ self.assertTrue(form_of(self.list_body("loops")))
by_slug, _ = regions.collect_regions(self.records)
- self.assertGreaterEqual(len(by_slug["ca-on"]["records"]), home.FILTER_MIN)
self.assertTrue(form_of(regions.region_page("ca-on", self.records, SITE)[2]))
self.assertTrue(form_of(regions.group_page("central-canada", self.records, SITE)[2]))
self.assertTrue(form_of(regions.routes_page(self.records, SITE)[2]))
- def test_a_set_under_the_threshold_has_the_plain_rows(self):
- small = [k for k, recs in self.shown.items() if len(recs) < home.FILTER_MIN and k != "routes"]
- self.assertTrue(small)
+ def test_every_state_province_and_list_page_has_the_bar_however_few_trails(self):
+ by_slug, _ = regions.collect_regions(self.records)
+ small = [k for k, v in by_slug.items() if len(v["records"]) < 10]
+ self.assertGreater(len(small), 40)
for key in small:
- body = self.list_body(key)
- self.assertFalse(form_of(body), key)
- self.assertNotIn("data-finder", str(body), key)
+ body = regions.region_page(key, self.records, SITE)[2]
+ self.assertIn('id="finder-form"', str(body), key)
+ self.assertIn("data-finder", str(body), key)
+ small_lists = [k for k, recs in self.shown.items() if len(recs) < 10 and k != "routes"]
+ self.assertTrue(small_lists)
+ for key in small_lists:
+ self.assertTrue(form_of(self.list_body(key)), key)
+
+ def test_a_two_trail_page_offers_only_filters_that_narrow_it(self):
+ by_slug, _ = regions.collect_regions(self.records)
+ two = [k for k, v in by_slug.items() if len(v["records"]) == 2]
+ self.assertTrue(two)
+ for key in two:
+ form = form_of(regions.region_page(key, self.records, SITE)[2])
+ self.assertIn('name="q"', form, key)
+ for sel in re.findall(r"", form, re.S):
+ self.assertNotIn("", sel)
+ self.assertGreater(len(re.findall(r"