@@ -12,9 +12,9 @@ def formatString(format: str, data: typing.Dict, structure=None, language=None):
1212
1313 """
1414 if "$(" in format :
15- return formatStringHandler (format ,data ,structure ,language = language )
15+ return formatStringHandler (format , data , structure , language = language )
16+ return evalStringHandler (format , data , structure , language )
1617
17- return evalStringHandler (format ,data ,structure ,language )
1818
1919# formatString ---------------------------------------------------------------------------------------------------------
2020def formatOneEntry (key , format , data , structure = None , prefix = None , language = None , context = None , _rec = 0 ):
@@ -43,7 +43,8 @@ def formatOneEntry(key, format, data, structure=None, prefix=None, language=None
4343 res , val , structure , prefix + [key ], language , _rec = _rec + 1
4444 )
4545
46- elif isinstance (val , list ) and len (val ) > 0 and isinstance (val [0 ], dict ): # if bone is relationalbone with rel and dest
46+ elif isinstance (val , list ) and len (val ) > 0 and isinstance (val [0 ],
47+ dict ): # if bone is relationalbone with rel and dest
4748 if struct and "dest" in val [0 ] and "rel" in val [0 ]:
4849 if "relskel" in struct and "format" in struct :
4950 format = struct ["format" ]
@@ -83,6 +84,7 @@ def formatOneEntry(key, format, data, structure=None, prefix=None, language=None
8384 res = res .replace ("$(%s)" % ("." .join (prefix + [key ])), str (val ))
8485 return res
8586
87+
8688def formatStringHandler (format , data , structure = None , prefix = None , language = None , context = None , _rec = 0 ):
8789 """Parses a string given by format and substitutes placeholders using values specified by data.
8890 The syntax for the placeholders is $(%s).
@@ -104,7 +106,7 @@ def formatStringHandler(format, data, structure=None, prefix=None, language=None
104106 :return: The traversed string with the replaced values.
105107 :rtype: str
106108 """
107- #print("FORMAT STRING", format, data, structure, prefix)
109+ # print("FORMAT STRING", format, data, structure, prefix)
108110 if structure and isinstance (structure , list ):
109111 structure = {k : v for k , v in structure }
110112
@@ -130,8 +132,10 @@ def formatStringHandler(format, data, structure=None, prefix=None, language=None
130132
131133 return res
132134
135+
133136# displayString ---------------------------------------------------------------------------------------------------------
134- def displayStringHandler (display : str , value : typing .Dict , structure : typing .Dict , language : str = "de" ) -> [html5 .Widget ]:
137+ def displayStringHandler (display : str , value : typing .Dict , structure : typing .Dict , language : str = "de" ) -> [
138+ html5 .Widget ]:
135139 from flare .forms import boneSelector
136140
137141 # --- Helpers ---
@@ -142,6 +146,7 @@ def listToDict(l):
142146
143147 assert isinstance (l , dict )
144148 return l
149+
145150 # ---------------
146151
147152 widgets = []
@@ -188,17 +193,20 @@ def listToDict(l):
188193
189194 return widgets
190195
196+
191197# evalString ---------------------------------------------------------------------------------------------------------
192198def evalStringHandler (format , data , structure , language ):
193199 if not html5 .core .htmlExpressionEvaluator :
194200 return format
195201
196202 try :
197- value = html5 .core .htmlExpressionEvaluator .execute (format , data )
203+ value = html5 .core .htmlExpressionEvaluator .execute (format , {"value" :data ,
204+ "structure" :structure ,
205+ "language" :language
206+ }
207+ )
198208 except Exception as e :
199209 logging .exception (e )
200210 value = "(invalid format string)"
201211
202212 return value
203-
204-
0 commit comments