On 2/25/06, BJörn Lindqvist <[EMAIL PROTECTED]> wrote:
> Where getset is this exposed method:
>
> @turbogears.expose(format = "json")
> def getset(self, tablename, rowid, colname, value = None):
> table = getattr(model, tablename)
> row = table.get(int(rowid))
> if value:
> setattr(row, colname, value)
> else:
> return dict(value = getattr(row, colname))
>
> This is better because now the getset method is more generic and can
> handle all SQLObject's inside the 'model' module. Still, it is a bad
> solution because
>
> 1. The getset() method contains stupid getattr tricks.
> 2. The getset() method is detached from the InstantTextField
> class. This makes my InstantTextField hard to reuse.
#1 is, imho, not really stupid. It's a standard and useful part of
Python. This seems like exactly the way to make such a thing generic.
As for #2, InstantTextField is actually *more* reusable. It can be
made to implement any kind of behavior, just depending on the
information sent to the controller and what the controller does with
it. That's the view of widgets being the "view" layer and not
incorporating controller logic.
> #1 can be solved my having the getset() method inside the
> InstantTextField class where it belongs. But then the method has to be
> mounted, and methods can't be mounted inside turbogears widgets. If
> the widgets had worked more like normal GUI widgets I could have
> written something like this:
But the web is not a normal GUI. A normal GUI is stateful and the web
is stateless. I think it's dangerous to develop web apps and
particularly web components that ignore the fact that the web is
stateless. In your example below, that InstantTextField (and the
reference to the database row!) would have to hang around on the
server until the user changes the data. In fact, it would have to hang
around after that, because the user could change it again. How would
you know when it could go away? Would it have a timeout?
> class InstantTextField(gtk.Entry):
> def on_changed(self, *args):
> """Updates the db"""
> setattr(self.row, self.colname, self.get_text())
>
> def __init__(self, row, colname):
> super(InstantTextField, self).__init__()
> self.row, self.colname = row, colname
> # Get initial field value from db
> self.set_text(getattr(row, colname))
> self.connect("changed", self.on_changed)
In a GUI you can do things like the above. But, on the web, it's
dangerous (for your server) to try to make it work like that.
Kevin
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---