comparison py/rlgalldb.py @ 31:7303535b5a5d

Right-align the numeric columns. The Game.printTable() method now right-aligns the name, rank, and score columns, by giving their cells a different CSS class.
author John "Elwin" Edwards
date Thu, 02 Jan 2014 11:39:57 -0500
parents e8f3b7994d88
children
comparison
equal deleted inserted replaced
30:e8f3b7994d88 31:7303535b5a5d
37 secthead = '<h3>{0}</h3>\n' 37 secthead = '<h3>{0}</h3>\n'
38 tblhead = '<div class="stable">\n' 38 tblhead = '<div class="stable">\n'
39 rowstart = '<div class="sentry">\n' 39 rowstart = '<div class="sentry">\n'
40 rowend = '</div>\n' 40 rowend = '</div>\n'
41 cell = ' <span class="sdata">{0}</span>\n' 41 cell = ' <span class="sdata">{0}</span>\n'
42 rcell = ' <span class="sdatar">{0}</span>\n'
42 hcell = ' <span class="shdata">{0}</span>\n' 43 hcell = ' <span class="shdata">{0}</span>\n'
43 tblend = '</div>\n' 44 tblend = '</div>\n'
44 pend = "</body></html>\n" 45 pend = "</body></html>\n"
45 46
46 # This would be more useful if we had to do translation 47 # This would be more useful if we had to do translation
110 rnum = 0 111 rnum = 0
111 for i, entry in enumerate(entries): 112 for i, entry in enumerate(entries):
112 clist = [] 113 clist = []
113 for field in fields: 114 for field in fields:
114 if field == "rank": 115 if field == "rank":
115 clist.append("{0}".format(i + 1)) 116 clist.append(("{0}".format(i + 1), rcell))
116 elif field in entry: 117 elif field in entry:
117 thing = entry[field] 118 thing = entry[field]
118 if field == "game": 119 if field == "game":
119 clist.append(thing.name) 120 clist.append((thing.name, cell))
120 elif field == "xl" or field == "score": # Numerics 121 elif field == "xl" or field == "score": # Numerics
121 clist.append(str(thing)) 122 clist.append((str(thing), rcell))
122 elif field == "name": 123 elif field == "name":
123 clist.append(playerlink(thing)) 124 clist.append((playerlink(thing), cell))
124 elif field == "fate": 125 elif field == "fate":
125 clist.append(thing) 126 clist.append((thing, cell))
126 elif field == "endt": 127 elif field == "endt":
127 clist.append(linktoArchive(entry)) 128 clist.append((linktoArchive(entry), cell))
128 else: 129 else:
129 clist.append("{0}".format(thing)) 130 clist.append(("{0}".format(thing), cell))
130 else: 131 else:
131 clist.append("N/A") 132 clist.append(("N/A", cell))
132 of.write(maketablerow(clist)) 133 rowstr = rowstart + "".join([ t.format(s) for (s, t) in clist ]) + rowend
134 of.write(rowstr)
133 of.write(tblend) 135 of.write(tblend)
134 return 136 return
135 137
136 class Game: 138 class Game:
137 def __init__(self, name, uname): 139 def __init__(self, name, uname):