Skip to content

Open Infrastructure Map, a view of infrastructure data in OpenStreetMap

Display improvements

Russ Garrettfa41f13dfe3d
diff --git a/main.py b/main.py
index fa59849..e71c6ce 100644
--- a/main.py
+++ b/main.py
@@ -4,7 +4,7 @@ from starlette.templating import Jinja2Templates
from starlette.routing import Mount, Route
from starlette.staticfiles import StaticFiles
-from template_functions import format_power, osm_link
+from template_functions import format_power, osm_link, country_name
from config import database, config
from util import cache_for, country_required
from sitemap import sitemap
@@ -15,6 +15,7 @@ DEBUG = config("DEBUG", cast=bool, default=False)
templates = Jinja2Templates(directory="templates")
templates.env.filters["power"] = format_power
+templates.env.filters["country_name"] = country_name
templates.env.globals["osm_link"] = osm_link
diff --git a/template_functions.py b/template_functions.py
index f127537..b5758d0 100644
--- a/template_functions.py
+++ b/template_functions.py
@@ -22,3 +22,16 @@ def osm_link(osm_id, geom_type):
else:
url += "way"
return url + "/" + str(osm_id)
+
+
+THE_COUNTRY_NAMES = {"United States", "United Kingdom", "Netherlands", "Bahamas",
+ "Canary Islands", "British Virgin Islands", "Azores", "Cayman Islands"}
+
+
+def country_name(name, cap=False):
+ if name in THE_COUNTRY_NAMES:
+ if cap:
+ return "The " + name
+ else:
+ return "the " + name
+ return name
diff --git a/templates/country.html b/templates/country.html
index dcecd74..eb7821a 100644
--- a/templates/country.html
+++ b/templates/country.html
@@ -2,13 +2,13 @@
{% set breadcrumbs = [('Stats', url_for('stats')), (country, None)] %}
{% block title %}{{country}}{% endblock %}
{% block description -%}
-Statistics on the electricity network in {{country}} from OpenStreetMap.
+Statistics on the electricity network in {{country|country_name}} from OpenStreetMap.
{%- endblock %}
{% block content -%}
- <p><strong>{{country}}</strong> has {{plant_stats.count}} power plants totalling {{plant_stats.output|power}} mapped on OpenStreetMap.</p>
+ <p><strong>{{country|country_name(true)}}</strong> has {{plant_stats.count}} power plants totalling {{plant_stats.output|power}} mapped on OpenStreetMap.</p>
<table>
- <caption>Power plants in {{country}} by source</caption>
+ <caption>Power plants in {{country|country_name}} by source</caption>
<thead>
<tr>
<th>Source</th>
diff --git a/templates/plants_country.html b/templates/plants_country.html
index 89a5c0e..494424f 100644
--- a/templates/plants_country.html
+++ b/templates/plants_country.html
@@ -7,7 +7,7 @@
{% endif %}
{% block title %}{{country}}{% if pretty_source %} {{pretty_source|title}}{% endif %} Power Plants{% endblock %}
{% block description -%}
- List of{% if pretty_source%} {{pretty_source}}{% endif %} power plants in {{country}} from OpenStreetMap
+ List of{% if pretty_source%} {{pretty_source}}{% endif %} power plants in {{country|country_name}} from OpenStreetMap
{%- endblock %}
{% block content -%}
@@ -17,10 +17,10 @@
{% endif %}
{% if plants|length == 0 %}
- <p>There are currently no power plants mapped in {{country}} on OpenStreetMap.</p>
+ <p>There are currently no power plants mapped in {{country|country_name}} on OpenStreetMap.</p>
{% else %}
<table class="plants-table">
- <caption>All {{plants|length}} {% if pretty_source %}{{pretty_source}} {% endif %}power plants in {{country}}</caption>
+ <caption>All {{plants|length}} {% if pretty_source %}{{pretty_source}} {% endif %}power plants in {{country|country_name}}</caption>
<thead>
<tr>
<th>Name</th>
@@ -52,7 +52,7 @@
</tbody>
</table>
{% if pretty_source %}
- <p><a href="{{url_for('plants_country', country=country)}}">View all power plants in {{country}}</a>.</p>
+ <p><a href="{{url_for('plants_country', country=country)}}">View all power plants in {{country|country_name}}</a>.</p>
{% endif %}
{% endif %}
{% endblock %}