21.12.2022 Views

python_para_desenvolvedores_2ed

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MVC 189

def add(self):

"""

Cadastra novos registros

"""

# Gera a página de registro novo a partir do modelo "add.html"

return cherrytemplate.renderTemplate(file='add.html',

outputEncoding='utf-8')

@cherrypy.expose

def rem(self, ident):

"""

Confirma a remoção de registros

"""

# Seleciona o registro

sel = zoo.select(zoo.c.id==ident)

rec = sel.execute()

res = rec.fetchone()

# Gera a página de confirmar exclusão a partir do modelo "rem.html"

return cherrytemplate.renderTemplate(file='rem.html',

outputEncoding='utf-8')

@cherrypy.expose

def mod(self, ident):

"""

Modifica registros

"""

# Seleciona o registro

sel = zoo.select(zoo.c.id==ident)

rec = sel.execute()

res = rec.fetchone()

# Gera a página de alteração de registro a partir do modelo "mod.html"

return cherrytemplate.renderTemplate(file='mod.html',

outputEncoding='utf-8')

# Inicia o servidor na porta 8080

cherrypy.quickstart(Root())

Modelo “index.html” (página principal):

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!