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
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' )
......
......@@ -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
......
......@@ -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
......
......@@ -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
#####################################################
......
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