Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create management command for importing shapefiles #248

Closed
jeancochrane opened this issue Jun 24, 2019 · 2 comments
Closed

Create management command for importing shapefiles #248

jeancochrane opened this issue Jun 24, 2019 · 2 comments

Comments

@jeancochrane
Copy link
Contributor

Pull out logic from the soon-to-be deprecated import_data command into its own management command, import_geographies. Specifically, adapt this method, making sure it fits with the new models introduced in #240:

def populate_council_district_shapes(self):
self.log_message('Populating boundaries ...')
# grab boundary listing
for boundary in settings.BOUNDARY_SET:
bndry_set_url = bndry_base_url + '/boundaries/' + boundary
r = self._get_response(bndry_set_url + '/?limit=0')
page_json = json.loads(r.text)
# loop through boundary listing
for bndry_json in page_json['objects']:
# grab boundary shape
shape_url = bndry_base_url + bndry_json['url'] + 'shape'
r = self._get_response(shape_url, raise_error=False)
# update the right post(s) with the shape
if r:
if 'ocd-division' in bndry_json['external_id']:
division_ocd_id = bndry_json['external_id']
Post.objects.filter(
division_ocd_id=division_ocd_id).update(shape=r.text)
else:
# Represent API doesn't use OCD id as external_id,
# so we must work around that
division_ocd_id_fragment = ':' + bndry_json['external_id']
Post.objects.filter(
division_ocd_id__endswith=division_ocd_id_fragment).update(shape=r.text)
print('.', end='')
sys.stdout.flush()

@fgregg
Copy link
Member

fgregg commented Jun 24, 2019

I'd like to see if we can lean into the collect static approach. If that's not desirable for some reason, please let me know.

https://docs.djangoproject.com/en/2.2/ref/contrib/staticfiles/

@jeancochrane
Copy link
Contributor Author

Closed in #249.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants