Skip to content

Commit

Permalink
Merge pull request #3 from open-oni/feature/aggregate-cities
Browse files Browse the repository at this point in the history
Feature/aggregate cities
  • Loading branch information
jduss4 authored Jul 24, 2017
2 parents 67adbcf + 88125de commit 859dda5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ generate valid JavaScript:
# Run this from the open-oni directory
docker-compose exec web manage map_places geonames-user OR

You can even automate it further by grepping only the first line of JS:
You can even automate it further by grepping only the first line of JS (note that this will hide errors from you!):

# Run this from the open-oni directory
docker-compose exec web manage map_places geonames-user OR | \
grep -A999999999 "var cities = " >themes/oregon/static/js/cities_list.js

**NOTE**: When using the map_places command, bear in mind that if you somehow have two
cities with the same name, one will end up clobbering the other!

To hitch this plugin to your project wagon, you will need to add a few lines in some files.

`onisite.plugins.map` needs to go in your `INSTALLED_APPS` list:
Expand Down
11 changes: 6 additions & 5 deletions management/commands/map_places.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ def handle(self, *args, **options):

# Record the lat/lng in our output data
if lat is not None and lng is not None:
output_data[place] = (lat,lng)
output_data[place.city] = (lat,lng)

_logger.info("finished looking up places in GeoNames")

cities_json = []
for place in output_data:
titles = models.Title.objects.filter(places__city__iexact=place.city).all()
for city in output_data:
latlng = output_data[city]
titles = models.Title.objects.filter(places__city__iexact=city).all()
if len(titles) == 0:
continue

city_json = {
"name": place.city,
"latlong": [place.latitude, place.longitude],
"name": city,
"latlong": [latlng[0], latlng[1]],
"papers": {}
}
for title in titles:
Expand Down

0 comments on commit 859dda5

Please sign in to comment.