plugin code changed according to new plugin specification ("pluginVisibility")
added ability to keep (and display) messages even after being redirected to another plugin (a little bit ugly)
This commit is contained in:
parent
151729c828
commit
c6acb6e45f
|
@ -12,12 +12,12 @@ class CryptoBoxPlugin:
|
||||||
## default capability is "system" - the other supported capability is: "volume"
|
## default capability is "system" - the other supported capability is: "volume"
|
||||||
pluginCapabilities = [ "system" ]
|
pluginCapabilities = [ "system" ]
|
||||||
|
|
||||||
|
## where should the plugin be visible by default?
|
||||||
|
pluginVisibility = [ "preferences" ]
|
||||||
|
|
||||||
## does this plugin require admin authentification?
|
## does this plugin require admin authentification?
|
||||||
requestAuth = False
|
requestAuth = False
|
||||||
|
|
||||||
## is this plugin enabled by default?
|
|
||||||
enabled = True
|
|
||||||
|
|
||||||
## default rank (0..100) of the plugin in listings (lower value means higher priority)
|
## default rank (0..100) of the plugin in listings (lower value means higher priority)
|
||||||
rank = 80
|
rank = 80
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ class CryptoBoxPlugin:
|
||||||
self.hdf_prefix = "Data.Plugins.%s." % self.getName()
|
self.hdf_prefix = "Data.Plugins.%s." % self.getName()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def doAction(self, **args):
|
def doAction(self, **args):
|
||||||
"""override doAction with your plugin code"""
|
"""override doAction with your plugin code"""
|
||||||
raise Exception, "undefined action handler ('doAction') in plugin '%'" % self.getName()
|
raise Exception, "undefined action handler ('doAction') in plugin '%'" % self.getName()
|
||||||
|
@ -125,16 +126,13 @@ class CryptoBoxPlugin:
|
||||||
"""check if this plugin is enabled
|
"""check if this plugin is enabled
|
||||||
first step: check plugin configuration
|
first step: check plugin configuration
|
||||||
second step: check default value of plugin"""
|
second step: check default value of plugin"""
|
||||||
import types
|
fallback = bool(self.pluginVisibility)
|
||||||
try:
|
try:
|
||||||
if self.cbox.prefs.pluginConf[self.getName()]["enabled"] is None:
|
if self.cbox.prefs.pluginConf[self.getName()]["visibility"] is None:
|
||||||
return self.enabled
|
return fallback
|
||||||
if self.cbox.prefs.pluginConf[self.getName()]["enabled"]:
|
return bool(self.cbox.prefs.pluginConf[self.getName()]["visibility"])
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return self.enabled
|
return fallback
|
||||||
|
|
||||||
|
|
||||||
def getRank(self):
|
def getRank(self):
|
||||||
|
@ -147,6 +145,15 @@ class CryptoBoxPlugin:
|
||||||
return int(self.cbox.prefs.pluginConf[self.getName()]["rank"])
|
return int(self.cbox.prefs.pluginConf[self.getName()]["rank"])
|
||||||
except KeyError, TypeError:
|
except KeyError, TypeError:
|
||||||
return self.rank
|
return self.rank
|
||||||
|
|
||||||
|
|
||||||
|
def getVisibility(self):
|
||||||
|
try:
|
||||||
|
if self.cbox.prefs.pluginConf[self.getName()]["visibility"] is None:
|
||||||
|
return self.pluginVisibility[:]
|
||||||
|
return self.cbox.prefs.pluginConf[self.getName()]["visibility"]
|
||||||
|
except KeyError:
|
||||||
|
return self.pluginVisibility
|
||||||
|
|
||||||
|
|
||||||
def getTestClass(self):
|
def getTestClass(self):
|
||||||
|
|
|
@ -387,7 +387,7 @@ CryptoBoxRootActions = string(min=1)
|
||||||
|
|
||||||
pluginValidationSpec = """
|
pluginValidationSpec = """
|
||||||
[__many__]
|
[__many__]
|
||||||
enabled = boolean(default=None)
|
visibility = boolean(default=None)
|
||||||
requestAuth = boolean(default=None)
|
requestAuth = boolean(default=None)
|
||||||
rank = integer(default=None)
|
rank = integer(default=None)
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -101,15 +101,20 @@ class WebInterfaceDataset(dict):
|
||||||
|
|
||||||
def setPluginData(self):
|
def setPluginData(self):
|
||||||
for p in self.plugins:
|
for p in self.plugins:
|
||||||
lang_data = p.getLanguageData()
|
|
||||||
entryName = "Settings.PluginList." + p.getName()
|
entryName = "Settings.PluginList." + p.getName()
|
||||||
|
## first: remove all existing settings of this plugin
|
||||||
|
for key in self.keys():
|
||||||
|
if key.startswith(entryName): del self[key]
|
||||||
|
lang_data = p.getLanguageData()
|
||||||
self[entryName] = p.getName()
|
self[entryName] = p.getName()
|
||||||
|
self[entryName + ".Name"] = lang_data.getValue("Name", p.getName())
|
||||||
self[entryName + ".Link"] = lang_data.getValue("Link", p.getName())
|
self[entryName + ".Link"] = lang_data.getValue("Link", p.getName())
|
||||||
self[entryName + ".Rank"] = p.getRank()
|
self[entryName + ".Rank"] = p.getRank()
|
||||||
self[entryName + ".RequestAuth"] = p.isAuthRequired() and "1" or "0"
|
self[entryName + ".RequestAuth"] = p.isAuthRequired() and "1" or "0"
|
||||||
self[entryName + ".Enabled"] = p.isEnabled() and "1" or "0"
|
|
||||||
for a in p.pluginCapabilities:
|
for a in p.pluginCapabilities:
|
||||||
self[entryName + ".Types." + a] = "1"
|
self[entryName + ".Types." + a] = "1"
|
||||||
|
for a in p.getVisibility():
|
||||||
|
self[entryName + ".Visible." + a] = "1"
|
||||||
|
|
||||||
|
|
||||||
def __setConfigValues(self):
|
def __setConfigValues(self):
|
||||||
|
|
|
@ -169,6 +169,14 @@ class WebInterfaceSites:
|
||||||
del args["redirect"]
|
del args["redirect"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
override_nextTemplate = None
|
override_nextTemplate = None
|
||||||
|
## check for information to be kept after the last call
|
||||||
|
try:
|
||||||
|
keep_values = args["message_keep"]
|
||||||
|
del args["message_keep"]
|
||||||
|
for key, value in keep_values["dataset"].items():
|
||||||
|
self.dataset[key] = value
|
||||||
|
except KeyError:
|
||||||
|
keep_values = None
|
||||||
## call the plugin handler
|
## call the plugin handler
|
||||||
nextTemplate = plugin.doAction(**args)
|
nextTemplate = plugin.doAction(**args)
|
||||||
## for 'volume' plugins: reread the dataset of the current disk
|
## for 'volume' plugins: reread the dataset of the current disk
|
||||||
|
@ -195,8 +203,21 @@ class WebInterfaceSites:
|
||||||
valueDict = dict(nextTemplate["values"])
|
valueDict = dict(nextTemplate["values"])
|
||||||
## force the current weblang attribute - otherwise it gets lost
|
## force the current weblang attribute - otherwise it gets lost
|
||||||
valueDict["weblang"] = self.dataset["Settings.Language"]
|
valueDict["weblang"] = self.dataset["Settings.Language"]
|
||||||
|
## check for warnings/success messages, that should be kept
|
||||||
|
if "Data.Warning" in plugin.hdf.keys() \
|
||||||
|
or "Data.Success" in plugin.hdf.keys():
|
||||||
|
self.cbox.log.info("keep warning message")
|
||||||
|
valueDict["message_keep"] = { "plugin":plugin, "dataset":{}}
|
||||||
|
for keep_key in ("Data.Warning", "Data.Success"):
|
||||||
|
if keep_key in plugin.hdf.keys():
|
||||||
|
valueDict["message_keep"]["dataset"][keep_key] = plugin.hdf[keep_key]
|
||||||
new_plugin = self.pluginList.getPlugin(nextTemplate["plugin"])
|
new_plugin = self.pluginList.getPlugin(nextTemplate["plugin"])
|
||||||
return self.return_plugin_action(new_plugin)(**valueDict)
|
return self.return_plugin_action(new_plugin)(**valueDict)
|
||||||
|
## did we want to keep some dataset values? then save the specified plugin
|
||||||
|
if keep_values:
|
||||||
|
if type(nextTemplate) == types.StringType:
|
||||||
|
nextTemplate = { "template":nextTemplate }
|
||||||
|
nextTemplate["old_plugin"] = keep_values["plugin"]
|
||||||
## save the currently active plugin name
|
## save the currently active plugin name
|
||||||
self.dataset["Data.ActivePlugin"] = plugin.getName()
|
self.dataset["Data.ActivePlugin"] = plugin.getName()
|
||||||
return self.__render(nextTemplate, plugin)
|
return self.__render(nextTemplate, plugin)
|
||||||
|
@ -367,12 +388,16 @@ class WebInterfaceSites:
|
||||||
## is renderInfo a string (filename of the template) or a dictionary?
|
## is renderInfo a string (filename of the template) or a dictionary?
|
||||||
if type(renderInfo) == types.DictType:
|
if type(renderInfo) == types.DictType:
|
||||||
template = renderInfo["template"]
|
template = renderInfo["template"]
|
||||||
|
if renderInfo.has_key("old_plugin"):
|
||||||
|
old_plugin = renderInfo["old_plugin"]
|
||||||
|
else:
|
||||||
|
old_plugin = None
|
||||||
if renderInfo.has_key("generator"):
|
if renderInfo.has_key("generator"):
|
||||||
generator = renderInfo["generator"]
|
generator = renderInfo["generator"]
|
||||||
else:
|
else:
|
||||||
generator = False
|
generator = None
|
||||||
else:
|
else:
|
||||||
(template, generator) = (renderInfo, None)
|
(template, generator, old_plugin) = (renderInfo, None, None)
|
||||||
|
|
||||||
## load the language data
|
## load the language data
|
||||||
hdf = neo_util.HDF()
|
hdf = neo_util.HDF()
|
||||||
|
@ -392,7 +417,14 @@ class WebInterfaceSites:
|
||||||
## load the language data
|
## load the language data
|
||||||
pl_lang = plugin.getLanguageData(self.dataset["Settings.Language"])
|
pl_lang = plugin.getLanguageData(self.dataset["Settings.Language"])
|
||||||
if pl_lang:
|
if pl_lang:
|
||||||
|
self.cbox.log.info("load plugin language: %s" % plugin.getName())
|
||||||
hdf.copy("Lang.Plugins.%s" % plugin.getName(), pl_lang)
|
hdf.copy("Lang.Plugins.%s" % plugin.getName(), pl_lang)
|
||||||
|
## was there an "old_plugin"? then load its language data, too
|
||||||
|
if old_plugin and (old_plugin != plugin):
|
||||||
|
pl_lang = old_plugin.getLanguageData(self.dataset["Settings.Language"])
|
||||||
|
if pl_lang:
|
||||||
|
self.cbox.log.info("load old plugin language: %s" % old_plugin.getName())
|
||||||
|
hdf.copy("Lang.Plugins.%s" % old_plugin.getName(), pl_lang)
|
||||||
## load the dataset of the plugin
|
## load the dataset of the plugin
|
||||||
plugin.loadDataSet(hdf)
|
plugin.loadDataSet(hdf)
|
||||||
|
|
||||||
|
@ -411,7 +443,7 @@ class WebInterfaceSites:
|
||||||
cs.parseFile(cs_path)
|
cs.parseFile(cs_path)
|
||||||
|
|
||||||
## is there a generator containing additional information?
|
## is there a generator containing additional information?
|
||||||
if generator is None:
|
if not generator:
|
||||||
## all content in one flush
|
## all content in one flush
|
||||||
yield cs.render()
|
yield cs.render()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue