Editace 2

Soubor controlers.py

from turbogears import controllers, expose, flash
from turbogears import redirect
from turbogears import validate, widgets, validators, error_handler
 
from foto import model
from model import Fotografie
 
from turbogears.toolbox.catwalk import CatWalk
 
import logging
log = logging.getLogger("foto.controllers")
 
class Policka(widgets.WidgetsList):
    nazev = widgets.TextField(validator=validators.NotEmpty)
    soubor = widgets.TextField(validator=validators.NotEmpty)
    # stejna jmena policek jako v databazi
 
formular = widgets.TableForm ( fields=Policka(),
                               submit_text="Ulozit" )
 
class Root(controllers.RootController):
 
    catwalk = CatWalk(model)
 
    @expose(template="foto.templates.uvod")
    def index(self):
        import time
        log.debug("*** Nekdo navstivil fologalerii ***")
        flash("Fotografie, verze 01")
        return dict(current_time=time.ctime())
 
    @expose(template="foto.templates.obsah")
    def obsah(self):
        # seznam fotografii
        return dict (snimky=Fotografie.select ())
 
    @expose(template="foto.templates.add")
    def add(self):
        # formular pro vlozeni nove radky
        return dict ()
 
    @expose()
    def insert(self, param_nazev, param_soubor):
        # vlozeni nove radky
        Fotografie (nazev=param_nazev, soubor=param_soubor)
        raise redirect ("/obsah");
 
    @expose(template="foto.templates.edit")
    def edit(self, id):
        # formular pro editovani radky
        return dict (snimek=Fotografie.get(id))
 
    @expose()
    def store(self, **args):
        # editovani udaju v databazi
        param_id=args["param_id"]
        param_nazev=args["param_nazev"]
        param_soubor=args["param_soubor"]
        snimek=Fotografie.get(param_id)
        snimek.nazev = param_nazev
        snimek.soubor = param_soubor
        raise redirect ("/obsah");
 
    @expose(template="foto.templates.modify")
    def modify(self, id):
        # formular pro editovani radky
        snimek=Fotografie.get(id)
        cilova_adresa="/update/" + str(id)
        # nezpomenout lomitko na zacatku
        return dict(okno=formular,
                    hodnoty=snimek,
                    cil=cilova_adresa)
 
    @expose()
    @error_handler(modify)
    @validate(form=formular)
    def update(self, id, **args):
        # editovani udaju v databazi
        print 'update: id=', id, 'args=', args
        from sqlobject import SQLObjectNotFound
        try:
            snimek=Fotografie.get(id)
            snimek.set(**args) 
        except SQLObjectNotFound:
            Fotografie(**args)
        raise redirect("/obsah")

Soubor template/modify.kid

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py:extends="'master.kid'">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
<title>Fotografie - uvod</title>
</head>
<body>
 
      ${ okno (value=hodnoty, action=cil) }
 
</body>
</html>

Soubor template/obsah.kid

        <TD> <A HREF='modify/${obrazek.id}'> editace </A> </TD>
 
turbogears4.txt · Last modified: 2008/04/24 13:42 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki