Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
authorEdouard Tisserant
Mon, 15 Jun 2020 14:27:58 +0200
changeset 2672 4bc60e426dd6
parent 2671 30493ff3a23a
child 2673 80e7eb44cab4
Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
bacnet/web_settings.py
modbus/web_settings.py
runtime/NevowServer.py
--- a/bacnet/web_settings.py	Fri Jun 12 14:40:50 2020 +0200
+++ b/bacnet/web_settings.py	Mon Jun 15 14:27:58 2020 +0200
@@ -346,7 +346,7 @@
         if _CheckConfiguration(_SavedConfiguration):
             _SetPLCConfiguration(_SavedConfiguration)
             
-    WebSettings = NS.newExtensionSetting("BACnet")
+    WebSettings = NS.newExtensionSetting("BACnet extension", "bacnet_token")
 
     # Configure the web interface to include the BACnet config parameters
     WebSettings.addSettings(
@@ -384,7 +384,7 @@
 
     #PLCObject.LogMessage("BACnet web server extension::OnUnLoadPLC() Called...")
     
-    NS.removeExtensionSetting("BACnet")
+    NS.removeExtensionSetting("bacnet_token")
     
     GetParamFuncs = {}
     SetParamFuncs = {}
--- a/modbus/web_settings.py	Fri Jun 12 14:40:50 2020 +0200
+++ b/modbus/web_settings.py	Mon Jun 15 14:27:58 2020 +0200
@@ -488,7 +488,7 @@
     def __OnButtonSave(**kwargs):
         OnButtonSave(WebNode_id=WebNode_id, **kwargs)
 
-    WebSettings = NS.newExtensionSetting("Modbus "+config_hash)
+    WebSettings = NS.newExtensionSetting("Modbus #"+ str(WebNode_id), config_hash)
 
     WebSettings.addSettings(
         "ModbusConfigParm"          + config_hash,     # name (internal, may not contain spaces, ...)
@@ -605,10 +605,10 @@
     
     # Delete the Modbus specific web interface extensions
     # (Safe to ask to delete, even if it has not been added!)
-    global _WebNodeList    
-    for WebNode_entry in _WebNodeList:
+    global _WebNodeList
+    for index, WebNode_entry in enumerate(_WebNodeList):
         config_hash = WebNode_entry["config_hash"]
-        NS.removeExtensionSetting("Modbus "+config_hash)
+        NS.removeExtensionSetting(config_hash)
         
     # Dele all entries...
     _WebNodeList = []
--- a/runtime/NevowServer.py	Fri Jun 12 14:40:50 2020 +0200
+++ b/runtime/NevowServer.py	Mon Jun 15 14:27:58 2020 +0200
@@ -185,15 +185,15 @@
 
 ConfigurableSettings = ConfigurableBindings()
 
-def newExtensionSetting(ext_name):
+def newExtensionSetting(display, token):
     global extensions_settings_od
     settings = ConfigurableBindings()
-    extensions_settings_od[ext_name] = settings
+    extensions_settings_od[token] = (settings, display)
     return settings
 
-def removeExtensionSetting(ext_name):
+def removeExtensionSetting(token):
     global extensions_settings_od
-    extensions_settings_od.pop(ext_name)
+    extensions_settings_od.pop(token)
 
 class ISettings(annotate.TypedInterface):
     platform = annotate.String(label=_("Platform"),
@@ -236,9 +236,10 @@
     def __getattr__(self, name):
         global extensions_settings_od
         if name.startswith('configurable_'):
-            ext_name = name[13:]
+            token = name[13:]
             def configurable_something(ctx):
-                return extensions_settings_od[ext_name]
+                settings, _display = extensions_settings_od[token]
+                return settings
             return configurable_something
         raise AttributeError
     
@@ -248,8 +249,9 @@
         """
         global extensions_settings_od
         res = []
-        for ext_name in extensions_settings_od:
-            res += [tags.h2[ext_name], webform.renderForms(ext_name)] 
+        for token in extensions_settings_od:
+            _settings, display = extensions_settings_od[token]
+            res += [tags.h2[display], webform.renderForms(token)] 
         return res
 
     docFactory = loaders.stan([tags.html[