Calling a function while adding an entry to auth_user table

100 views
Skip to first unread message

ranjith

unread,
Oct 16, 2013, 2:07:06 PM10/16/13
to web...@googlegroups.com
Hi,

I want to add a membership to a user when a new user is added to the auth_user table. It is possible when the user registers via the front end through the callback auth.settings.register_onaccept.

But in my case, I am adding the bulk entries to the auth_user table using the script. So, now, while entries getting added to the auth_user, how to add the permission for the different set of users?

Please help!!!!

Niphlod

unread,
Oct 16, 2013, 2:53:39 PM10/16/13
to web...@googlegroups.com
use DAL callbacks if you need "mass inserts" to work in the same way.

http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#before-and-after-callbacks

黄祥

unread,
Oct 16, 2013, 7:45:19 PM10/16/13
to web...@googlegroups.com
other way i think you can add auth.add_permission on your script, something like :

# add group
auth.add_group('Manager', 'Manager')
auth.add_group('Admin', 'Admin')
# add user
db.auth_user.bulk_insert([{'first_name' : 'Manager', 'last_name' : 'Manager', 
  'email' : 'a...@a.com', 'username' : 'manager', 
  'password' : db.auth_user.password.validate('passmeplease')[0]}, 
 {'first_name' : 'Admin', 'last_name' : 'Admin', 
  'email' : 'b...@b.com', 'username' : 'admin', 
  'password' : db.auth_user.password.validate('passmeplease')[0]}])

# add permission
auth.add_permission(1, 'read', db.whatever)
auth.add_permission(1, 'create', db.whatever)
auth.add_permission(1, 'select', db.whatever)

ref:

best regards,
stifan

ranjith2041

unread,
Oct 17, 2013, 1:21:36 AM10/17/13
to web...@googlegroups.com
Thanks for the reply. 


--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/_gvWtKM7NPY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

ranjith

unread,
Oct 17, 2013, 2:56:11 AM10/17/13
to web...@googlegroups.com
Thanks for the information. I hope so now I can proceed with that.

Also, is there any callbacks for the table creation?? I have a table which will have the three static entries added to it only one time. Now, I am manually inserting the records into the table once the table is created. I want to do it automatically, so that once the table is created, those entries should be inserted into that table. Is there a way to achieve this?
Thanks for the reply. 


To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

ranjith

unread,
Oct 17, 2013, 1:38:25 PM10/17/13
to web...@googlegroups.com
I just need to insert some records into a table when that table is created. I dont know how to do it. Please help!!!

ranjith

unread,
Oct 18, 2013, 8:31:01 AM10/18/13
to web...@googlegroups.com
Is there a way to do it?

黄祥

unread,
Oct 18, 2013, 9:06:22 AM10/18/13
to web...@googlegroups.com
yes, can, please do with before insert or after insert and please read the book on dal chapter in before and after callback sub chapter

ref:

and for the example you can see in this forum 

best regards,
stifan

ranjith2041

unread,
Oct 18, 2013, 10:50:43 AM10/18/13
to web...@googlegroups.com
Thanks. But those callbacks are for insertion and deletion of records in a table. I want a callback for the creation of a table.


--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/_gvWtKM7NPY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Dave S

unread,
Oct 18, 2013, 4:08:08 PM10/18/13
to web...@googlegroups.com
On Friday, October 18, 2013 7:50:43 AM UTC-7, ranjith wrote:
Thanks. But those callbacks are for insertion and deletion of records in a table. I want a callback for the creation of a table.


How often is a table created?  Your original message in this thread referred to the auth table, which pretty much is just created once, right?

If this is the case, could you use the web2py shell, or even the database engines shell? For out-of-the-box web2py, that's the sqlite command line tool, which I use quite a bit for ad hoc queries on the data I'm logging with my web2py app. The admin page of the app's site also allows you to add new entries to a table, and you could turn your site on only for localhost, add the entries, and then make the site visible to your audience.  But if "bulk loading" means you've got a lot of entries, than a script run from the shell seems like the easy way to do this.

(sqlite's version of backing up is essentially a way to generate such a script which would then be used to rereate the DB and repopulate it)

/dps
Reply all
Reply to author
Forward
0 new messages