Skip to content
This repository was archived by the owner on Feb 1, 2020. It is now read-only.

Allow billy to handle newly-defined Imago boundary sets #257

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion billy/core/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
MONGO_USER_DATABASE = 'billy_userdata'

BOUNDARY_SERVICE_URL = 'http://localhost:8001/1.0/'
BOUNDARY_SERVICE_SETS = 'sldl-14,sldu-14,nh-12'
BOUNDARY_SERVICE_SETS = r'sld[lu]-[a-z]{2}-[0-9]{2}'
ENABLE_ELASTICSEARCH = False
ENABLE_ELASTICSEARCH_PUSH = False
ELASTICSEARCH_HOST = '127.0.0.1:9200'
Expand Down
17 changes: 6 additions & 11 deletions billy/web/api/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from piston.handler import BaseHandler, HandlerMetaClass

AT_LARGE = ['At-Large', 'Chairman']
ACTIVE_BOUNDARY_SETS = settings.BOUNDARY_SERVICE_SETS.split(",")
ACTIVE_BOUNDARY_SETS_RE = settings.BOUNDARY_SERVICE_SETS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we re.compile this?



_lower_fields = (settings.LEVEL_FIELD, 'chamber')
Expand Down Expand Up @@ -402,17 +402,12 @@ def read(self, request):

for dist in resp['results']:
ocdid = dist['id']
# ocd-division/country:us/state:oh/cd:11
_, localpart = ocdid.rsplit("/", 1)
set_, series = localpart.split(":", 1)
if set_ not in ['sldl', 'sldu', 'ward']:
# Place, CD, County, ...
continue

districts = db.districts.find({'division_id': ocdid})
count = districts.count()

if count == 1:
if count == 0:
continue
elif count == 1:
district = districts[0]
boundary_id = district['division_id']

Expand All @@ -425,7 +420,7 @@ def read(self, request):
district['chamber'])] = boundary_id

jurisdiction = district['abbr']
elif count != 0:
else:
raise ValueError('multiple districts with boundary_id: %s' %
boundary_id)

Expand Down Expand Up @@ -490,7 +485,7 @@ def _ocd_id_to_shape_url(self, ocd_id):
)
data = json.load(urllib2.urlopen(url))
geometries = filter(
lambda x: x['boundary_set']['name'] in ACTIVE_BOUNDARY_SETS,
lambda x: re.search(ACTIVE_BOUNDARY_SETS_RE, x['boundary_set']['name']),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should perhaps do a re.match + handling for sldl-nh-12-floterial or something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The settings.py's RE already accounts for extra text afterwards, so that's all good, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh, never mind, apparently not in the version I pushed :)

data['geometries']
)
if len(geometries) == 1:
Expand Down