{p}" if i % 2 else p for i, p in enumerate(parts)))
def absent_reason_short(rec):
"""line_absent_reason without the opening "No line is included." (the status already says so)."""
reason = rec.get("source", {}).get("line_absent_reason", "")
return re.sub(r"^No line is included\.\s*", "", reason) or reason
def regions_html(rec, linked=False):
"""Region codes with their names; optionally each linked to the filtered list."""
parts = []
for code in rec.get("regions", []):
name = words.region_name(code)
if code == words.ALL_CANADA:
text = Markup(esc(name))
href = "/regions/#canada-wide"
else:
text = Markup(f'{esc(code)}')
href = f"/regions/{words.region_key(code, rec['country']).lower()}/"
if linked:
text = Markup(f'{text}')
parts.append(text)
return Markup(" ".join(parts))
def tags(rec, with_policy=True):
"""Kind, tier and listing tags, and (with_policy) the line policy of a route."""
out = []
if is_route(rec):
out.append('Person-defined route')
elif rec.get("tier") == "national":
out.append('National Scenic Trail')
else:
out.append('Designated trail')
tier = rec.get("tier")
if tier in ("short", "deferred", "candidate"):
out.append(f'{esc(words.label(words.TIERS, tier))}')
if str(rec.get("wave")) == "held":
out.append('Held')
if is_route(rec) and with_policy:
out.append(policy_chip(policy(rec)))
return Markup("".join(out))
def policy_chip(value):
lab, short = words.label(words.POLICIES, value), words.meaning(words.POLICIES, value)
return Markup(f''
f'Line policy: {esc(lab)}')
def logo_img(rec, alt, eager=False):
"""The logo