Commit b4b92a1f authored by Vincent Pelletier's avatar Vincent Pelletier

Update Formulator rendering API (except css and odt) to make it accept a new...

Update Formulator rendering API (except css and odt) to make it accept a new "render_prefix" parameter.
Its basic purpose is similar to existing "key" parameter, but instead of replacing field id it gets prepended to it.
Its "evolved" purpose is to make it possible to distinguish multiple renderings of the *same* field (same form, same field) in a single rendering sequence (ie, in the same web page).
It's safe to just ignore it when writing a renderer.
Update all existing renderers, and monkeypatch a few more.
Ignore the new parameter in all of them except ListBox (stored on renderer instance but not used yet).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21998 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent bdd36dcb
...@@ -64,7 +64,7 @@ class DurationWidget(FormulatorPatch.IntegerWidget): ...@@ -64,7 +64,7 @@ class DurationWidget(FormulatorPatch.IntegerWidget):
default="", default="",
required=1) required=1)
def render_view(self, field, value, REQUEST=None): def render_view(self, field, value, REQUEST=None, render_prefix=None):
sub_field_render_list = [] sub_field_render_list = []
for title, sub_key, convertion in (('Hour', 'hour', HOUR_IN_SECOND), for title, sub_key, convertion in (('Hour', 'hour', HOUR_IN_SECOND),
('Minute', 'minute', MINUTE_IN_SECOND)): ('Minute', 'minute', MINUTE_IN_SECOND)):
...@@ -80,7 +80,7 @@ class DurationWidget(FormulatorPatch.IntegerWidget): ...@@ -80,7 +80,7 @@ class DurationWidget(FormulatorPatch.IntegerWidget):
field, value, REQUEST=REQUEST)) field, value, REQUEST=REQUEST))
return ':'.join(sub_field_render_list) return ':'.join(sub_field_render_list)
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
sub_field_render_list = [] sub_field_render_list = []
for title, sub_key, convertion in (('Hour', 'hour', HOUR_IN_SECOND), for title, sub_key, convertion in (('Hour', 'hour', HOUR_IN_SECOND),
('Minute', 'minute', MINUTE_IN_SECOND)): ('Minute', 'minute', MINUTE_IN_SECOND)):
...@@ -97,14 +97,14 @@ class DurationWidget(FormulatorPatch.IntegerWidget): ...@@ -97,14 +97,14 @@ class DurationWidget(FormulatorPatch.IntegerWidget):
value, REQUEST, 'second')) value, REQUEST, 'second'))
return ':'.join(sub_field_render_list) return ':'.join(sub_field_render_list)
def render_sub_field_view(self, field, value, REQUEST=None): def render_sub_field_view(self, field, value, REQUEST=None, render_prefix=None):
""" """
Render dynamically a subfield Render dynamically a subfield
""" """
return FormulatorPatch.IntegerFieldWidgetInstance.render_view(field, value, return FormulatorPatch.IntegerFieldWidgetInstance.render_view(field, value,
REQUEST=REQUEST) REQUEST=REQUEST)
def render_sub_field(self, field, key, value, REQUEST, keyword): def render_sub_field(self, field, key, value, REQUEST, keyword, render_prefix=None):
""" """
Render dynamically a subfield Render dynamically a subfield
""" """
......
...@@ -72,7 +72,7 @@ class EditorWidget(Widget.TextAreaWidget): ...@@ -72,7 +72,7 @@ class EditorWidget(Widget.TextAreaWidget):
items=[('Standard Text Area', 'text_area'), items=[('Standard Text Area', 'text_area'),
('FCK Editor', 'fck_editor')]) ('FCK Editor', 'fck_editor')])
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
""" """
Render editor Render editor
""" """
...@@ -87,7 +87,7 @@ class EditorWidget(Widget.TextAreaWidget): ...@@ -87,7 +87,7 @@ class EditorWidget(Widget.TextAreaWidget):
'inputname' : key 'inputname' : key
}) })
def render_view(self, field, value, REQUEST=None): def render_view(self, field, value, REQUEST=None, render_prefix=None):
""" """
Render form in view only mode. Render form in view only mode.
""" """
......
...@@ -86,7 +86,7 @@ class FormBoxWidget(Widget.Widget): ...@@ -86,7 +86,7 @@ class FormBoxWidget(Widget.Widget):
default="", default="",
required=0) required=0)
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
""" """
Render a form in a field Render a form in a field
""" """
......
...@@ -60,7 +60,7 @@ def Field_generate_field_key(self, validation=0, key=None): ...@@ -60,7 +60,7 @@ def Field_generate_field_key(self, validation=0, key=None):
else: else:
return '%s.%s:record' % (self.field_record, self.id) return '%s.%s:record' % (self.field_record, self.id)
def Field_render(self, value=None, REQUEST=None, key=None): def Field_render(self, value=None, REQUEST=None, key=None, render_prefix=None):
"""Render the field widget. """Render the field widget.
value -- the value the field should have (for instance value -- the value the field should have (for instance
from validation). from validation).
...@@ -72,12 +72,12 @@ def Field_render(self, value=None, REQUEST=None, key=None): ...@@ -72,12 +72,12 @@ def Field_render(self, value=None, REQUEST=None, key=None):
""" """
return self._render_helper(self.generate_field_key(key=key), value, REQUEST) return self._render_helper(self.generate_field_key(key=key), value, REQUEST)
def Field_render_view(self, value=None, REQUEST=None): def Field_render_view(self, value=None, REQUEST=None, render_prefix=None):
"""Render value to be viewed. """Render value to be viewed.
""" """
return self.widget.render_view(self, value, REQUEST=REQUEST) return self.widget.render_view(self, value, REQUEST=REQUEST)
def Field_render_sub_field(self, id, value=None, REQUEST=None, key=None): def Field_render_sub_field(self, id, value=None, REQUEST=None, key=None, render_prefix=None):
"""Render a sub field, as part of complete rendering of widget in """Render a sub field, as part of complete rendering of widget in
a form. Works like render() but for sub field. a form. Works like render() but for sub field.
Added key parameter for ERP5 in order to be compatible with listbox/matrixbox Added key parameter for ERP5 in order to be compatible with listbox/matrixbox
...@@ -101,15 +101,25 @@ def Field_validate_sub_field(self, id, REQUEST, key=None): ...@@ -101,15 +101,25 @@ def Field_validate_sub_field(self, id, REQUEST, key=None):
return self.sub_form.get_field(id)._validate_helper( return self.sub_form.get_field(id)._validate_helper(
self.generate_subfield_key(id, validation=1, key=key), REQUEST) self.generate_subfield_key(id, validation=1, key=key), REQUEST)
def Field_render_helper(self, key, value, REQUEST): def Field_render_helper(self, key, value, REQUEST, render_prefix=None):
value = self._get_default(key, value, REQUEST) value = self._get_default(key, value, REQUEST)
__traceback_info__ = ('key=%s value=%r' % (key, value)) __traceback_info__ = ('key=%s value=%r' % (key, value))
if self.get_value('hidden', REQUEST=REQUEST): if self.get_value('hidden', REQUEST=REQUEST):
return self.widget.render_hidden(self, key, value, REQUEST) return self.widget.render_hidden(self, key, value, REQUEST)
elif (not self.get_value('editable', REQUEST=REQUEST)): elif (not self.get_value('editable', REQUEST=REQUEST)):
return self.widget.render_view(self, value, REQUEST=REQUEST) # XXX: API transition try..except..log..raise. Remove after a while.
try:
return self.widget.render_view(self, value, REQUEST=REQUEST, render_prefix=render_prefix)
except TypeError:
LOG('FormulatorPatch', 0, 'To update: %r (%r)' % (self.widget.render_view, getattr(self.widget.render_view, 'func_code', None)))
raise
else: else:
return self.widget.render(self, key, value, REQUEST) # XXX: API transition try..except..log..raise. Remove after a while.
try:
return self.widget.render(self, key, value, REQUEST, render_prefix=render_prefix)
except TypeError:
LOG('FormulatorPatch', 0, 'To update: %r (%r)' % (self.widget.render, getattr(self.widget.render, 'func_code', None)))
raise
def Field_get_user_input_value(self, key, REQUEST): def Field_get_user_input_value(self, key, REQUEST):
""" """
...@@ -289,7 +299,7 @@ def BooleanValidator_validate(self, field, key, REQUEST): ...@@ -289,7 +299,7 @@ def BooleanValidator_validate(self, field, key, REQUEST):
BooleanValidator.validate = BooleanValidator_validate BooleanValidator.validate = BooleanValidator_validate
from Products.Formulator.Widget import CheckBoxWidget from Products.Formulator.Widget import CheckBoxWidget
def CheckBoxWidget_render(self, field, key, value, REQUEST): def CheckBoxWidget_render(self, field, key, value, REQUEST, render_prefix=None):
"""Render checkbox. """Render checkbox.
""" """
rendered = [render_element("input", rendered = [render_element("input",
...@@ -317,7 +327,7 @@ def CheckBoxWidget_render(self, field, key, value, REQUEST): ...@@ -317,7 +327,7 @@ def CheckBoxWidget_render(self, field, key, value, REQUEST):
CheckBoxWidget.render = CheckBoxWidget_render CheckBoxWidget.render = CheckBoxWidget_render
def CheckBoxWidget_render_view(self, field, value, REQUEST=None): def CheckBoxWidget_render_view(self, field, value, REQUEST=None, render_prefix=None):
"""Render checkbox in view mode. """Render checkbox in view mode.
""" """
if value: if value:
...@@ -343,7 +353,7 @@ from Globals import get_request ...@@ -343,7 +353,7 @@ from Globals import get_request
from urlparse import urljoin from urlparse import urljoin
class PatchedLinkWidget(TextWidget): class PatchedLinkWidget(TextWidget):
def render_view(self, field, value, REQUEST=None): def render_view(self, field, value, REQUEST=None, render_prefix=None):
"""Render link. """Render link.
""" """
link_type = field.get_value('link_type', REQUEST=REQUEST) link_type = field.get_value('link_type', REQUEST=REQUEST)
...@@ -363,7 +373,7 @@ LinkField.widget = PatchedLinkWidgetInstance ...@@ -363,7 +373,7 @@ LinkField.widget = PatchedLinkWidgetInstance
# Patch the render_view of TextField to enclose the value within <span> html tags if css class defined # Patch the render_view of TextField to enclose the value within <span> html tags if css class defined
def TextWidget_patched_render_view(self, field, value, REQUEST=None): def TextWidget_patched_render_view(self, field, value, REQUEST=None, render_prefix=None):
"""Render text as non-editable. """Render text as non-editable.
This renderer is designed to be type error resistant. This renderer is designed to be type error resistant.
in we get a non string value. It does escape the result in we get a non string value. It does escape the result
...@@ -388,12 +398,23 @@ def TextWidget_patched_render_view(self, field, value, REQUEST=None): ...@@ -388,12 +398,23 @@ def TextWidget_patched_render_view(self, field, value, REQUEST=None):
from Products.Formulator.Widget import TextWidget from Products.Formulator.Widget import TextWidget
TextWidget.render_view = TextWidget_patched_render_view TextWidget.render_view = TextWidget_patched_render_view
original_TextWidget_render = TextWidget.render
def TextWidget_render(self, field, key, value, REQUEST, render_prefix=None):
return original_TextWidget_render(self, field, key, value, REQUEST)
TextWidget.render = TextWidget_render
from Products.Formulator.Widget import TextAreaWidget from Products.Formulator.Widget import TextAreaWidget
# Use a standard span rendering # Use a standard span rendering
TextAreaWidget.render_view = TextWidget_patched_render_view TextAreaWidget.render_view = TextWidget_patched_render_view
original_TextAreaWidget_render = TextAreaWidget.render
def TextAreaWidget_render(self, field, key, value, REQUEST, render_prefix=None):
return original_TextAreaWidget_render(self, field, key, value, REQUEST)
TextAreaWidget.render = TextAreaWidget_render
class IntegerWidget(TextWidget) : class IntegerWidget(TextWidget) :
def render(self, field, key, value, REQUEST) : def render(self, field, key, value, REQUEST, render_prefix=None) :
"""Render an editable integer. """Render an editable integer.
""" """
if isinstance(value, float): if isinstance(value, float):
...@@ -417,7 +438,7 @@ class IntegerWidget(TextWidget) : ...@@ -417,7 +438,7 @@ class IntegerWidget(TextWidget) :
size=field.get_value('display_width'), size=field.get_value('display_width'),
extra=field.get_value('extra')) extra=field.get_value('extra'))
def render_view(self, field, value, REQUEST=None): def render_view(self, field, value, REQUEST=None, render_prefix=None):
"""Render a non-editable interger.""" """Render a non-editable interger."""
if isinstance(value, float): if isinstance(value, float):
value = int(value) value = int(value)
...@@ -499,7 +520,7 @@ def Widget_render_hidden(self, field, key, value, REQUEST): ...@@ -499,7 +520,7 @@ def Widget_render_hidden(self, field, key, value, REQUEST):
extra=extra) extra=extra)
return result return result
def Widget_render_view(self, field, value, REQUEST=None): def Widget_render_view(self, field, value, REQUEST=None, render_prefix=None):
"""Renders this widget for public viewing. """Renders this widget for public viewing.
""" """
# default implementation # default implementation
...@@ -545,9 +566,23 @@ for widget_name in ('MultiItemsWidget', 'LabelWidget', ...@@ -545,9 +566,23 @@ for widget_name in ('MultiItemsWidget', 'LabelWidget',
'FileWidget', 'PasswordWidget',): 'FileWidget', 'PasswordWidget',):
widget = getattr(WidgetModule, widget_name) widget = getattr(WidgetModule, widget_name)
widget._old_render_view = widget.render_view widget._old_render_view = widget.render_view
widget.render_view = lambda self, field, value, REQUEST=None: \ widget.render_view = lambda self, field, value, REQUEST=None, render_prefix=None: \
self._old_render_view(field, value) self._old_render_view(field, value)
widget._old_render = widget.render
widget.render = lambda self, field, key, value, REQUEST=None, render_prefix=None: \
self._old_render(field, key, value, REQUEST)
from Products.Formulator.ListTextAreaField import ListTextAreaWidget
original_ListTextAreaWidget_render = ListTextAreaWidget.render
def ListTextAreaWidget_render(self, field, key, value, REQUEST, render_prefix=None):
return original_ListTextAreaWidget_render(self, field, key, value, REQUEST)
ListTextAreaWidget.render = ListTextAreaWidget_render
from Products.Formulator.MethodField import MethodWidget
original_MethodWidget_render = MethodWidget.render
def MethodWidget_render(self, field, key, value, REQUEST, render_prefix=None):
return original_MethodWidget_render(self, field, key, value, REQUEST)
MethodWidget.render = MethodWidget_render
from Products.Formulator.Validator import LinesValidator from Products.Formulator.Validator import LinesValidator
...@@ -612,7 +647,7 @@ FloatValidator.validate = FloatValidator_validate ...@@ -612,7 +647,7 @@ FloatValidator.validate = FloatValidator_validate
from Products.Formulator.Widget import SingleItemsWidget from Products.Formulator.Widget import SingleItemsWidget
def SingleItemsWidget_render_items(self, field, key, value, REQUEST): def SingleItemsWidget_render_items(self, field, key, value, REQUEST, render_prefix=None):
# get items # get items
cell = getattr(REQUEST, 'cell', None) cell = getattr(REQUEST, 'cell', None)
items = field.get_value('items', REQUEST=REQUEST, cell=cell) items = field.get_value('items', REQUEST=REQUEST, cell=cell)
...@@ -671,7 +706,7 @@ def SingleItemsWidget_render_items(self, field, key, value, REQUEST): ...@@ -671,7 +706,7 @@ def SingleItemsWidget_render_items(self, field, key, value, REQUEST):
SingleItemsWidget.render_items = SingleItemsWidget_render_items SingleItemsWidget.render_items = SingleItemsWidget_render_items
def SingleItemsWidget_render_view(self, field, value, REQUEST=None): def SingleItemsWidget_render_view(self, field, value, REQUEST=None, render_prefix=None):
""" """
This method is not as efficient as using a StringField in read only. This method is not as efficient as using a StringField in read only.
Always consider to change the field in your Form. Always consider to change the field in your Form.
...@@ -690,7 +725,7 @@ ListWidget.render_pdf = SingleItemsWidget_render_view ...@@ -690,7 +725,7 @@ ListWidget.render_pdf = SingleItemsWidget_render_view
RadioWidget.render_view = SingleItemsWidget_render_view RadioWidget.render_view = SingleItemsWidget_render_view
RadioWidget.render_pdf = SingleItemsWidget_render_view RadioWidget.render_pdf = SingleItemsWidget_render_view
def MultiItemsWidget_render_items(self, field, key, value, REQUEST): def MultiItemsWidget_render_items(self, field, key, value, REQUEST, render_prefix=None):
# list is needed, not a tuple # list is needed, not a tuple
if isinstance(value, tuple): if isinstance(value, tuple):
value = list(value) value = list(value)
...@@ -752,7 +787,7 @@ MultiItemsWidget.render_items = MultiItemsWidget_render_items ...@@ -752,7 +787,7 @@ MultiItemsWidget.render_items = MultiItemsWidget_render_items
from Products.Formulator.Widget import MultiListWidget from Products.Formulator.Widget import MultiListWidget
def MultiListWidget_render(self, field, key, value, REQUEST): def MultiListWidget_render(self, field, key, value, REQUEST, render_prefix=None):
rendered_items = self.render_items(field, key, value, REQUEST) rendered_items = self.render_items(field, key, value, REQUEST)
input_hidden = render_element('input', type='hidden', name="default_%s:int" % (key, ), value="0") input_hidden = render_element('input', type='hidden', name="default_%s:int" % (key, ), value="0")
multi_list = render_element( multi_list = render_element(
...@@ -770,7 +805,7 @@ MultiListWidget.render = MultiListWidget_render ...@@ -770,7 +805,7 @@ MultiListWidget.render = MultiListWidget_render
from Products.Formulator.Widget import MultiCheckBoxWidget from Products.Formulator.Widget import MultiCheckBoxWidget
def MultiCheckBoxWidget_render(self, field, key, value, REQUEST): def MultiCheckBoxWidget_render(self, field, key, value, REQUEST, render_prefix=None):
rendered_items = self.render_items(field, key, value, REQUEST) rendered_items = self.render_items(field, key, value, REQUEST)
rendered_items.append(render_element('input', type='hidden', name="default_%s:int" % (key, ), value="0")) rendered_items.append(render_element('input', type='hidden', name="default_%s:int" % (key, ), value="0"))
orientation = field.get_value('orientation') orientation = field.get_value('orientation')
...@@ -781,7 +816,7 @@ def MultiCheckBoxWidget_render(self, field, key, value, REQUEST): ...@@ -781,7 +816,7 @@ def MultiCheckBoxWidget_render(self, field, key, value, REQUEST):
MultiCheckBoxWidget.render = MultiCheckBoxWidget_render MultiCheckBoxWidget.render = MultiCheckBoxWidget_render
def ListWidget_render(self, field, key, value, REQUEST): def ListWidget_render(self, field, key, value, REQUEST, render_prefix=None):
rendered_items = self.render_items(field, key, value, REQUEST) rendered_items = self.render_items(field, key, value, REQUEST)
input_hidden = render_element('input', type='hidden', input_hidden = render_element('input', type='hidden',
name="default_%s:int" % (key, ), value="0") name="default_%s:int" % (key, ), value="0")
...@@ -868,7 +903,7 @@ class PatchedDateTimeWidget(DateTimeWidget): ...@@ -868,7 +903,7 @@ class PatchedDateTimeWidget(DateTimeWidget):
input_order = 'my' input_order = 'my'
return input_order return input_order
def render_dict(self, field, value): def render_dict(self, field, value, render_prefix=None):
""" """
This is yet another field rendering. It is designed to allow code to This is yet another field rendering. It is designed to allow code to
understand field's value data by providing its type and format when understand field's value data by providing its type and format when
...@@ -890,7 +925,7 @@ class PatchedDateTimeWidget(DateTimeWidget): ...@@ -890,7 +925,7 @@ class PatchedDateTimeWidget(DateTimeWidget):
'format': field.get_value('date_separator').join(input_order), 'format': field.get_value('date_separator').join(input_order),
'type': 'date'} 'type': 'date'}
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
use_ampm = field.get_value('ampm_time_style') use_ampm = field.get_value('ampm_time_style')
use_timezone = field.get_value('timezone_style') use_timezone = field.get_value('timezone_style')
# FIXME: backwards compatibility hack: # FIXME: backwards compatibility hack:
...@@ -1018,10 +1053,10 @@ class PatchedDateTimeWidget(DateTimeWidget): ...@@ -1018,10 +1053,10 @@ class PatchedDateTimeWidget(DateTimeWidget):
else: else:
return date_result return date_result
def render_view(self, field, value, REQUEST=None): def render_view(self, field, value, REQUEST=None, render_prefix=None):
return self.format_value(field, value, mode='html') return self.format_value(field, value, mode='html')
def render_pdf(self, field, value): def render_pdf(self, field, value, render_prefix=None):
return self.format_value(field, value, mode='pdf') return self.format_value(field, value, mode='pdf')
DateTimeField.widget = PatchedDateTimeWidget() DateTimeField.widget = PatchedDateTimeWidget()
...@@ -1338,7 +1373,7 @@ class FloatWidget(TextWidget): ...@@ -1338,7 +1373,7 @@ class FloatWidget(TextWidget):
return value.strip() return value.strip()
return '' return ''
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
"""Render Float input field """Render Float input field
""" """
value = self.format_value(field, value) value = self.format_value(field, value)
...@@ -1356,7 +1391,7 @@ class FloatWidget(TextWidget): ...@@ -1356,7 +1391,7 @@ class FloatWidget(TextWidget):
**extra_keys) **extra_keys)
def render_view(self, field, value, REQUEST=None): def render_view(self, field, value, REQUEST=None, render_prefix=None):
""" """
Render Float display field. Render Float display field.
This patch add: This patch add:
...@@ -1382,12 +1417,12 @@ class FloatWidget(TextWidget): ...@@ -1382,12 +1417,12 @@ class FloatWidget(TextWidget):
return "<span class='%s'>%s</span>" % (css_class, value) return "<span class='%s'>%s</span>" % (css_class, value)
return value return value
def render_pdf(self, field, value): def render_pdf(self, field, value, render_prefix=None):
"""Render the field as PDF.""" """Render the field as PDF."""
return self.format_value(field, value) return self.format_value(field, value)
def render_dict(self, field, value): def render_dict(self, field, value, render_prefix=None):
""" """
This is yet another field rendering. It is designed to allow code to This is yet another field rendering. It is designed to allow code to
understand field's value data by providing its type and format when understand field's value data by providing its type and format when
...@@ -1455,7 +1490,7 @@ def Field_render_html(self, *args, **kw): ...@@ -1455,7 +1490,7 @@ def Field_render_html(self, *args, **kw):
return self.render(*args, **kw) return self.render(*args, **kw)
Field.render_html = Field_render_html Field.render_html = Field_render_html
def Field_render_htmlgrid(self, value=None, REQUEST=None, key=None): def Field_render_htmlgrid(self, value=None, REQUEST=None, key=None, render_prefix=None):
""" """
render_htmlgrid returns a list of tuple (title, html render) render_htmlgrid returns a list of tuple (title, html render)
""" """
...@@ -1463,30 +1498,40 @@ def Field_render_htmlgrid(self, value=None, REQUEST=None, key=None): ...@@ -1463,30 +1498,40 @@ def Field_render_htmlgrid(self, value=None, REQUEST=None, key=None):
widget_key = self.generate_field_key(key=key) widget_key = self.generate_field_key(key=key)
value = self._get_default(widget_key, value, REQUEST) value = self._get_default(widget_key, value, REQUEST)
__traceback_info__ = ('key=%s value=%r' % (key, value)) __traceback_info__ = ('key=%s value=%r' % (key, value))
return self.widget.render_htmlgrid(self, widget_key, value, REQUEST) # XXX: API transition try..except..log..raise. Remove after a while.
try:
return self.widget.render_htmlgrid(self, widget_key, value, REQUEST, render_prefix=render_prefix)
except TypeError:
LOG('FormulatorPatch', 0, 'To update: %r (%r)' % (self.widget.render_htmlgrid, getattr(self.widget.render_htmlgrid, 'func_code', None)))
raise
Field.render_htmlgrid = Field_render_htmlgrid Field.render_htmlgrid = Field_render_htmlgrid
def Widget_render_htmlgrid(self, field, key, value, REQUEST): def Widget_render_htmlgrid(self, field, key, value, REQUEST, render_prefix=None):
""" """
render_htmlgrid returns a list of tuple (title, html render) render_htmlgrid returns a list of tuple (title, html render)
""" """
# XXX Calling _render_helper on the field is not optimized # XXX Calling _render_helper on the field is not optimized
# XXX: API transition try..except..log..raise. Remove after a while.
try:
return ((field.get_value('title'), return ((field.get_value('title'),
field._render_helper(key, value, REQUEST)),) field._render_helper(key, value, REQUEST, render_prefix=render_prefix)),)
except TypeError:
LOG('FormulatorPatch', 0, 'To update: %r (%r)' % (field._render_helper, getattr(field._render_helper, 'func_code', None)))
raise
Widget.render_htmlgrid = Widget_render_htmlgrid Widget.render_htmlgrid = Widget_render_htmlgrid
# Generic possible renderers # Generic possible renderers
# def render_ext(self, field, key, value, REQUEST): # def render_ext(self, field, key, value, REQUEST, render_prefix=None):
# return getattr(self, '%s_render' % self.__class__.__name__) # return getattr(self, '%s_render' % self.__class__.__name__)
# #
# def render_pt(self, field, key, value, REQUEST): # def render_pt(self, field, key, value, REQUEST, render_prefix=None):
# """ # """
# Call a page template which contains 1 macro per field # Call a page template which contains 1 macro per field
# """ # """
# return self.field_master(self.__class__.__name__) # return self.field_master(self.__class__.__name__)
# #
# def render_grid(self, field, key, value, REQUEST): # def render_grid(self, field, key, value, REQUEST, render_prefix=None):
# return ((self.get_value('title'), self.get_value('value'),) # return ((self.get_value('title'), self.get_value('value'),)
# # What about CSS ? What about description ? What about error ? # # What about CSS ? What about description ? What about error ?
# # What about rendering a listbox ? # # What about rendering a listbox ?
...@@ -1529,7 +1574,7 @@ Field.get_javascript_list = Field_get_javascript_list ...@@ -1529,7 +1574,7 @@ Field.get_javascript_list = Field_get_javascript_list
from Products.Formulator.TALESField import TALESWidget from Products.Formulator.TALESField import TALESWidget
def TALESWidget_render_view(self, field, value, REQUEST=None): def TALESWidget_render_view(self, field, value, REQUEST=None, render_prefix=None):
""" """
Render TALES as read only Render TALES as read only
""" """
...@@ -1584,15 +1629,16 @@ Field.PrincipiaSearchSource = Field_PrincipiaSearchSource ...@@ -1584,15 +1629,16 @@ Field.PrincipiaSearchSource = Field_PrincipiaSearchSource
from Products.Formulator.Widget import LinesTextAreaWidget from Products.Formulator.Widget import LinesTextAreaWidget
original_LinesTextAreaWidget_render = LinesTextAreaWidget.render original_LinesTextAreaWidget_render = LinesTextAreaWidget.render
def LinesTextAreaWidget_render(self, field, key, value, REQUEST): def LinesTextAreaWidget_render(self, field, key, value, REQUEST, render_prefix=None):
if isinstance(value, (str, unicode)): if isinstance(value, (str, unicode)):
value = [value] value = [value]
return original_LinesTextAreaWidget_render(self, field, key, value, REQUEST) return original_LinesTextAreaWidget_render(self, field, key, value, REQUEST)
LinesTextAreaWidget.render = LinesTextAreaWidget_render LinesTextAreaWidget.render = LinesTextAreaWidget_render
original_LinesTextAreaWidget_render_view = LinesTextAreaWidget.render_view original_LinesTextAreaWidget_render_view = LinesTextAreaWidget.render_view
def LinesTextAreaWidget_render_view(self, field, value, REQUEST=None): def LinesTextAreaWidget_render_view(self, field, value, REQUEST=None, render_prefix=None):
if isinstance(value, (str, unicode)): if isinstance(value, (str, unicode)):
value = [value] value = [value]
return original_LinesTextAreaWidget_render_view(self, field, value) return original_LinesTextAreaWidget_render_view(self, field, value)
LinesTextAreaWidget.render_view = LinesTextAreaWidget_render_view LinesTextAreaWidget.render_view = LinesTextAreaWidget_render_view
...@@ -14,7 +14,7 @@ class HyperLinkWidget(LabelWidget): ...@@ -14,7 +14,7 @@ class HyperLinkWidget(LabelWidget):
default="", default="",
required=1) required=1)
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
return render_element("a", return render_element("a",
href=field.get_value('href'), href=field.get_value('href'),
css_class=field.get_value('css_class'), css_class=field.get_value('css_class'),
......
...@@ -66,12 +66,12 @@ class ImageFieldWidget(Widget.TextWidget): ...@@ -66,12 +66,12 @@ class ImageFieldWidget(Widget.TextWidget):
default=75, default=75,
required=0) required=0)
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
"""Render image field as a link to the image """Render image field as a link to the image
""" """
return self.render_view(field, value, REQUEST=REQUEST) return self.render_view(field, value, REQUEST=REQUEST)
def render_view(self, field, value, REQUEST=None): def render_view(self, field, value, REQUEST=None, render_prefix=None):
"""Render image field as a link to the image """Render image field as a link to the image
""" """
# Url is already defined in value # Url is already defined in value
......
...@@ -68,7 +68,7 @@ class InputButtonWidget(Widget.Widget): ...@@ -68,7 +68,7 @@ class InputButtonWidget(Widget.Widget):
default='', default='',
required=0) required=0)
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
"""Render input button. """Render input button.
""" """
image = field.get_value('image') image = field.get_value('image')
......
...@@ -355,14 +355,14 @@ class ListBoxWidget(Widget.Widget): ...@@ -355,14 +355,14 @@ class ListBoxWidget(Widget.Widget):
required=0) required=0)
property_names.append('page_template') property_names.append('page_template')
def render_view(self, field, value, REQUEST=None, render_format='html', key='listbox'): def render_view(self, field, value, REQUEST=None, render_format='html', key='listbox', render_prefix=None):
""" """
Render a ListBox in read-only. Render a ListBox in read-only.
""" """
if REQUEST is None: REQUEST=get_request() if REQUEST is None: REQUEST=get_request()
return self.render(field, key, value, REQUEST, render_format=render_format) return self.render(field, key, value, REQUEST, render_format=render_format)
def render(self, field, key, value, REQUEST, render_format='html'): def render(self, field, key, value, REQUEST, render_format='html', render_prefix=None):
""" """
This is where most things happen. This method renders a list This is where most things happen. This method renders a list
of items of items
...@@ -390,7 +390,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -390,7 +390,7 @@ class ListBoxWidget(Widget.Widget):
if render_format == 'list': if render_format == 'list':
renderer = ListBoxListRenderer(self, field, REQUEST) renderer = ListBoxListRenderer(self, field, REQUEST)
else: else:
renderer = ListBoxHTMLRenderer(self, field, REQUEST) renderer = ListBoxHTMLRenderer(self, field, REQUEST, render_prefix=render_prefix)
return renderer() return renderer()
...@@ -417,12 +417,13 @@ class ListBoxRenderer: ...@@ -417,12 +417,13 @@ class ListBoxRenderer:
and a request object. and a request object.
""" """
def __init__(self, widget = None, field = None, REQUEST = None, **kw): def __init__(self, widget = None, field = None, REQUEST = None, render_prefix=None, **kw):
"""Store the parameters for later use. """Store the parameters for later use.
""" """
self.widget = widget self.widget = widget
self.field = field self.field = field
self.request = REQUEST self.request = REQUEST
self.render_prefix = render_prefix
def getPhysicalPath(self): def getPhysicalPath(self):
""" """
......
...@@ -175,7 +175,7 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -175,7 +175,7 @@ class MatrixBoxWidget(Widget.Widget):
"The cell range should be updated upon edit."), "The cell range should be updated upon edit."),
default=0) default=0)
def render(self, field, key, value, REQUEST, render_format='html'): def render(self, field, key, value, REQUEST, render_format='html', render_prefix=None):
""" """
This is where most things happen. This method renders a list This is where most things happen. This method renders a list
of items of items
......
...@@ -35,7 +35,7 @@ class MultiLinkFieldWidget(Widget.MultiItemsWidget): ...@@ -35,7 +35,7 @@ class MultiLinkFieldWidget(Widget.MultiItemsWidget):
property_names = Widget.Widget.property_names +\ property_names = Widget.Widget.property_names +\
['items', 'view_separator', 'extra', 'extra_item'] ['items', 'view_separator', 'extra', 'extra_item']
def render_item(self, item_text, item_value, key, css_class, extra_item) : def render_item(self, item_text, item_value, key, css_class, extra_item, render_prefix=None) :
"""Render an Item.""" """Render an Item."""
return Widget.render_element('a', return Widget.render_element('a',
href=item_value, href=item_value,
...@@ -45,7 +45,7 @@ class MultiLinkFieldWidget(Widget.MultiItemsWidget): ...@@ -45,7 +45,7 @@ class MultiLinkFieldWidget(Widget.MultiItemsWidget):
extra_item = extra_item) extra_item = extra_item)
render_selected_item = render_item render_selected_item = render_item
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
"""Render the field.""" """Render the field."""
rendered_items = self.render_items(field, key, value, REQUEST) rendered_items = self.render_items(field, key, value, REQUEST)
return field.get_value('view_separator').join(rendered_items) return field.get_value('view_separator').join(rendered_items)
......
...@@ -236,7 +236,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, ...@@ -236,7 +236,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
value_list, None)] value_list, None)]
return result_list return result_list
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
""" """
Render text input field. Render text input field.
""" """
...@@ -294,7 +294,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, ...@@ -294,7 +294,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
REQUEST.set('_v_relation_field_index', relation_field_index + 1) REQUEST.set('_v_relation_field_index', relation_field_index + 1)
return html_string return html_string
def render_view(self, field, value, REQUEST=None): def render_view(self, field, value, REQUEST=None, render_prefix=None):
""" """
Render read only field. Render read only field.
...@@ -310,7 +310,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, ...@@ -310,7 +310,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
return html_string return html_string
def render_wheel(self, field, value, REQUEST, relation_index=0, def render_wheel(self, field, value, REQUEST, relation_index=0,
sub_index=None): sub_index=None, render_prefix=None):
""" """
Render wheel used to display a listbox Render wheel used to display a listbox
""" """
...@@ -329,7 +329,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, ...@@ -329,7 +329,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
(portal_url_string, portal_selections_url_string, (portal_url_string, portal_selections_url_string,
relation_index, sub_index_string) relation_index, sub_index_string)
def render_relation_link(self, field, value, REQUEST): def render_relation_link(self, field, value, REQUEST, render_prefix=None):
""" """
Render link to the related object. Render link to the related object.
""" """
......
...@@ -378,7 +378,7 @@ class OOoChartWidget(Widget.Widget): ...@@ -378,7 +378,7 @@ class OOoChartWidget(Widget.Widget):
return extra_argument_dict return extra_argument_dict
def render_view(self, field, value, REQUEST=None, key=None, render_format='html'): def render_view(self, field, value, REQUEST=None, key=None, render_format='html', render_prefix=None):
""" """
Render a Chart in read-only. Render a Chart in read-only.
""" """
...@@ -386,7 +386,7 @@ class OOoChartWidget(Widget.Widget): ...@@ -386,7 +386,7 @@ class OOoChartWidget(Widget.Widget):
return self.render(field, key, value, REQUEST, render_format=render_format) return self.render(field, key, value, REQUEST, render_format=render_format)
def render_odf(self, field, key, value, REQUEST, render_format='ooo'): def render_odf(self, field, key, value, REQUEST, render_format='ooo', render_prefix=None):
""" """
Render a Chart for ODT Style. Render a Chart for ODT Style.
""" """
...@@ -399,7 +399,7 @@ class OOoChartWidget(Widget.Widget): ...@@ -399,7 +399,7 @@ class OOoChartWidget(Widget.Widget):
return content return content
def render(self, field, key, value, REQUEST, render_format='html'): def render(self, field, key, value, REQUEST, render_format='html', render_prefix=None):
""" """
Render a chart. Render a chart.
......
...@@ -220,7 +220,7 @@ class POSBoxWidget(Widget.Widget): ...@@ -220,7 +220,7 @@ class POSBoxWidget(Widget.Widget):
required=0, required=0,
group="order summary") group="order summary")
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
""" """
Render point of sales widget. Render point of sales widget.
""" """
...@@ -242,7 +242,7 @@ class POSBoxWidget(Widget.Widget): ...@@ -242,7 +242,7 @@ class POSBoxWidget(Widget.Widget):
fastResourceEntry_display = field.get_value("display_fastResourceEntry"), fastResourceEntry_display = field.get_value("display_fastResourceEntry"),
) )
def render_javascript(self, field, key, value, REQUEST): def render_javascript(self, field, key, value, REQUEST, render_prefix=None):
here = REQUEST['here'] here = REQUEST['here']
page_template = getattr(here,field.get_value("javascript_ZPT")) page_template = getattr(here,field.get_value("javascript_ZPT"))
...@@ -259,7 +259,7 @@ class POSBoxWidget(Widget.Widget): ...@@ -259,7 +259,7 @@ class POSBoxWidget(Widget.Widget):
resource_category_fastResourceEntry = field.get_value('resource_category_fastResourceEntry') resource_category_fastResourceEntry = field.get_value('resource_category_fastResourceEntry')
) )
def render_view(self, field, value, REQUEST=None): def render_view(self, field, value, REQUEST=None, render_prefix=None):
""" """
Render point of sales widget Render point of sales widget
""" """
...@@ -286,6 +286,6 @@ class POSBox(ZMIField): ...@@ -286,6 +286,6 @@ class POSBox(ZMIField):
def render_css(self, value=None, REQUEST=None): def render_css(self, value=None, REQUEST=None):
return self.widget.render_css(self,'',value,REQUEST) return self.widget.render_css(self,'',value,REQUEST)
def render_javascript(self, value=None, REQUEST=None): def render_javascript(self, value=None, REQUEST=None, render_prefix=None):
return self.widget.render_javascript(self,'',value,REQUEST) return self.widget.render_javascript(self,'',value,REQUEST)
...@@ -97,7 +97,7 @@ class ParallelListWidget(Widget.MultiListWidget, ...@@ -97,7 +97,7 @@ class ParallelListWidget(Widget.MultiListWidget,
'MultiListField': Widget.MultiListWidgetInstance, 'MultiListField': Widget.MultiListWidgetInstance,
} }
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
hash_list = generateSubForm(field, value, REQUEST) hash_list = generateSubForm(field, value, REQUEST)
# Call render on each sub field # Call render on each sub field
sub_field_render_list = [] sub_field_render_list = []
...@@ -111,7 +111,7 @@ class ParallelListWidget(Widget.MultiListWidget, ...@@ -111,7 +111,7 @@ class ParallelListWidget(Widget.MultiListWidget,
join(sub_field_render_list) join(sub_field_render_list)
return html_string return html_string
def render_htmlgrid(self, field, key, value, REQUEST): def render_htmlgrid(self, field, key, value, REQUEST, render_prefix=None):
hash_list = generateSubForm(field, value, REQUEST) hash_list = generateSubForm(field, value, REQUEST)
# Call render on each sub field # Call render on each sub field
sub_field_render_list = [] sub_field_render_list = []
...@@ -125,7 +125,7 @@ class ParallelListWidget(Widget.MultiListWidget, ...@@ -125,7 +125,7 @@ class ParallelListWidget(Widget.MultiListWidget,
return sub_field_render_list return sub_field_render_list
def render_sub_field(self, field, key, value, REQUEST, def render_sub_field(self, field, key, value, REQUEST,
sub_field_property_dict): sub_field_property_dict, render_prefix=None):
""" """
Render dynamically a subfield Render dynamically a subfield
""" """
......
...@@ -940,7 +940,7 @@ class PlanningBoxWidget(Widget.Widget): ...@@ -940,7 +940,7 @@ class PlanningBoxWidget(Widget.Widget):
return CSS_data return CSS_data
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
""" """
Method called to render the HTML code relative to the planning. Method called to render the HTML code relative to the planning.
for that recover the structure previouly saved in the REQUEST, and then for that recover the structure previouly saved in the REQUEST, and then
...@@ -961,7 +961,7 @@ class PlanningBoxWidget(Widget.Widget): ...@@ -961,7 +961,7 @@ class PlanningBoxWidget(Widget.Widget):
# return HTML data # return HTML data
return HTML_data return HTML_data
def render_structure(self, field, REQUEST, context): def render_structure(self, field, REQUEST, context, render_prefix=None):
""" """
This method is the begining of the rendering procedure. it calls all This method is the begining of the rendering procedure. it calls all
methods needed to generate BasicStructure with ERP5 objects, and then methods needed to generate BasicStructure with ERP5 objects, and then
......
...@@ -102,7 +102,7 @@ class ZGDChartWidget(Widget.Widget): ...@@ -102,7 +102,7 @@ class ZGDChartWidget(Widget.Widget):
default='', default='',
required=0) required=0)
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
""" """
This is where most things happens This is where most things happens
......
...@@ -94,7 +94,7 @@ class ZPyChartWidget(Widget.Widget): ...@@ -94,7 +94,7 @@ class ZPyChartWidget(Widget.Widget):
default='', default='',
required=0) required=0)
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_prefix=None):
""" """
Here, we just generate tags which will later call download Here, we just generate tags which will later call download
""" """
......
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