Function can take the row object as an argument. That way it can access all
of the data regarding that row that is about to be inserted, if it needs
information from other parts of the database, just use a db.select() inside
said function.
Just throwing some pseudocode out there..
def afunction(row):
print row.title, row.permalink, row.content
count = db().count(db.row)
print count
.........
for func in self.after_update:
func(self)
-Thadeus
On Tue, Nov 3, 2009 at 4:04 PM, Jon Romero <[email protected]> wrote:
>
> I was misunderstood (my mistake - it's getting late here in Greece). I
> didn't want to say about the list but about taking an argument.
> > after_update should be a list of functions, that take one argument, the
> row.
>
> Now that I am thinking about it, I think that these functions must
> have access to table data.
> For example, creating permalinks after a title field has been updated,
> means that a create_permalink function must have access
> to the db.table.title and to the db.table.permalink. The thing is that
> I am making changes inside the update function (in sql.py) - after the
>
> self._db._execute(query)
>
> but I don't believe I have access to table's data.
> Am I doing something wrong here? Should I patch somewhere else (first
> time reading the sql.py)?
>
> On Nov 3, 11:48 pm, Thadeus Burgess <[email protected]> wrote:
> > A list is a list, doesn't matter if your setting it to a new list or
> using
> > the list.append() afterwords, it will work the same.
> >
> > db.table.field.after_update = []
> >
> > db.table.field.after_update = [lambda row: print row]
> >
> > db.table.field.after_update.append(lambda row: del row)
> >
> > -Thadeus
> >
> > On Tue, Nov 3, 2009 at 3:37 PM, Jon Romero <[email protected]> wrote:
> >
> > > ok, I hacked an after_update attribute in sql.py but I am doing this:
> >
> > > db.table.field.after_update = a_list_with_functions
> >
> > > I think it feels more natural. What do you guys think?
> >
> > > On Nov 3, 10:58 pm, Thadeus Burgess <[email protected]> wrote:
> > > > after_update should be a list of functions, that take one argument,
> the
> > > row.
> >
> > > > db.table.field.after_update.append(lambda row: print row)
> >
> > > > -Thadeus
> >
> > > > On Tue, Nov 3, 2009 at 2:56 PM, Jon Romero <[email protected]>
> wrote:
> >
> > > > > Is it possible to do something like that in the db declarations or
> I
> > > > > have to put code inside the controller?
> > > > > For example in Rails you specify functions that will run before or
> > > > > after an insert/update/delete/select inside the declaration of
> model.
> > > > > That makes the code very easy to read/reuse.
> >
> > > > > I think that it is easy to do this in web2py if you put something
> like
> > > > > that:
> > > > > db.table_name.table_field.after_update = function_do_something
> >
> > > > > Any ideas?
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---