Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
0.1.4.dev
~~~~~~~~~
- Popups allow unicode. @apatil
- Support for https protocol. @apatil
- Custom popup width. @ocefpaf
- Support multiPolyLine. @scari
- Added max and min zoom keywords. @Paradoxeuh


Bug Fixes

- Remove margins from leaflet-tiles (Fixes #64). @lennart0901
Expand Down
19 changes: 17 additions & 2 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from folium import utilities
from folium.six import text_type, binary_type, iteritems

import sys


ENV = Environment(loader=PackageLoader('folium', 'templates'))

Expand Down Expand Up @@ -616,10 +618,21 @@ def _popup_render(self, popup=None, mk_name=None, count=None,
if not popup_on:
return 'var no_pop = null;'
else:
if isinstance(popup, str):
if sys.version_info >= (3,0):
utype, stype = str, bytes
else:
utype, stype = unicode, str

if isinstance(popup, (utype, stype)):
popup_temp = self.env.get_template('simple_popup.js')
Copy link
Member

Choose a reason for hiding this comment

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

Use

isinstance(popup, (str, unicode))

instead.

if isinstance(popup, utype):
popup_txt = popup.encode('ascii', 'xmlcharrefreplace')
Copy link
Member

Choose a reason for hiding this comment

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

Loved it!

else:
popup_txt = popup
if sys.version_info >= (3,0):
popup_txt = popup_txt.decode()
return popup_temp.render({'pop_name': mk_name + str(count),
'pop_txt': json.dumps(popup),
'pop_txt': json.dumps(str(popup_txt)),
Copy link
Member

Choose a reason for hiding this comment

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

@apatil I am on the fence here. I am not sure if the call to str is necessary, but it does not hurt... What is your argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was getting type errors in python3 without it. The encode('ascii', ...) produces a bytes object, which json.dumps doesn't like.

Copy link
Member

Choose a reason for hiding this comment

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

str it is then.

'width': width})
elif isinstance(popup, tuple):
#Update template with JS libs
Expand Down Expand Up @@ -653,6 +666,8 @@ def _popup_render(self, popup=None, mk_name=None, count=None,
'max_width': max_width,
'json_out': json_out,
'vega_id': vega_id})
else:
raise TypeError("Unrecognized popup type: {!r}".format(popup))

@iter_obj('geojson')
def geo_json(self, geo_path=None, geo_str=None, data_out='data.json',
Expand Down