def index(self): basedirlen = len(config['torrent_dir']) dottorrentlen = len('.torrent') tpl = p.GetTemplate('torrentrow.html') totalupamt = 0 totaluprate = 0 totaldnamt = 0 totaldnrate = 0 rows = '' for (name, status, progress, peers, seeds, seedsmsg, dist, uprate, dnrate, upamt, dnamt, size, t, msg, path) in files: t = fmttime(t) if t: status = t progress = float(progress.replace('%', '')) # derive downloaded figure from percentage done so it's overall rather than just this session dnamt = (size / 100) * progress totalupamt += upamt totaluprate += uprate totaldnamt += dnamt totaldnrate += dnrate rows += renderTemplate(tpl) paused_tpl = p.GetTemplate('pausedrow.html') paused = '' try: dir_contents = os.listdir(config['paused_torrent_dir']) for f in dir_contents: if f.endswith('.torrent'): paused += renderTemplate(paused_tpl) except (IOError, OSError), e: pass
def mod(self, ident): #modifca os registros sel = zoo.select(zoo.c.id == ident) rec = sel.execute() res = rec.fetchone() return cherrytemplate.renderTemplate(file='mod.html', outputEncoding='utf-8')
def edit(self, id, **kwargs): self._kwargs(kwargs) game = Game.get(id) if kwargs: kwargs ['date'] = datetime.datetime(kwargs.pop('year'), kwargs.pop('month'), kwargs.pop('day')) game.set(**kwargs) return renderTemplate(file = 'html/edit_game.html')
def default(self, key, value): if key == 'id': coach = Coach.get(value) else: coach = eval('Coach.by%s(value)' % key.capitalize()) assert coach is not None return renderTemplate(file = 'html/view_coach.html')
def rem(self, ident): #confirma remocao dos dados sel = zoo.select(zoo.c.id == ident) rec = sel.execute() res = rec.fetchone() return cherrytemplate.renderTemplate(file='rem.html', outputEncoding='utf-8')
def _cpOnError(self): try: raise except cherrypy.NotFound: cherrypy.response.headerMap ['Status'] = '404 Not Found' cherrypy.response.body = ['<h1>Page Not Found</h1>'] except: cherrypy.response.body = renderTemplate(file = 'html/error.html')
def edit(self, id, **kwargs): self._kwargs(kwargs) if kwargs.has_key('password2'): assert kwargs ['password'] == kwargs.pop('password2'), 'Passwords do not match!' coach = Coach.get(id) if kwargs: coach.set(**kwargs) return renderTemplate(file = 'html/edit_coach.html')
def _wrapper(*args, **kwargs): global config if config['http_password'] == '': cpg.request.sessionMap['authenticated'] = 1 if cpg.request.sessionMap.has_key('authenticated'): return fn(*args, **kwargs) else: reason = '' submiturl = cpg.request.browserUrl try: pwd = kwargs['pwd'] except KeyError: return p.Get(renderTemplate(p.GetTemplate('login.html')), 'Authenticate') if pwd != config['http_password']: reason = 'Incorrect password' return p.Get(renderTemplate(p.GetTemplate('login.html')), 'Authenticate') cpg.request.sessionMap['authenticated'] = 1 return fn(*args, **kwargs)
def edit(self, id, player = None, changeName = False, **kwargs): self._kwargs(kwargs) team = Team.get(id) editPlayer = None if player: editPlayer = Player.get(player) if kwargs: skill = kwargs.pop('skill') if skill and editPlayer.eligibleSkill(Skill.get(skill)): editPlayer.addSkill(skill) editPlayer.set(**kwargs) editPlayer = None else: if kwargs: team.set(**kwargs) return renderTemplate(file = 'html/edit_team.html')
def stats(self): return renderTemplate(file = 'html/stats_coach.html')
def stats(self): return renderTemplate(file = 'html/stats_team.html')
def edit(self, id, **kwargs): self._kwargs(kwargs) season = Season.get(id) if kwargs: season.set(**kwargs) return renderTemplate(file = 'html/edit_season.html')
def default(self, key, value): if key == 'id': race = Race.get(value) else: race = eval('Race.by%s(value)' % key.capitalize()) return renderTemplate(file = 'html/view_race.html')
def index(self): return renderTemplate(file = 'html/league.html')
def add(self): #cadastra novos registros return cherrytemplate.renderTemplate(file='add.html', outputEncoding='utf-8')
class Root(object): @cherrypy.expose def index(self, **args): #lista os registros msg = '' op = args.get('op') ident = int(args.get('ident', 0)) novo = {} for coluna in colunas: novo[coluna] = args.get(coluna) if op == 'rem': rem = zoo.delete(zoo.c.id == ident) rem.execute() msg = 'registro removido' elif op == 'add': novo = {} for coluna in colunas: novo[coluna] = args[coluna] try: #insere dados ins = zoo.insert() ins.execute(novo) msg = 'registr adicionado' except sql.exceptions.IntegrityError: msg = 'registr existe' elif op == 'mod': novo = {} for coluna in colunas: novo[coluna] = args[coluna] try: #modifica dados mod = zoo.update(zoo.c.id == ident) mod.execute(novo) msg = 'registro modificado' except sql.exceptions.IntegrityError: msg = 'registro exite' sel = zoo.select(order_by=zoo.c.nome) rec = sel.execute() return cherrytemplate.renderTemplate(file='index.html', outputEncoding='utf-8') @cherrypy.expose def add(self): #cadastra novos registros return cherrytemplate.renderTemplate(file='add.html', outputEncoding='utf-8') @cherrypy.expose def rem(self, ident): #confirma remocao dos dados sel = zoo.select(zoo.c.id == ident) rec = sel.execute() res = rec.fetchone() return cherrytemplate.renderTemplate(file='rem.html', outputEncoding='utf-8') @cherrypy.expose def mod(self, ident): #modifca os registros sel = zoo.select(zoo.c.id == ident) rec = sel.execute() res = rec.fetchone() return cherrytemplate.renderTemplate(file='mod.html', outputEncoding='utf-8')
#!/usr/bin/python from cherrytemplate import renderTemplate progs = ['Yes', 'Genesis', 'King Crimsom'] template = '<html>\n<body>\n'\ '<py-for="prog in progs">'\ '<py-eval="prog"><br>\n'\ '</body>\n</html>\n' print renderTemplate(template)
def checkRes(res, expectedRes): if res != expectedRes: f = open('result', 'w') f.write("Result: " + repr(res) + "\n") f.close() f = open('result.raw', 'w') f.write(res) f.close() print "\nThe expected result was:\n%s and the real result was:\n%s\n*** ERROR ***" % ( repr(expectedRes), repr(res)) sys.exit(-1) print "OK" print "Testing CGTL...", name = "world" res = cherrytemplate.renderTemplate(file = 'testTags.html') checkRes(res, open('testTags.result', 'r').read()) print "Testing latin-1 template, latin-1 output (1)...", europoundUnicode = u'\x80\xa3' europoundLatin1 = europoundUnicode.encode('latin-1') res = cherrytemplate.renderTemplate(europoundLatin1 + """<py-eval="europoundLatin1">""") checkRes(res, europoundLatin1*2) print "Testing latin-1 template, latin-1 output (2)...", res = cherrytemplate.renderTemplate(europoundLatin1 + """<py-eval="europoundLatin1">""", inputEncoding = 'latin-1', outputEncoding = 'latin-1') checkRes(res, europoundLatin1*2) print "Testing latin-1 template, utf-16 output...", res = cherrytemplate.renderTemplate(europoundLatin1 + """<py-eval="europoundLatin1">""", inputEncoding = 'latin-1', outputEncoding = 'utf-16')
def Get(self, body, pagetitle = None): title = defaulttitle loggedin = cpg.request.sessionMap.has_key('authenticated') if pagetitle: title = title + ' :: ' + pagetitle return renderTemplate(template = self.header() + body + self.footer())
def admin(self): teams = Team.select() return renderTemplate(file = 'html/admin_medal.html')
def index(self, **args): return cherrytemplate.renderTemplate(form)
def admin(self): seasons = Season.select() return renderTemplate(file = 'html/admin_season.html')
def index(self): return renderTemplate(file = 'html/front.html')
def default(self, key, value): if key == 'id': season = Season.get(value) else: season = eval('Season.by%s(value)' % key.capitalize()) return renderTemplate(file = 'html/view_season.html')
def index(self): return renderTemplate(file = 'html/admin.html')
def default(self, key, value): if key == 'id': team = Team.get(value) else: team = eval('Team.by%s(value)' % key.capitalize()) return renderTemplate(file = 'html/view_team.html')
def admin(self): coaches = Coach.select() return renderTemplate(file = 'html/admin_coach.html')
if res != expectedRes: f = open('result', 'w') f.write("Result: " + repr(res) + "\n") f.close() f = open('result.raw', 'w') f.write(res) f.close() print "\nThe expected result was:\n%s and the real result was:\n%s\n*** ERROR ***" % ( repr(expectedRes), repr(res)) sys.exit(-1) print "OK" print "Testing CGTL...", name = "world" res = cherrytemplate.renderTemplate(file='testTags.html') checkRes(res, open('testTags.result', 'r').read()) print "Testing latin-1 template, latin-1 output (1)...", europoundUnicode = u'\x80\xa3' europoundLatin1 = europoundUnicode.encode('latin-1') res = cherrytemplate.renderTemplate(europoundLatin1 + """<py-eval="europoundLatin1">""") checkRes(res, europoundLatin1 * 2) print "Testing latin-1 template, latin-1 output (2)...", res = cherrytemplate.renderTemplate(europoundLatin1 + """<py-eval="europoundLatin1">""", inputEncoding='latin-1', outputEncoding='latin-1')
def render(template_name, **kwargs): """ A helper method to render templates """ if not kwargs.has_key('msg_error'): kwargs['msg_error'] = '' kwargs['template_file'] = 'templates/%s.html'%template_name return renderTemplate(file='templates/skel.html', loc=kwargs)