From: philipp Date: Wed, 28 Aug 2013 21:34:32 +0000 (+0000) Subject: Worked on formatting of output from create_wrmap. X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/wrpylib.git/commitdiff_plain/9aa63dcdf2fbd61b13771dc504a3767613492b4d?hp=f71116f2cd846d18c7a120ca1ed640b2e68012fc Worked on formatting of output from create_wrmap. git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@1531 7aebc617-e5e2-0310-91dc-80fb5f6d2477 --- diff --git a/tests/test_wrmwmarkup.py b/tests/test_wrmwmarkup.py index 77005db..2ac1d94 100644 --- a/tests/test_wrmwmarkup.py +++ b/tests/test_wrmwmarkup.py @@ -2,6 +2,7 @@ # -*- coding: iso-8859-15 -*- import wrpylib.wrmwmarkup import formencode +import textwrap def test_rodelbahnbox_to_sledrun(): @@ -167,7 +168,7 @@ def test_create_wrmap(): } wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson) - assert wikitext == u''' + assert wikitext == textwrap.dedent(u'''\ 47.240689 11.190454 47.245789 11.238971 @@ -177,5 +178,5 @@ def test_create_wrmap(): 47.244951 11.230868 47.245470 11.237853 - ''' + ''') diff --git a/wrpylib/wrmwmarkup.py b/wrpylib/wrmwmarkup.py index 1ed237f..d131402 100644 --- a/wrpylib/wrmwmarkup.py +++ b/wrpylib/wrmwmarkup.py @@ -515,19 +515,29 @@ def create_wrmap_coordinates(coords): def create_wrmap(geojson): """Creates a wikitext from geojson (as python types).""" wrmap_xml = xml.etree.ElementTree.Element('wrmap') + wrmap_xml.text = '\n\n' for k, v in geojson['properties'].iteritems(): wrmap_xml.attrib[k] = str(v) assert geojson['type'] == 'FeatureCollection' json_features = geojson['features'] + last_json_feature = None for json_feature in json_features: feature_xml = xml.etree.ElementTree.SubElement(wrmap_xml, json_feature['properties']['type']) geo = json_feature['geometry'] if geo['type'] == 'Point': feature_xml.text = create_wrmap_coordinates([geo['coordinates']]) + if last_json_feature is not None: + last_json_feature.tail = '\n' else: - feature_xml.text = create_wrmap_coordinates(geo['coordinates']) + if last_json_feature is not None: + last_json_feature.tail = '\n\n' + feature_xml.text = '\n' + create_wrmap_coordinates(geo['coordinates']) + '\n' + last_json_feature = feature_xml feature_xml.attrib = json_feature['properties'] + print last_json_feature.tag + if last_json_feature is not None: + last_json_feature.tail = '\n\n' return xml.etree.ElementTree.tostring(wrmap_xml)