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.

188 MVC

# Remove dados

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 = 'registro adicionado.'

except sql.exceptions.IntegrityError:

msg = 'registro 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 existe.'

# Seleciona dados

sel = zoo.select(order_by=zoo.c.nome)

rec = sel.execute()

# Gera a página principal a partir do modelo "index.html"

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

outputEncoding='utf-8')

@cherrypy.expose

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

Saved successfully!

Ooh no, something went wrong!