Commit 58331c88 authored by Casey Duncan's avatar Casey Duncan

Fixed problem where external methods did not setup the func_defaults properly...

Fixed problem where external methods did not setup the func_defaults properly on first load. This resulted in ZPublisher being unable to properly arguments to Ex Methods on the first try.
parent b839009d
...@@ -92,6 +92,10 @@ Zope Changes ...@@ -92,6 +92,10 @@ Zope Changes
Bugs: Bugs:
- External methods didn't properly setup func_defaults and func_code
when they were first loaded. This meant mapply couldn't properly map
arguments on the first try.
- Fixed bug #96: Narrower/Wider buttons now work on both CSS and non-CSS - Fixed bug #96: Narrower/Wider buttons now work on both CSS and non-CSS
compliant browsers. This allows better control for browsers that have a compliant browsers. This allows better control for browsers that have a
hard time knowing what 100% means. hard time knowing what 100% means.
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
This product provides support for external methods, which allow This product provides support for external methods, which allow
domain-specific customization of web environments. domain-specific customization of web environments.
""" """
__version__='$Revision: 1.48 $'[11:-2] __version__='$Revision: 1.49 $'[11:-2]
from Globals import Persistent, DTMLFile, MessageDialog, HTML from Globals import Persistent, DTMLFile, MessageDialog, HTML
import OFS.SimpleItem, Acquisition import OFS.SimpleItem, Acquisition
import AccessControl.Role, sys, os, stat, traceback import AccessControl.Role, sys, os, stat, traceback
...@@ -80,8 +80,9 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, Acquisition.Explicit, ...@@ -80,8 +80,9 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, Acquisition.Explicit,
meta_type = 'External Method' meta_type = 'External Method'
func_defaults = ComputedAttribute(lambda self: self._v_func_defaults) func_defaults = ComputedAttribute(lambda self: self.getFuncDefaults())
func_code = ComputedAttribute(lambda self: self._v_func_code) func_code = ComputedAttribute(lambda self: self.getFuncCode())
ZopeTime=Acquisition.Acquired ZopeTime=Acquisition.Acquired
HelpSys=Acquisition.Acquired HelpSys=Acquisition.Acquired
...@@ -146,7 +147,38 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, Acquisition.Explicit, ...@@ -146,7 +147,38 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, Acquisition.Explicit,
return f return f
def reloadIfChanged(self):
# If the file has been modified since last loaded, force a reload.
ts=os.stat(self.filepath())[stat.ST_MTIME]
if (not hasattr(self, '_v_last_read') or
(ts != self._v_last_read)):
self._v_f=self.getFunction(1)
self._v_last_read=ts
if DevelopmentMode:
# In development mode we do an automatic reload
# if the module code changed
def getFuncDefaults(self):
self.reloadIfChanged()
if not hasattr(self, '_v_func_defaults'):
self._v_f = self.getFunction()
return self._v_func_defaults
def getFuncCode(self):
self.reloadIfChanged()
if not hasattr(self, '_v_func_code'):
self._v_f = self.getFunction()
return self._v_func_code
else:
def getFuncDefaults(self):
if not hasattr(self, '_v_func_defaults'):
self._v_f = self.getFunction()
return self._v_func_defaults
def getFuncCode(self):
if not hasattr(self, '_v_func_code'):
self._v_f = self.getFunction()
return self._v_func_code
def __call__(self, *args, **kw): def __call__(self, *args, **kw):
"""Call an ExternalMethod """Call an ExternalMethod
...@@ -178,14 +210,8 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, Acquisition.Explicit, ...@@ -178,14 +210,8 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, Acquisition.Explicit,
"external method could not be called " \ "external method could not be called " \
"because the file does not exist" "because the file does not exist"
if DevelopmentMode: if DevelopmentMode:
# If the file has been modified since last loaded, force a reload. self.reloadIfChanged()
ts=os.stat(self.filepath())[stat.ST_MTIME]
if (not hasattr(self, '_v_last_read') or
(ts != self._v_last_read)):
self._v_f=self.getFunction(1)
self._v_last_read=ts
if hasattr(self, '_v_f'): if hasattr(self, '_v_f'):
f=self._v_f f=self._v_f
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment