class _RadioIndexHtmlElement(template.Element): loader = template.XMLFile( os.path.join(_template_path, 'index.template.xhtml')) def __init__(self, wcommon, title): self.__wcommon = wcommon self.__title = unicode(title) @template.renderer def title(self, request, tag): return tag(self.__title) @template.renderer def quoted_state_url(self, request, tag): return tag( json.dumps( self.__wcommon.make_websocket_url( request, _prepath_escaped(request) + 'radio'))) @template.renderer def quoted_audio_url(self, request, tag): return tag( json.dumps( self.__wcommon.make_websocket_url( request, _prepath_escaped(request) + 'audio')))
class UserPointsElement(template.Element): loader = template.XMLFile( util.sibpath(__file__, 'templates/pointslist.xhtml')) def __init__(self, highscore, display_name, points): template.Element.__init__(self) self.highscore = highscore self.display_name = display_name self.points = points @template.renderer def title(self, request, tag): return tag("Points for %s" % (self.display_name, )) @template.renderer def main_table(self, request, tag): ul = template.tags.ul() tag(ul, class_='points') for pt in self.points: li = template.tags.li() li( template.tags.span(time.asctime(time.gmtime(pt['when'])), class_="when")) li(" ") li(template.tags.span(str(pt['points']), class_="points")) li(" ") li(template.tags.span(pt['comments'], class_="comments")) ul(li) return ul
class _RadioIndexHtmlElement(template.Element): loader = template.XMLFile( os.path.join(template_path, 'index.template.xhtml')) def __init__(self, wcommon, title): super(_RadioIndexHtmlElement, self).__init__() self.__wcommon = wcommon self.__title = unicode(title) @template.renderer def title(self, request, tag): return tag(self.__title) @template.renderer def quoted_state_url(self, request, tag): return tag( serialize( self.__wcommon.make_websocket_url( request, prepath_escaped(request) + CAP_OBJECT_PATH_ELEMENT))) @template.renderer def quoted_audio_url(self, request, tag): return tag( serialize( self.__wcommon.make_websocket_url( request, prepath_escaped(request) + 'audio')))
class ErrorPageElement(template.Element): loader = template.XMLFile(template_filepath.child('error-page.template.xhtml')) def __init__(self, details_text): super(ErrorPageElement, self).__init__() self.__details_text = details_text @template.renderer def details_text(self, request, tag): return tag(self.__details_text)
class _RadioIndexHtmlElement(template.Element): loader = template.XMLFile( os.path.join(_templatePath, 'index.template.xhtml')) def __init__(self, title): self.__title = unicode(title) @template.renderer def title(self, request, tag): return tag(self.__title)
class _BlockHtmlElement(template.Element): ''' Template element for HTML page for an arbitrary block. ''' loader = template.XMLFile( os.path.join(_templatePath, 'block.template.xhtml')) @template.renderer def _block_url(self, request, tag): return tag( '/' + '/'.join([urllib.quote(x, safe='') for x in request.prepath]))
class _RadioIndexHtmlElement(EntryPointIndexElement): loader = template.XMLFile(template_filepath.child('index.template.xhtml')) @template.renderer def title(self, request, tag): return tag(self.entry_point_wcommon.title) @template.renderer def quoted_audio_url(self, request, tag): return tag( serialize( self.entry_point_wcommon.make_websocket_url( request, prepath_escaped(request) + 'audio')))
class _DbsIndexListElement(template.Element): loader = template.XMLFile( template_filepath.child('database-list.template.xhtml')) def __init__(self, dbs_resource): super(_DbsIndexListElement, self).__init__() self.__dbs_resource = dbs_resource @template.renderer def list_items(self, request, tag): for db_name in self.__dbs_resource.names: yield tag.clone().fillSlots(db_name=db_name, db_url='{}/'.format( urllib.quote(db_name, '')))
class _BlockHtmlElement(template.Element): """ Template element for HTML page for an arbitrary block. """ loader = template.XMLFile(os.path.join(template_path, 'block.template.xhtml')) def __init__(self, wcommon): self.__wcommon = wcommon @template.renderer def title(self, request, tag): return tag(request.prepath) @template.renderer def quoted_state_url(self, request, tag): return tag(serialize(self.__wcommon.make_websocket_url(request, prepath_escaped(request))))
class HighscoresElement(template.Element): loader = template.XMLFile( util.sibpath(__file__, 'templates/leaderboard.xhtml')) def __init__(self, highscore, scores, ltscores): template.Element.__init__(self) self.highscore = highscore self.scores = scores self.ltscores = ltscores @template.renderer def title(self, request, tag): return tag("High Scores") def getPostSuffix(self, pos): posDict = {1: 'st', 2: 'nd', 3: 'rd'} return posDict.get(pos, 'th') def getPosStr(self, position): return str(position) + self.getPostSuffix(position) def getClassCol(self, position): classDict = {1: 'first', 2: 'second', 3: 'third'} return classDict.get(position, 'others') def toHref(self, row): url = self.highscore.www.makeUrl('user', row['userid']) return template.tags.a(row['display_name'], class_="display_name", href=url) @template.renderer def monthly_header(self, request, tag): h3 = template.tags.h3('Monthly', class_='monthly') return h3 @template.renderer def career_header(self, request, tag): h3 = template.tags.h3(template.tags.b('Career'), class_='career') return h3 def getTableHeader(self): th_pos = template.tags.th('Pos.', class_='pos_col') th_name = template.tags.th('Name', class_='name_col') th_pts = template.tags.th('Points', class_='pts_col') tr = template.tags.tr(th_pos, th_name, th_pts, '') return tr @template.renderer def monthly_table(self, request, tag): position = 0 table = template.tags.table(width='100%') rowlist = [] rowlist.append(self.getTableHeader()) for sc in self.scores: position += 1 td_pos = template.tags.td(self.getPosStr(position), class_=self.getClassCol(position)) td_name = template.tags.td(self.toHref(sc), class_=self.getClassCol(position)) td_points = template.tags.td(str(sc['points']), class_=self.getClassCol(position)) if position <= 3: td_excl = template.tags.td( template.tags.i("!" * (4 - position))) else: td_excl = template.tags.td("") tr = template.tags.tr("\n", td_pos, td_name, td_points, td_excl) rowlist.append(tr) if position < 10: for j in range(11): if j > position: td_pos = template.tags.td(self.getPosStr(j), class_=self.getClassCol(j)) td_name = template.tags.td('empty', class_=self.getClassCol(j)) td_points = template.tags.td('0', class_=self.getClassCol(j)) td_excl = template.tags.td('') tr = template.tags.tr("\n", td_pos, td_name, td_points, td_excl) rowlist.append(tr) return template.tags.table(rowlist) @template.renderer def career_table(self, request, tag): position = 0 table = template.tags.table(width='100%') rowlist = [] rowlist.append(self.getTableHeader()) for sc in self.ltscores: position += 1 td_pos = template.tags.td(self.getPosStr(position), class_=self.getClassCol(position)) td_name = template.tags.td(self.toHref(sc), class_=self.getClassCol(position)) td_points = template.tags.td(str(sc['points']), class_=self.getClassCol(position)) if position <= 3: td_excl = template.tags.td( template.tags.i("!" * (4 - position))) else: td_excl = template.tags.td("") tr = template.tags.tr("\n", td_pos, td_name, td_points, td_excl) rowlist.append(tr) if position < 10: for j in range(11): if j > position: td_pos = template.tags.td(self.getPosStr(j), class_=self.getClassCol(j)) td_name = template.tags.td('empty', class_=self.getClassCol(j)) td_points = template.tags.td('0', class_=self.getClassCol(j)) td_excl = template.tags.td('') tr = template.tags.tr("\n", td_pos, td_name, td_points, td_excl) rowlist.append(tr) return template.tags.table(rowlist)