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

Implement render_pdf on Fields, for use in erp5_pdf_style



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11307 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 53713aa2
...@@ -415,10 +415,9 @@ def StringBaseValidator_validate(self, field, key, REQUEST): ...@@ -415,10 +415,9 @@ def StringBaseValidator_validate(self, field, key, REQUEST):
StringBaseValidator.validate = StringBaseValidator_validate StringBaseValidator.validate = StringBaseValidator_validate
def render_hidden(self, field, key, value, REQUEST): def Widget_render_hidden(self, field, key, value, REQUEST):
"""Renders this widget as a hidden field. """Renders this widget as a hidden field.
""" """
#LOG('render_hidden',0,str(value))
try: try:
extra = field.get_value('extra') extra = field.get_value('extra')
except KeyError: except KeyError:
...@@ -442,7 +441,9 @@ def render_hidden(self, field, key, value, REQUEST): ...@@ -442,7 +441,9 @@ def render_hidden(self, field, key, value, REQUEST):
extra=extra) extra=extra)
return result return result
Widget.render_hidden = render_hidden Widget.render_hidden = Widget_render_hidden
# default render_pdf for a Widget
Widget.render_pdf = Widget.render_view
from Products.Formulator.Validator import LinesValidator from Products.Formulator.Validator import LinesValidator
...@@ -800,8 +801,8 @@ class PatchedDateTimeWidget(DateTimeWidget): ...@@ -800,8 +801,8 @@ class PatchedDateTimeWidget(DateTimeWidget):
return date_result + '   ' + time_result return date_result + '   ' + time_result
else: else:
return date_result return date_result
def render_view(self, field, value): def format_value(self, field, value, mode='html'):
if value is None: if value is None:
return '' return ''
...@@ -831,14 +832,25 @@ class PatchedDateTimeWidget(DateTimeWidget): ...@@ -831,14 +832,25 @@ class PatchedDateTimeWidget(DateTimeWidget):
else: else:
output = [year, month, day] output = [year, month, day]
date_result = string.join(output, field.get_value('date_separator')) date_result = string.join(output, field.get_value('date_separator'))
if mode in ('html', ):
space = ' '
else:
space = ' '
if not field.get_value('date_only'): if not field.get_value('date_only'):
time_result = hour + field.get_value('time_separator') + minute time_result = hour + field.get_value('time_separator') + minute
if use_ampm: if use_ampm:
time_result += ' ' + ampm time_result += space + ampm
return date_result + '   ' + time_result return date_result + (space * 3) + time_result
else: else:
return date_result return date_result
def render_view(self, field, value):
return self.format_value(field, value, mode='html')
def render_pdf(self, field, value):
return self.format_value(field, value, mode='pdf')
DateTimeField.widget = PatchedDateTimeWidget() DateTimeField.widget = PatchedDateTimeWidget()
...@@ -1045,6 +1057,9 @@ class FloatWidget(TextWidget): ...@@ -1045,6 +1057,9 @@ class FloatWidget(TextWidget):
return TextWidgetInstance.render_view(field, value) return TextWidgetInstance.render_view(field, value)
def render_pdf(self, field, value):
"""Render the field as PDF."""
return self.format_value(field, value)
FloatWidgetInstance = FloatWidget() FloatWidgetInstance = FloatWidget()
from Products.Formulator.StandardFields import FloatField from Products.Formulator.StandardFields import FloatField
...@@ -1113,8 +1128,14 @@ Field.render_htmlgrid = Field_render_htmlgrid ...@@ -1113,8 +1128,14 @@ Field.render_htmlgrid = Field_render_htmlgrid
# # Grid is only valid if stucture of grid has some meaning and is # # Grid is only valid if stucture of grid has some meaning and is
# # implemeted by listbox (ex. spreadsheet = grid) # # implemeted by listbox (ex. spreadsheet = grid)
# #
# def render_pdf(self, field, key, value, REQUEST):
# return 'whatever for reportlab' def Field_render_pdf(self, value=None, REQUEST=None, key=None, **kw):
"""
render_pdf renders the field for reportlab
"""
return self.widget.render_pdf(self, value)
Field.render_pdf = Field_render_pdf
from Products.Formulator.TALESField import TALESWidget from Products.Formulator.TALESField import TALESWidget
def TALESWidget_render_view(self, field, value): def TALESWidget_render_view(self, field, value):
...@@ -1131,4 +1152,3 @@ def TALESWidget_render_view(self, field, value): ...@@ -1131,4 +1152,3 @@ def TALESWidget_render_view(self, field, value):
return text return text
TALESWidget.render_view = TALESWidget_render_view TALESWidget.render_view = TALESWidget_render_view
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