auth.add_group() actually does a database insert, so you don't want to keep 
repeating it on every request (actually, I would probably move that code 
out of the app altogether, as it really only needs to be run once ever).

Specifying the after update callback, on the other hand, does not affect 
the database at all -- it simply tells the DAL what to do after a database 
update. In fact, you need this to run on every request because it is part 
of the model definition (for the same reason you need to run the associated 
db.define_table() on every request).

Anthony

On Wednesday, July 29, 2015 at 10:59:59 PM UTC-4, Thomas Sitter wrote:
>
> Hello,
>
> I'm adding an _after_update callback to my table in db.py using:
>
> def myfunc(s,f):
>   #do stuff
>   return False
>
> db.tt._after_update.append(myfunc)
>
> My question is whether this will continuously append this method every 
> time a database table is modified.
>
> I'm asking because I had a similar issue when creating the initial auth 
> users/groups in db.py. I had to wrap the code in the following logic to 
> prevent them being added multiple times
>
> if not db().select(db.auth_user.ALL).first():
>   group_1 = auth.add_group('group1', 'group1 employees')
>   ...
>
>
> Thanks
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to