diff --git a/product/ERP5/Document/Document.py b/product/ERP5/Document/Document.py index 6c6d59acc2efb33089ee3fb5fd640e1ca71c9753..0e7259d28d47796f655c9b3b642a6fb05dfdc508 100644 --- a/product/ERP5/Document/Document.py +++ b/product/ERP5/Document/Document.py @@ -40,7 +40,7 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces 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 @@ class DocumentProxyMixin: 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' ) diff --git a/product/ERP5/Document/Image.py b/product/ERP5/Document/Image.py index 9a30bef7ea2794c28945ff5aff46f86b9b5fc9da..803339b4d0beb596c939239458860f7b1fdc8877 100644 --- a/product/ERP5/Document/Image.py +++ b/product/ERP5/Document/Image.py @@ -41,6 +41,7 @@ from Acquisition import aq_base 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 @@ class Image(TextConvertableMixin, File, OFSImage): # 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 diff --git a/product/ERP5/mixin/downloadable.py b/product/ERP5/mixin/downloadable.py index 01a88e4b7240f85e0dfdebe4a592eb8c0e3fb278..7a18bbfd0c850e79fd1063a08eb4a933d0bea32c 100644 --- a/product/ERP5/mixin/downloadable.py +++ b/product/ERP5/mixin/downloadable.py @@ -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 @@ class DownloadableMixin: ### 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 diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py index 1543ebea7d4523126f0f2a345c3c7488c3e56aae..4c9079417c93ec651c533a341fb675709c5bc99c 100644 --- a/product/ERP5Type/Utils.py +++ b/product/ERP5Type/Utils.py @@ -34,6 +34,7 @@ import string import time import warnings import sys +import inspect import persistent try: # Python 2.5 or later @@ -350,6 +351,38 @@ def Email_parseAddressHeader(text): """ 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 #####################################################