Changeset 91:f8cc09945b2b
- Timestamp:
- 01/16/09 03:11:00 (20 months ago)
- Branch:
- default
- Files:
-
- 1 modified
-
relatorio/templates/opendocument.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
relatorio/templates/opendocument.py
r90 r91 26 26 import zipfile 27 27 from cStringIO import StringIO 28 from copy import deepcopy 29 28 30 29 31 import warnings … … 94 96 return {'{http://www.w3.org/1999/xlink}href': path} 95 97 98 class TableColumnDef: 99 """A class used to add the correct number of column definitions to a 100 table containing an horizontal repetition" 101 """ 102 def __init__(self, zfile, context): 103 self.zip = zfile 104 self.context = context.copy() 105 106 def __call__(self, expr, name): 107 #FIXME: name argument is unused 108 return 96 109 97 110 class Template(MarkupTemplate): … … 207 220 else: 208 221 closing_tags[id(opened_tags.pop())] = statement 209 # - we o perate only on opening statements222 # - we only need to return opening statements 210 223 if is_opening: 211 224 r_statements.append((statement, … … 213 226 ) 214 227 assert not opened_tags 215 216 228 return r_statements, closing_tags 217 229 … … 221 233 tags 222 234 """ 223 # Some tag name constants235 # Some tag/attribute name constants 224 236 table_cell_tag = '{%s}table-cell' % self.namespaces['table'] 237 table_row_tag = '{%s}table-row' % self.namespaces['table'] 238 num_col_attr = '{%s}number-columns-repeated' % self.namespaces['table'] 225 239 attrib_name = '{%s}attrs' % self.namespaces['py'] 226 240 office_name = '{%s}value' % self.namespaces['office'] 227 241 office_valuetype = '{%s}value-type' % self.namespaces['office'] 228 genshi_replace = '{%s}replace' % self.namespaces['py'] 242 py_namespace = self.namespaces['py'] 243 genshi_replace = '{%s}replace' % py_namespace 229 244 230 245 r_statements, closing_tags = self._relatorio_statements(tree) … … 235 250 # If the node is a genshi directive statement: 236 251 if directive is not None: 237 238 252 opening = r_node 239 253 closing = closing_tags[id(r_node)] … … 248 262 idx = c_ancestors.index(node) 249 263 assert c_ancestors[idx] == node 264 # we only need ancestors up to the common one 250 265 del c_ancestors[idx:] 251 266 ancestor = node … … 257 272 "No common ancestor found for opening and closing tag" 258 273 274 # handle horizontal repetition (over columns) 275 if False: 276 #if directive == "for" and ancestor.tag == table_row_tag: 277 print "horizontal repetition", a_val 278 # find position of current cell in row 279 position_xpath_expr = \ 280 'count(ancestor::table:table-cell/preceding-sibling::*)' 281 opening_pos = opening.xpath(position_xpath_expr, 282 namespaces=self.namespaces) 283 closing_pos = closing.xpath(position_xpath_expr, 284 namespaces=self.namespaces) 285 print "opening_pos", opening_pos 286 print "closing_pos", closing_pos 287 288 idx = 0 289 table_node = opening.xpath('ancestor::table:table[1]', 290 namespaces=self.namespaces)[0] 291 #XXX: use getiterator('table:table-column') instead of xpath? 292 to_split = [] 293 to_move = [] 294 for tag in table_node.xpath('table:table-column', 295 namespaces=self.namespaces): 296 if num_col_attr in tag.attrib: 297 oldidx = idx 298 idx += int(tag.attrib[num_col_attr]) 299 print "oldidx", oldidx, "idx", idx 300 if oldidx < opening_pos < idx or \ 301 oldidx < closing_pos < idx: 302 to_split.append(tag) 303 print "to_split", to_split 304 else: 305 idx += 1 306 307 # split tags 308 for tag in to_split: 309 tag_pos = table_node.index(tag) 310 print "tag_pos", tag_pos 311 num = int(tag.attrib[num_col_attr]) 312 tag.attrib.pop(num_col_attr) 313 new_tags = [deepcopy(tag) for _ in range(num)] 314 table_node[tag_pos:tag_pos] = new_tags 315 316 # compute moves 317 if False: 318 if idx < opening_pos: 319 pass 320 elif opening_pos < idx < closing_pos: 321 to_move.append(tag) 322 else: 323 break 324 print idx 325 # move tags 326 # 327 # add a <py:for each="%s"> % a_val 328 # for_node = EtreeElement('{%s}%s' % (py_namespace, 'for'), 329 # attrib={attr: a_val}, 330 # nsmap=self.namespaces) 331 259 332 # - we create a <py:xxx> node 260 genshi_node = EtreeElement('{%s}%s' % ( self.namespaces['py'],333 genshi_node = EtreeElement('{%s}%s' % (py_namespace, 261 334 directive), 262 335 attrib={attr: a_val},
