On Tuesday, May 15, 2012 10:13:42 AM UTC-4, Craig wrote:
>
> When a user logs on, there is a field in the profile that contains the
> designation of the database for the institution associated with that user.
>
Does that mean there's a master database that stores the user records so
you can access it to log in the user (i.e., before you know the user's
institution and therefore database)? In that case, maybe something like
this in the db.py model file:
auth_db = DAL('[auth db URI]')
from gluon.tools import Auth
auth = Auth(auth_db, hmac_key=Auth.get_or_create_key())
if not auth.user and not request.function == 'user':
redirect(URL('default', 'user'))
auth.define_tables()
db = DAL(auth.user.db_uri if auth.user else None)
If the user isn't logged in, that will redirect to the /default/user URL
for login. Note, the URI for the call to DAL() that defines the "db"
connection is either auth.user.db_uri (when the user is logged in) or None.
The reason for the None is so you still have a db instance when the user is
going to the /default/user URL for login (otherwise, any subsequent
db.define_table calls would generate errors). I think None will work, but
if not, you could also use a dummy 'sqlite:memory' URI, or even a regular
SQLite URI.
Anthony