$def with (param, facet_counts=None, async_load=True, path=None, query={}) $code: start_facet_count = 5 facet_inc = 10 def add_facet_url(k, v): if k != 'has_fulltext': return changequery(query=dict(query), page=None, _path=path, **{k:param.get(k, []) + [v]}) else: return changequery(query=dict(query), page=None, _path=path, **{k:v}) def add_track(key: str) -> str: """ KeyError will be raised if key is not in the following dict. """ facets = { "has_fulltext": "Ebook", "author_key": "Author", "subject_facet": "Subjects", "person_facet": "People", "place_facet": "Places", "time_facet": "Times", "first_publish_year": "FirstPublished", "publisher_facet": "Publisher", "language": "Language", } return "SearchFacet|" + facets[key] $def facet(header, label, counts):
$ magic_wand_markup = '' $if header == 'author_key' and len(counts) > 1 and ctx.user and ("merge-authors" in ctx.features or ctx.user.is_admin()): $ keys = '&'.join('key=%s' % k for k, display, count in counts) $ magic_wand_markup = ' %s' % (keys, _('Merge duplicate authors from this search'), _("Merge duplicates"))

$(label)$:(magic_wand_markup)

$ num = 0 $for k, display, count in counts: $ num = num + 1 $ hide_entry = num > start_facet_count $ facet_url = None if async_load else add_facet_url(header, k) $ num_found = 0 if async_load else commify(count) $:facet_entry(display, num_found, facet_url, hide_entry=hide_entry) $if len(counts) > start_facet_count:
$_("more") $_("less")
$def facet_entry(display, count, facet_url, hide_entry=False): $ facet_classes = 'facetEntry' $if hide_entry: $ facet_classes += ' ui-helper-hidden'
$if async_load: $_('Loading...') $else: $ link_title = _('Filter results for %(facet)s', facet=display) $if header == 'has_fulltext': $ link_title = _('Filter results for ebook availability') $if display == 'yes': $ display = _('yes') $else: $ display = _('no') $display $commify(count)

$_("Zoom In")

$:_('Focus your results using these filters')
$for header, label in get_facet_map(): $if header=='has_fulltext' and 'has_fulltext' in param: $continue $if header=='public_scan_b': $continue $ counts = [i for i in facet_counts[header] if i[0] not in param.get(header, [])] if not async_load else [(None, None, None)] $if not counts and not async_load: $continue $:facet(header, label, counts)