' % h)
while True:
if i == n:
break
cell = row[i]
css_classes = []
cell_str = cell # by default, we don't touch it
if schema.ColumnIndexIsInteger(i):
css_classes.append('num') # right justify
try:
cell_int = int(cell)
except ValueError:
pass # NA?
else:
# commas AND floating point
cell_str = '{:,}'.format(cell_int)
# Look up by index now?
elif schema.ColumnIndexIsNumeric(i):
css_classes.append('num') # right justify
try:
cell_float = float(cell)
except ValueError:
pass # NA
else:
# Floats can also be timestamps
fmt = schema.ColumnStrftime(i)
if fmt not in ('-', ''):
from datetime import datetime
t = datetime.fromtimestamp(cell_float)
if fmt == 'iso':
cell_str = t.isoformat()
else:
cell_str = t.strftime(fmt)
else:
# commas AND floating point to a given precision
# default precision is 1
precision = schema.ColumnPrecision(i)
cell_str = '{0:,.{precision}f}'.format(cell_float, precision=precision)
# Percentage
#cell_str = '{:.1f}%'.format(cell_float * 100)
# Special CSS class for R NA values.
if cell.strip() == 'NA':
css_classes.append('na') # make it red
if css_classes:
print(' | '.format(' '.join(css_classes)), end=' ')
else:
print(' | ', end=' ')
s = html.escape(cell_str)
# If it's an _HREF, advance to the next column, and mutate 's'.
if schema.ColumnIndexHasHref(i):
i += 1
href = row[i]
if href:
s = '%s' % (html.escape(href), html.escape(cell_str))
print(s, end=' ')
print(' | ')
i += 1
print('
')
def PrintColGroup(col_names, schema):
"""Print HTML colgroup element, used for JavaScript sorting."""
print('