Worked on formatting of output from create_wrmap.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Wed, 28 Aug 2013 21:34:32 +0000 (21:34 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Wed, 28 Aug 2013 21:34:32 +0000 (21:34 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@1531 7aebc617-e5e2-0310-91dc-80fb5f6d2477

tests/test_wrmwmarkup.py
wrpylib/wrmwmarkup.py

index 77005dbc1fb712ca8be3ea78e541308702f30a25..2ac1d948583c36baadcc6ef4856e62424fdfb2ce 100644 (file)
@@ -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'''\
     <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
     <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
     <parkplatz>47.245789 11.238971</parkplatz>
@@ -177,5 +178,5 @@ def test_create_wrmap():
         47.244951 11.230868
         47.245470 11.237853
     </rodelbahn>
-    </wrmap>'''
+    </wrmap>''')
 
index 1ed237f3abb0b3b4ab25517ee10e76f874010a69..d131402f3bee9ddd57f6bf7887294cde726099c7 100644 (file)
@@ -515,19 +515,29 @@ def create_wrmap_coordinates(coords):
 def create_wrmap(geojson):
     """Creates a <wrmap> 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)