> I don't know much about TurboGears' widgets, I focus mainly on Ajax
> applications and I have my own Javascript API that I use, however,
> this is really a simple MVC problem.
>
> Your GTK example actually breaks MVC for no particular reason.

The particular reason is that it is the most straight forward way to
write what I'm trying to express.

> The way I would handle this in a MVC-compliant way is to create a
> specific controller just for the data I'm modifying. Let's call it
> the KeyValueController. It might be defined like this:

[snip]

> You could then drop this into your main controller as follows:
>
> class MyController(Controller):
>      person= KeyValueController( TG_User,
> "myproject.templates.all_people",
>                                  "myproject.templates.edit_person" )

I assume "person" is now a KeyValueController for a certain table?
This is the approach I myself have been able to figure out. But I
don't like it. What if I want more controllers than one? What if I
can't know what table the KeyValueController should control before an
exposed method is called? The answer is that you have to generalize
your controller so that it accepts any table, fieldid and column name.
Like this:

class CellController(Controller):
    def __init__(self, tablestore):
        super(CellController, self).__init__()
        self.tablestore = tablestore

    def getrow(self, tablename, rowid):
        table = getattr(self.tablestore, tablename)
        return table.get(int(rowid))

    def set(self, tablename, rowid, colname, value):
        row = self.getrow(tablename, rowid)
        setattr(row, colname, value)

    def get(self, tablename, rowid, colname):
        row = self.getrow(tablename, rowid)
        return dict(value = getattr(row, colname))

    @turbogears.expose(format = "json")
    def default(self, *vpath, **params):
        tablename, rowid, colname = vpath
        if params.has_key("value"):
            return self.set(tablename, rowid, colname, params["value"])
        else:
            return self.get(tablename, rowid, colname)

class Root(RootController):
    cell_controller = CellController(model)

    @turbogears.expose(template="foobar.templates.welcome")
    def index(self):
        tfield1 = InstantTextField(name = "tfield1",
                                   controller = "cell_controller",
                                   celldesc = ("Person", "1", "name"))
        return dict(textfield = tfield1)

Here you have to feed a textual reference to a table row to the
InstantTextField widget ("Person", "1", "name") instead of
Person.get(1), "name". The controlling methods (callbacks) get and set
have to take the textual name, row id and column name and convert that
to a sqlrow object before they can do their manipulations. Compare how
complicated this method is compared to how simple it would be if you
could store the sqlrow instance inside the InstantTextField object.

> Of course, you _could_ do that. Or you could simply use the
> AjaxDataController that's built into TurboGears. You'll have to send
> your data back and forth encoded as JSON, but that's no big deal.
> Javascript works a treat with JSON data.

> The advantage to using AjaxDataController (besides making me feel
> better) is that it handles most errors you're likely to encounter
> _and_ you can create and delete whole objects. You can also update
> more than just one attribute at a time, because you're sending a JSON
> formatted object back to the server.

It isn't very obvious how you are supposed to use the
AjaxDataController. It seems like some of its exposed methods are
capable of taking SQLObject instances as its input. If that is the
case, then it would solve some of my concerns. And similar to your
previous example, the AjaxDataController is the controller of only one
sql_class. If you are creating something similar to CatWalk, you
wouldn't be able to use that controller.

--
mvh Björn

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to