]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/blobdiff - wrpylib/wrmwmarkup.py
Create "Buttonleiste" with key_value_template.
[philipp/winterrodeln/wrpylib.git] / wrpylib / wrmwmarkup.py
index 91d876ddacd9f54cfd2ecdc517ac47a0d51de59c..16ce286228021bc7d57113ffe072edfc180b9a7a 100644 (file)
@@ -3,7 +3,7 @@
 import re
 import xml.etree.ElementTree
 import collections
-from typing import Tuple, Optional, List, OrderedDict, Union, Dict
+from typing import Tuple, Optional, List, OrderedDict, Union, Dict, Any
 
 import jinja2
 from mwparserfromhell.nodes import Template, Wikilink
@@ -340,7 +340,7 @@ def create_wrmap(geojson: Dict) -> str:
                 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']
+        feature_xml.attrib = json_feature['properties'].copy()
         del feature_xml.attrib['type']
 
     if last_json_feature is not None:
@@ -377,6 +377,11 @@ class Jinja2Tools:
     def list_template(self, name: str, value: List[str]) -> str:
         return str(wrpylib.mwmarkup.create_template(name, value))
 
+    def key_value_template(self, name: str, value: Dict[str, Any], keep_empty: bool = False) -> str:
+        value = {k: str(v) for k, v in value.items()
+                 if keep_empty or (v is not None and not isinstance(v, jinja2.Undefined) and str(v).strip() != '')}
+        return str(wrpylib.mwmarkup.create_template(name, [], value))
+
     def json_template(self, value) -> str:
         args = []
         kwargs = {}