Commit f911a8a8 authored by Jérome Perrin's avatar Jérome Perrin

Define a generic method to delegate a call to the original field widget. This

method is used by all methods called on the field from page templates: render,
render_view, render_css, render_pdf etc
Also add render_pdf to those methods.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15777 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent da14d24f
......@@ -42,12 +42,29 @@ from Products.PythonScripts.Utility import allow_class
from Products.PythonScripts.standard import url_quote_plus
from AccessControl import ClassSecurityInfo
import string
from MethodObject import Method
from zLOG import LOG, WARNING, DEBUG
from Acquisition import aq_base, aq_inner, aq_acquire, aq_chain
from Globals import DTMLFile
class WidgetDelegatedMethod(Method):
"""Method delegated to the proxied field's widget.
"""
def __init__(self, method_id, default=''):
self._method_id = method_id
self._default = default
def __call__(self, instance, *args, **kw):
field = instance
proxied_field = field.getRecursiveTemplateField()
if proxied_field:
proxied_method = getattr(proxied_field.widget, self._method_id)
return proxied_method(field, *args, **kw)
return self._default
class ProxyWidget(Widget.Widget):
"""
A widget that renders itself as a field from another form
......@@ -86,55 +103,15 @@ class ProxyWidget(Widget.Widget):
href='manage_edit_target',
required=0)
def render(self, field, key, value, REQUEST):
"""
Render proxy field
"""
result = ''
proxy_field = field.getRecursiveTemplateField()
if proxy_field is not None:
result = proxy_field.widget.render(field, key, value, REQUEST)
return result
def render_htmlgrid(self, field, key, value, REQUEST):
"""
Render proxy field
"""
result = ''
proxy_field = field.getRecursiveTemplateField()
if proxy_field is not None:
result = proxy_field.widget.render_htmlgrid(field, key, value, REQUEST)
return result
# Field API Methods, delegated to the template field widget
render = WidgetDelegatedMethod('render', default='')
render_htmlgrid = WidgetDelegatedMethod('render_htmlgrid', default='')
render_view = WidgetDelegatedMethod('render_view', default='')
render_pdf = WidgetDelegatedMethod('render_pdf', default='')
render_css = WidgetDelegatedMethod('render_css', default='')
get_javascript_list = WidgetDelegatedMethod(
'get_javascript_list', default=[])
def render_view(self, field, value):
"""
Display proxy field
"""
result = ''
proxy_field = field.getRecursiveTemplateField()
if proxy_field is not None:
result = proxy_field.widget.render_view(field, value)
return result
def render_css(self, field, REQUEST):
"""
Render proxy field
"""
result = ''
proxy_field = field.getRecursiveTemplateField()
if proxy_field is not None:
result = proxy_field.widget.render_css(field, REQUEST)
return result
def get_javascript_list(self, field, REQUEST):
"""
Render proxy field
"""
result = []
proxy_field = field.getRecursiveTemplateField()
if proxy_field is not None:
result = proxy_field.widget.get_javascript_list(field, REQUEST)
return result
class ProxyValidator(Validator.Validator):
"""
......
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