Skip to content

Commit

Permalink
Merge fa559d4 into 986682d
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaël UTARD committed Dec 18, 2018
2 parents 986682d + fa559d4 commit 375d3f0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CHANGELOG

**Bug fixes**

-
- Replace \u2028 and \u2029 by \n in synced (geo)json files (fix Geotrek-mobile crash)


2.22.3 (2018-12-14)
Expand Down
10 changes: 7 additions & 3 deletions geotrek/trekking/management/commands/sync_rando.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def close_zip(zipfile):

tiles.run()

def sync_view(self, lang, view, name, url='/', params={}, zipfile=None, **kwargs):
def sync_view(self, lang, view, name, url='/', params={}, zipfile=None, fix2028=False, **kwargs):
if self.verbosity == 2:
self.stdout.write(u"\x1b[36m{lang}\x1b[0m \x1b[1m{name}\x1b[0m ...".format(lang=lang, name=name), ending="")
self.stdout.flush()
Expand Down Expand Up @@ -209,6 +209,10 @@ def sync_view(self, lang, view, name, url='/', params={}, zipfile=None, **kwargs
content = b''.join(response.streaming_content)
else:
content = response.content
# Fix strange unicode characters 2028 and 2029 that make Geotrek-mobile crash
if fix2028:
content = content.replace('\\u2028', '\\n')
content = content.replace('\\u2029', '\\n')
f.write(content)
f.close()
oldfilename = os.path.join(self.dst_root, name)
Expand All @@ -233,7 +237,7 @@ def sync_json(self, lang, viewset, name, zipfile=None, params={}, as_view_args=[
params['source'] = ','.join(self.source)
if self.portal:
params['portal'] = ','.join(self.portal)
self.sync_view(lang, view, name, params=params, zipfile=zipfile, **kwargs)
self.sync_view(lang, view, name, params=params, zipfile=zipfile, fix2028=True, **kwargs)

def sync_geojson(self, lang, viewset, name, zipfile=None, params={}, **kwargs):
view = viewset.as_view({'get': 'list'})
Expand All @@ -253,7 +257,7 @@ def sync_geojson(self, lang, viewset, name, zipfile=None, params={}, **kwargs):
elif 'portal' in params.keys():
del params['portal']

self.sync_view(lang, view, name, params=params, zipfile=zipfile, **kwargs)
self.sync_view(lang, view, name, params=params, zipfile=zipfile, fix2028=True, **kwargs)

def sync_trek_infrastructures(self, lang, trek, zipfile=None):
params = {'format': 'geojson'}
Expand Down
14 changes: 14 additions & 0 deletions geotrek/trekking/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ def test_sync(self):
self.assertEquals(len(treks['features']),
trek_models.Trek.objects.filter(published=True).count())

def test_sync_2028(self):
self.trek_1.description = u'toto\u2028tata'
self.trek_1.save()
self.trek_2.delete()
self.trek_3.delete()
self.trek_4.delete()
with mock.patch('geotrek.trekking.models.Trek.prepare_map_image'):
management.call_command('sync_rando', settings.SYNC_RANDO_ROOT, url='http://localhost:8000',
skip_tiles=True, skip_pdf=True, verbosity=0)
with open(os.path.join(settings.SYNC_RANDO_ROOT, 'api', 'en', 'treks.geojson'), 'r') as f:
treks = json.load(f)
# \u2028 is translated to \n
self.assertEquals(treks['features'][0]['properties']['description'], u'toto\ntata')

def test_sync_filtering_sources(self):
# source A only
with mock.patch('geotrek.trekking.models.Trek.prepare_map_image'):
Expand Down

0 comments on commit 375d3f0

Please sign in to comment.