Commit 7f6f6506 authored by Romain Courteaud's avatar Romain Courteaud

Creation of a list render for the PDF print.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2062 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 44dc35d8
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
############################################################################## ##############################################################################
import string import string
from AccessControl import ClassSecurityInfo
from Products.Formulator.DummyField import fields from Products.Formulator.DummyField import fields
from Products.Formulator import Widget, Validator from Products.Formulator import Widget, Validator
from Products.Formulator.Field import ZMIField from Products.Formulator.Field import ZMIField
...@@ -139,7 +140,7 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -139,7 +140,7 @@ class MatrixBoxWidget(Widget.Widget):
default=0) default=0)
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST, render_format='html'):
""" """
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
...@@ -170,6 +171,9 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -170,6 +171,9 @@ class MatrixBoxWidget(Widget.Widget):
# IT IS BAD BECAUSE TAB_IDS DO NOT DEFINE A RANGE.... # IT IS BAD BECAUSE TAB_IDS DO NOT DEFINE A RANGE....
# here.setCellRange(line_ids, column_ids, base_id=cell_base_id) # here.setCellRange(line_ids, column_ids, base_id=cell_base_id)
# result for the list render
list_result = []
url = REQUEST.URL url = REQUEST.URL
list_html = '' list_html = ''
...@@ -181,6 +185,9 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -181,6 +185,9 @@ class MatrixBoxWidget(Widget.Widget):
if type(tab_id) is not type(()) and type(tab_id) is not type([]) and tab_id is not None: if type(tab_id) is not type(()) and type(tab_id) is not type([]) and tab_id is not None:
tab_id = [tab_id] tab_id = [tab_id]
if render_format == 'list':
list_result_tab = [[tab[1]]]
# Create the header of the table - this should probably become DTML # Create the header of the table - this should probably become DTML
header = """\ header = """\
<!-- Matrix Content --> <!-- Matrix Content -->
...@@ -212,6 +219,9 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -212,6 +219,9 @@ class MatrixBoxWidget(Widget.Widget):
for cname in columns: for cname in columns:
list_header = list_header + ("<td class=\"Data\">%s</td>\n" % list_header = list_header + ("<td class=\"Data\">%s</td>\n" %
str(cname[1])) str(cname[1]))
if render_format == 'list':
list_result_tab[0].append(cname[1])
list_header = list_header + "</tr>" list_header = list_header + "</tr>"
# Build Lines # Build Lines
...@@ -219,6 +229,8 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -219,6 +229,8 @@ class MatrixBoxWidget(Widget.Widget):
j = 0 j = 0
list_body = '' list_body = ''
for l in lines: for l in lines:
if not i % 2: if not i % 2:
td_css = 'DataA' td_css = 'DataA'
else: else:
...@@ -226,6 +238,9 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -226,6 +238,9 @@ class MatrixBoxWidget(Widget.Widget):
list_body = list_body + '<tr><td class=\"%s\">%s</td>' % (td_css, str(l[1])) list_body = list_body + '<tr><td class=\"%s\">%s</td>' % (td_css, str(l[1]))
j = 0 j = 0
if render_format == 'list':
list_result_lines = [ str(l[1]) ]
for c in columns: for c in columns:
#if column_id is None and tab_id is None: #if column_id is None and tab_id is None:
...@@ -254,18 +269,35 @@ class MatrixBoxWidget(Widget.Widget): ...@@ -254,18 +269,35 @@ class MatrixBoxWidget(Widget.Widget):
#LOG("Cell",0,str(kw)) #LOG("Cell",0,str(kw))
attribute_value = my_field.get_value('default', cell = cell, attribute_value = my_field.get_value('default', cell = cell,
cell_index = kw, cell_position = (i,j, k)) cell_index = kw, cell_position = (i,j, k))
if render_format == 'list':
if not my_field.get_value('hidden'):
list_result_lines.append(attribute_value)
REQUEST['cell'] = cell REQUEST['cell'] = cell
cell_body += str(my_field.render(value = attribute_value, REQUEST = REQUEST, key = key)) cell_body += str(my_field.render(value = attribute_value, REQUEST = REQUEST, key = key))
list_body = list_body + \ list_body = list_body + \
('<td class=\"%s\">%s</td>' % (td_css, cell_body)) ('<td class=\"%s\">%s</td>' % (td_css, cell_body))
j += 1 j += 1
list_body = list_body + '</tr>' list_body = list_body + '</tr>'
i += 1 i += 1
if render_format == 'list':
list_result_tab.append(list_result_lines)
list_html += header + list_header + \ list_html += header + list_header + \
list_body + footer list_body + footer
k += 1 k += 1
if render_format == 'list':
list_result.append(list_result_tab)
if render_format == 'list':
return list_result
return list_html return list_html
MatrixBoxWidgetInstance = MatrixBoxWidget() MatrixBoxWidgetInstance = MatrixBoxWidget()
...@@ -349,6 +381,14 @@ class MatrixBox(ZMIField): ...@@ -349,6 +381,14 @@ class MatrixBox(ZMIField):
widget = MatrixBoxWidgetInstance widget = MatrixBoxWidgetInstance
validator = MatrixBoxValidatorInstance validator = MatrixBoxValidatorInstance
security = ClassSecurityInfo()
security.declareProtected('Access contents information', 'get_value')
def get_value(self, id, **kw):
if id == 'default' and kw.get('render_format') in ('list', ):
return self.widget.render(self, self.generate_field_key() , None , kw.get('REQUEST'), render_format=kw.get('render_format'))
else:
return ZMIField.get_value(self, id, **kw)
# Psyco # Psyco
import psyco import psyco
......
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