Added a new system for layouting production-ready forms without any HTML coding, many performance improvements and more independence towards Archetypes.

This commit is contained in:
Gaetan Delannay 2010-08-05 18:23:17 +02:00
parent 309ea921fa
commit bfd2357f69
84 changed files with 4663 additions and 3549 deletions

View file

@ -18,7 +18,7 @@ mimeTypesExts = {
'image/jpeg' : 'jpg',
'image/gif' : 'gif'
}
xmlPrologue = '<?xml version="1.0" encoding="utf-8"?>'
xmlPrologue = '<?xml version="1.0" encoding="utf-8"?>\n'
# ------------------------------------------------------------------------------
class UnmarshalledObject:

58
shared/odf.py Normal file
View file

@ -0,0 +1,58 @@
'''This module contains some useful classes for constructing ODF documents
programmatically.'''
# ------------------------------------------------------------------------------
class OdtTable:
'''This class allows to construct an ODT table programmatically.'''
# Some namespace definitions
tns = 'table:'
txns = 'text:'
def __init__(self, tableName, paraStyle, cellStyle,
paraHeaderStyle, cellHeaderStyle, nbOfCols):
self.tableName = tableName
self.paraStyle = paraStyle
self.cellStyle = cellStyle
self.paraHeaderStyle = paraHeaderStyle
self.cellHeaderStyle = cellHeaderStyle
self.nbOfCols = nbOfCols
self.res = ''
def dumpCell(self, content, span=1, header=False):
if header:
paraStyleName = self.paraHeaderStyle
cellStyleName = self.cellHeaderStyle
else:
paraStyleName = self.paraStyle
cellStyleName = self.cellStyle
self.res += '<%stable-cell %sstyle-name="%s" ' \
'%snumber-columns-spanned="%d">' % \
(self.tns, self.tns, cellStyleName, self.tns, span)
self.res += '<%sp %sstyle-name="%s">%s</%sp>' % \
(self.txns, self.txns, paraStyleName, content, self.txns)
self.res += '</%stable-cell>' % self.tns
def startRow(self):
self.res += '<%stable-row>' % self.tns
def endRow(self):
self.res += '</%stable-row>' % self.tns
def startTable(self):
self.res += '<%stable %sname="AnalysisTable">' % (self.tns, self.tns)
self.res += '<%stable-column %snumber-columns-repeated="%d"/>' % \
(self.tns, self.tns, self.nbOfCols)
def endTable(self):
self.res += '</%stable>' % self.tns
def dumpFloat(self, number):
return str(round(number, 2))
def get(self):
'''Returns the whole table.'''
self.startTable()
self.getRows()
self.endTable()
return self.res.decode('utf-8')
# ------------------------------------------------------------------------------

View file

@ -526,8 +526,7 @@ class XmlMarshaller:
mustDump = True
if mustDump:
self.dumpField(res, fieldName, fieldValue)
elif objectType in ('archetype', 'appy'):
fields = instance.schema.fields()
elif objectType == 'archetype':
for field in instance.schema.fields():
# Dump only needed fields
mustDump = False
@ -550,18 +549,32 @@ class XmlMarshaller:
fieldType = 'ref'
self.dumpField(res, field.getName(),field.get(instance),
fieldType=fieldType)
if objectType == 'appy':
# Dump the object history.
res.write('<history type="list">')
wfInfo = instance.portal_workflow.getWorkflowsFor(instance)
if wfInfo:
history = instance.workflow_history[wfInfo[0].id]
for event in history:
res.write('<event type="object">')
for k, v in event.iteritems():
self.dumpField(res, k, v)
res.write('</event>')
res.write('</history>')
elif objectType == 'appy':
for field in instance.getAllAppyTypes():
# Dump only needed fields
if field.name in self.fieldsToExclude: continue
if (field.type == 'Ref') and field.isBack: continue
if (type(self.fieldsToMarshall) in self.sequenceTypes) \
and (field.name not in self.fieldsToMarshall): continue
# Determine field type
fieldType = 'basic'
if field.type == 'File':
fieldType = 'file'
elif field.type == 'Ref':
fieldType = 'ref'
self.dumpField(res, field.name,field.getValue(instance),
fieldType=fieldType)
# Dump the object history.
res.write('<history type="list">')
wfInfo = instance.portal_workflow.getWorkflowsFor(instance)
if wfInfo:
history = instance.workflow_history[wfInfo[0].id]
for event in history:
res.write('<event type="object">')
for k, v in event.iteritems():
self.dumpField(res, k, v)
res.write('</event>')
res.write('</history>')
self.marshallSpecificElements(instance, res)
res.write('</'); res.write(self.rootElementName); res.write('>')
else: