Commit 04c300c5 authored by Julien Muchembled's avatar Julien Muchembled

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).

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35905 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e1cc7fc2
...@@ -40,7 +40,7 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces ...@@ -40,7 +40,7 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.DateUtils import convertDateToHour,\ from Products.ERP5Type.DateUtils import convertDateToHour,\
number_of_hours_in_day, number_of_hours_in_year 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.TransactionalVariable import getTransactionalVariable
from Products.ERP5Type.ExtensibleTraversable import ExtensibleTraversableMixIn from Products.ERP5Type.ExtensibleTraversable import ExtensibleTraversableMixIn
from Products.ERP5Type.Cache import getReadOnlyTransactionCache from Products.ERP5Type.Cache import getReadOnlyTransactionCache
...@@ -243,14 +243,10 @@ class DocumentProxyMixin: ...@@ -243,14 +243,10 @@ class DocumentProxyMixin:
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,'index_html')
'index_html' ) def index_html(self, REQUEST, *args, **kw):
def index_html(self, REQUEST, RESPONSE, display=None, format='', quality=75,
resolution=None, frame=0, **kw):
""" Only a proxy method """ """ Only a proxy method """
return self.getProxiedDocument().index_html(REQUEST, RESPONSE, return self.getProxiedDocument().index_html(REQUEST, *args, **kw)
display=display, format=format, quality=quality, resolution=resolution,
frame=frame, **kw)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getProxiedDocument' ) 'getProxiedDocument' )
......
...@@ -41,6 +41,7 @@ from Acquisition import aq_base ...@@ -41,6 +41,7 @@ from Acquisition import aq_base
from DocumentTemplate.DT_Util import html_quote from DocumentTemplate.DT_Util import html_quote
from Products.CMFCore.utils import _setCacheHeaders, _ViewEmulator from Products.CMFCore.utils import _setCacheHeaders, _ViewEmulator
from Products.ERP5Type import Permissions, PropertySheet 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.File import File
from Products.ERP5.Document.Document import Document, ConversionError,\ from Products.ERP5.Document.Document import Document, ConversionError,\
VALID_TEXT_FORMAT_LIST VALID_TEXT_FORMAT_LIST
...@@ -353,13 +354,11 @@ class Image(TextConvertableMixin, File, OFSImage): ...@@ -353,13 +354,11 @@ class Image(TextConvertableMixin, File, OFSImage):
# Display # Display
security.declareProtected('View', 'index_html') security.declareProtected('View', 'index_html')
def index_html(self, REQUEST, RESPONSE, format=None, display=None, @fill_args_from_request('display', 'quality', 'resolution', 'frame')
quality=DEFAULT_QUALITY, resolution=None, frame=None, **kw): def index_html(self, REQUEST, *args, **kw):
"""Return the image data.""" """Return the image data."""
self._upradeImage() self._upradeImage()
return Document.index_html(self, REQUEST, RESPONSE, format=format, return Document.index_html(self, REQUEST, *args, **kw)
display=display, quality=quality, resolution=resolution,
frame=frame, **kw)
# #
# Photo processing # Photo processing
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo, Unauthorized from AccessControl import ClassSecurityInfo, Unauthorized
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.Utils import fill_args_from_request
from Products.CMFCore.utils import getToolByName, _setCacheHeaders,\ from Products.CMFCore.utils import getToolByName, _setCacheHeaders,\
_ViewEmulator _ViewEmulator
...@@ -36,6 +37,7 @@ class DownloadableMixin: ...@@ -36,6 +37,7 @@ class DownloadableMixin:
### Content processing methods ### Content processing methods
security.declareProtected(Permissions.View, 'index_html') security.declareProtected(Permissions.View, 'index_html')
@fill_args_from_request
def index_html(self, REQUEST, RESPONSE, format=None, **kw): def index_html(self, REQUEST, RESPONSE, format=None, **kw):
""" """
We follow here the standard Zope API for files and images We follow here the standard Zope API for files and images
......
...@@ -34,6 +34,7 @@ import string ...@@ -34,6 +34,7 @@ import string
import time import time
import warnings import warnings
import sys import sys
import inspect
import persistent import persistent
try: try:
# Python 2.5 or later # Python 2.5 or later
...@@ -350,6 +351,38 @@ def Email_parseAddressHeader(text): ...@@ -350,6 +351,38 @@ def Email_parseAddressHeader(text):
""" """
return AddressList(text).addresslist 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 # Globals initialization
##################################################### #####################################################
......
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