[Erp5-report] r35905 jm - in /erp5/trunk/products: ERP5/Document/ ERP5/mixin/ ERP5Type/
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Jun 2 16:48:17 CEST 2010
Author: jm
Date: Wed Jun 2 16:48:13 2010
New Revision: 35905
URL: http://svn.erp5.org?rev=35905&view=rev
Log:
DMS: stop relying on ZPublisher to get parameters from the request
Previous code led to much code duplication. For DMS, each method redefining
'index_html' had to merge all possible parameters (with their default values)
of overridden methods. This was even worse for DocumentProxyMixin.index_html,
because the type of the proxied document is not even known.
This commit adds a new 'fill_args_from_request' decorator and fixes
'index_html' for proxied images (default value for 'frame' was only changed
in Image class).
Modified:
erp5/trunk/products/ERP5/Document/Document.py
erp5/trunk/products/ERP5/Document/Image.py
erp5/trunk/products/ERP5/mixin/downloadable.py
erp5/trunk/products/ERP5Type/Utils.py
Modified: erp5/trunk/products/ERP5/Document/Document.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Document.py?rev=35905&r1=35904&r2=35905&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Document.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Document.py [utf8] Wed Jun 2 16:48:13 2010
@@ -40,7 +40,7 @@
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.DateUtils import convertDateToHour,\
number_of_hours_in_day, number_of_hours_in_year
-from Products.ERP5Type.Utils import convertToUpperCase
+from Products.ERP5Type.Utils import convertToUpperCase, fill_args_from_request
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Type.ExtensibleTraversable import ExtensibleTraversableMixIn
from Products.ERP5Type.Cache import getReadOnlyTransactionCache
@@ -243,14 +243,10 @@
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
- security.declareProtected(Permissions.AccessContentsInformation,
- 'index_html' )
- def index_html(self, REQUEST, RESPONSE, display=None, format='', quality=75,
- resolution=None, frame=0, **kw):
+ security.declareProtected(Permissions.AccessContentsInformation,'index_html')
+ def index_html(self, REQUEST, *args, **kw):
""" Only a proxy method """
- return self.getProxiedDocument().index_html(REQUEST, RESPONSE,
- display=display, format=format, quality=quality, resolution=resolution,
- frame=frame, **kw)
+ return self.getProxiedDocument().index_html(REQUEST, *args, **kw)
security.declareProtected(Permissions.AccessContentsInformation,
'getProxiedDocument' )
Modified: erp5/trunk/products/ERP5/Document/Image.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Image.py?rev=35905&r1=35904&r2=35905&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Image.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Image.py [utf8] Wed Jun 2 16:48:13 2010
@@ -41,6 +41,7 @@
from DocumentTemplate.DT_Util import html_quote
from Products.CMFCore.utils import _setCacheHeaders, _ViewEmulator
from Products.ERP5Type import Permissions, PropertySheet
+from Products.ERP5Type.Utils import fill_args_from_request
from Products.ERP5.Document.File import File
from Products.ERP5.Document.Document import Document, ConversionError,\
VALID_TEXT_FORMAT_LIST
@@ -353,13 +354,11 @@
# Display
security.declareProtected('View', 'index_html')
- def index_html(self, REQUEST, RESPONSE, format=None, display=None,
- quality=DEFAULT_QUALITY, resolution=None, frame=None, **kw):
+ @fill_args_from_request('display', 'quality', 'resolution', 'frame')
+ def index_html(self, REQUEST, *args, **kw):
"""Return the image data."""
self._upradeImage()
- return Document.index_html(self, REQUEST, RESPONSE, format=format,
- display=display, quality=quality, resolution=resolution,
- frame=frame, **kw)
+ return Document.index_html(self, REQUEST, *args, **kw)
#
# Photo processing
Modified: erp5/trunk/products/ERP5/mixin/downloadable.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/mixin/downloadable.py?rev=35905&r1=35904&r2=35905&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/mixin/downloadable.py [utf8] (original)
+++ erp5/trunk/products/ERP5/mixin/downloadable.py [utf8] Wed Jun 2 16:48:13 2010
@@ -28,6 +28,7 @@
##############################################################################
from AccessControl import ClassSecurityInfo, Unauthorized
from Products.ERP5Type import Permissions
+from Products.ERP5Type.Utils import fill_args_from_request
from Products.CMFCore.utils import getToolByName, _setCacheHeaders,\
_ViewEmulator
@@ -36,6 +37,7 @@
### Content processing methods
security.declareProtected(Permissions.View, 'index_html')
+ @fill_args_from_request
def index_html(self, REQUEST, RESPONSE, format=None, **kw):
"""
We follow here the standard Zope API for files and images
Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=35905&r1=35904&r2=35905&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Wed Jun 2 16:48:13 2010
@@ -34,6 +34,7 @@
import time
import warnings
import sys
+import inspect
import persistent
try:
# Python 2.5 or later
@@ -349,6 +350,38 @@
this header
"""
return AddressList(text).addresslist
+
+def fill_args_from_request(*optional_args):
+ """Method decorator to fill missing args from given request
+
+ Without this decorator, code would have to rely on ZPublisher to get
+ paramaters from the REQUEST, which leads to much code duplication (copy and
+ paster of possible paramaters with their default values).
+
+ This decorator optional takes an list of names for parameters that are not
+ required by the method.
+ """
+ def decorator(wrapped):
+ names = inspect.getargspec(wrapped)[0]
+ assert names[:2] == ['self', 'REQUEST']
+ del names[:2]
+ names += optional_args
+ def wrapper(self, REQUEST=None, *args, **kw):
+ if REQUEST is not None:
+ for k in names[len(args):]:
+ if k not in kw:
+ v = REQUEST.get(k, kw)
+ if v is not kw:
+ kw[k] = v
+ return wrapped(self, REQUEST, *args, **kw)
+ wrapper.__name__ = wrapped.__name__
+ wrapper.__doc__ = wrapped.__doc__
+ return wrapper
+ if len(optional_args) == 1 and not isinstance(optional_args[0], basestring):
+ function, = optional_args
+ optional_args = ()
+ return decorator(function)
+ return decorator
#####################################################
# Globals initialization
More information about the Erp5-report
mailing list