Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
 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')
Ejemplo n.º 3
0
	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')
Ejemplo n.º 4
0
	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')
Ejemplo n.º 5
0
 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')
Ejemplo n.º 6
0
	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')
Ejemplo n.º 7
0
	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')
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
	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')
Ejemplo n.º 10
0
	def stats(self):
		return renderTemplate(file = 'html/stats_coach.html')
Ejemplo n.º 11
0
	def stats(self):
		return renderTemplate(file = 'html/stats_team.html')
Ejemplo n.º 12
0
	def edit(self, id, **kwargs):
		self._kwargs(kwargs)
		season = Season.get(id)
		if kwargs:
			season.set(**kwargs)
		return renderTemplate(file = 'html/edit_season.html')
Ejemplo n.º 13
0
	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')
Ejemplo n.º 14
0
	def index(self):
		return renderTemplate(file = 'html/league.html')
Ejemplo n.º 15
0
 def add(self):
     #cadastra novos registros
     return cherrytemplate.renderTemplate(file='add.html',
                                          outputEncoding='utf-8')
Ejemplo n.º 16
0
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')
Ejemplo n.º 17
0
#!/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)
Ejemplo n.º 18
0
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')
Ejemplo n.º 19
0
 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())
Ejemplo n.º 20
0
	def admin(self):
		teams = Team.select()
		return renderTemplate(file = 'html/admin_medal.html')
Ejemplo n.º 21
0
 def index(self, **args):
     return cherrytemplate.renderTemplate(form)
Ejemplo n.º 22
0
	def admin(self):
		seasons = Season.select()
		return renderTemplate(file = 'html/admin_season.html')
Ejemplo n.º 23
0
	def index(self):
		return renderTemplate(file = 'html/front.html')
Ejemplo n.º 24
0
	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')
Ejemplo n.º 25
0
	def index(self):
		return renderTemplate(file = 'html/admin.html')
Ejemplo n.º 26
0
	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')
Ejemplo n.º 27
0
	def admin(self):
		coaches = Coach.select()
		return renderTemplate(file = 'html/admin_coach.html')
Ejemplo n.º 28
0
    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')
Ejemplo n.º 29
0
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)