Skip to content

Commit f09aee3

Browse files
committed
account for superflous whitespace in codes
1 parent ccb22ab commit f09aee3

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

findthatpostcode/commands/codes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ def process_date(value, date_format="%d/%m/%Y"):
4343
return datetime.datetime.strptime(value, date_format)
4444

4545

46+
def process_str(value):
47+
if value in ["", "n/a"]:
48+
return None
49+
if not isinstance(value, str):
50+
return value
51+
return value.strip()
52+
53+
4654
def process_int(value):
4755
if value in ["", "n/a"]:
4856
return None
@@ -202,7 +210,7 @@ def import_chd(url=None, es_index=AREA_INDEX, encoding=DEFAULT_ENCODING):
202210
"date_start": process_date(area["OPER_DATE"][0:10], "%d/%m/%Y"),
203211
"date_end": process_date(area["TERM_DATE"][0:10], "%d/%m/%Y"),
204212
"parent": area["PARENTCD"] if area["PARENTCD"] else None,
205-
"entity": area["ENTITYCD"],
213+
"entity": process_str(area["ENTITYCD"]),
206214
"owner": area["OWNER"],
207215
"active": area["STATUS"] == "live",
208216
"areaehect": process_float(area["AREAEHECT"]),
@@ -213,7 +221,7 @@ def import_chd(url=None, es_index=AREA_INDEX, encoding=DEFAULT_ENCODING):
213221
"predecessor": [],
214222
"successor": [],
215223
"equivalents": {},
216-
"type": ENTITIES.get(area["ENTITYCD"]),
224+
"type": ENTITIES.get(process_str(area["ENTITYCD"])),
217225
}
218226
)
219227

findthatpostcode/controllers/areas.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Areatype(Controller):
1818
areatypes = AREA_TYPES
1919

2020
def __init__(self, id, data=None):
21+
id = id.strip()
2122
if not data:
2223
data = self.areatypes.get(id)
2324
super().__init__(id, data)
@@ -51,6 +52,7 @@ def get_name(self, country=None):
5152

5253
@classmethod
5354
def get_from_es(cls, id, es, es_config=None, full=False):
55+
id = id.strip()
5456
if cls.areatypes.get(id):
5557
return cls(id)
5658
return super().get_from_es(id, es, es_config=es_config)

findthatpostcode/templates/area.html.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{% set subtitle = "<span class='bg-red white pa2 mt2 dib'>INACTIVE</span> {}".format(result.relationships.areatype.get_name(result.id)) %}
88
{% endif %}
99
{% if result.attributes.ctry_name and result.attributes.ctry_name != result.attributes.name %}
10-
{% set subtitle = subtitle + " in " + result.attributes.ctry_name %}
10+
{% set subtitle = (subtitle or "Area") + " in " + result.attributes.ctry_name %}
1111
{% endif %}
1212
{% set example_postcodes = result.relationships.example_postcodes %}
1313
{% extends "base.html.j2" %}
@@ -19,6 +19,7 @@
1919
{% block content %}
2020
<div class="cf">
2121
<div class="fl w-third-l w-100 pr4 f5">
22+
{{ result.relationships.areatype }}
2223
{% if result.has_boundary %}
2324
<div class="mb3">
2425
<a href="{{ url_for('areas.get_area_boundary', areacodes=result.id) }}" class="link blue underline-hover">Boundary

0 commit comments

Comments
 (0)