reportlab/platypus/tables.py
changeset 2589 1af821ded9f1
parent 2582 4a008286f3dc
child 2590 deaa612ecb4c
equal deleted inserted replaced
2588:ea348c8bdef1 2589:1af821ded9f1
   236                 Spacer.__init__(self,0,0)
   236                 Spacer.__init__(self,0,0)
   237             else:
   237             else:
   238                 raise ValueError, '%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction)
   238                 raise ValueError, '%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction)
   239             return
   239             return
   240 
   240 
   241         self._cellvalues = data
   241         # we need a cleanup pass to ensure data is strings - non-unicode and non-null
       
   242         self._cellvalues = self.normalizeData(data)
   242         if not _seqCW: colWidths = ncols*[colWidths]
   243         if not _seqCW: colWidths = ncols*[colWidths]
   243         elif len(colWidths) != ncols:
   244         elif len(colWidths) != ncols:
   244             raise ValueError, "%s data error - %d columns in data but %d in grid" % (self.identity(),ncols, len(colWidths))
   245             raise ValueError, "%s data error - %d columns in data but %d in grid" % (self.identity(),ncols, len(colWidths))
   245         if not _seqRH: rowHeights = nrows*[rowHeights]
   246         if not _seqRH: rowHeights = nrows*[rowHeights]
   246         elif len(rowHeights) != nrows:
   247         elif len(rowHeights) != nrows:
   274         cv = getattr(self,'_cellvalues','[unknown]')
   275         cv = getattr(self,'_cellvalues','[unknown]')
   275         import pprint, string
   276         import pprint, string
   276         cv = pprint.pformat(cv)
   277         cv = pprint.pformat(cv)
   277         cv = string.replace(cv, "\n", "\n  ")
   278         cv = string.replace(cv, "\n", "\n  ")
   278         return "%s(\n rowHeights=%s,\n colWidths=%s,\n%s\n) # end table" % (self.__class__.__name__,r,c,cv)
   279         return "%s(\n rowHeights=%s,\n colWidths=%s,\n%s\n) # end table" % (self.__class__.__name__,r,c,cv)
       
   280 
       
   281     def normalizeData(self, data):
       
   282         """Takes a block of input data (list of lists etc.) and
       
   283         - coerces to non-unicode UTF8
       
   284         - accepts nulls
       
   285         
       
   286         """
       
   287         def normCell(stuff):
       
   288             if stuff is None:
       
   289                 return ''
       
   290             elif type(stuff) == type(u''):
       
   291                 return stuff.encode('utf8')
       
   292             else:
       
   293                 return stuff
       
   294         outData = []
       
   295         for row in data:
       
   296             outRow = [normCell(cell) for cell in row]
       
   297             outData.append(outRow)
       
   298         from pprint import pprint as pp
       
   299         #pp(outData)
       
   300         return outData
       
   301 
       
   302 
   279 
   303 
   280     def identity(self, maxLen=30):
   304     def identity(self, maxLen=30):
   281         '''Identify our selves as well as possible'''
   305         '''Identify our selves as well as possible'''
   282         if self.ident: return self.ident
   306         if self.ident: return self.ident
   283         vx = None
   307         vx = None