On 8/29/06, Lee McFadden <[EMAIL PROTECTED]> wrote:
> consumo=TextField(label="Consumo", validator=validators.Int())
No, all the pertinent methods are classmethods, so they work with or
without instantiation. I cannot reproduce on 0.9a8.
########################## model.py
from sqlobject import *
from turbogears.database import PackageHub
hub = PackageHub("tgtest")
__connection__ = hub
class Lectura(SQLObject):
consumo = IntCol(default=0)
######################## controllers.py
import turbogears
from turbogears import controllers, expose, validate, redirect, error_handler
from turbogears import widgets as W
from turbogears import validators as v
from tgtest.model import Lectura
class MyCampos(W.WidgetsList):
id = W.HiddenField(validator=v.Int)
consumo = W.TextField(label="Consumo",validator=v.Int)
campos_form = W.ListForm(fields = MyCampos())
class Root(controllers.RootController):
@expose(template="tgtest.templates.welcome")
def index(self):
return dict(form=campos_form,data={'id':1},action='/grabarMod')
@expose()
@error_handler(index)
@validate(form=campos_form)
def grabarMod(self,**datos):
id=datos.get('id',None)
if id:
lectura = Lectura.get(id)
lectura.consumo = datos.get('consumo',0)
turbogears.flash('good')
else:
turbogears.flash('bad')
turbogears.redirect('/')
############################## templates/welcome.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>Welcome to TurboGears</title>
</head>
<body>
${form(value_of('data',None), action=action, method='POST')}
</body>
</html>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---