Hello,
I am building a web2py app which is an admin interface for an exisitng 
application with its own database.   I will define all of the other app's 
tables with migrate=False.
I would like the setting of the DAL connection parameters for this database 
to be a part of the web2py application.  
 
Problem is that I will not know the password, or even the user, and these 
need to be updatable by the end user.  So I can't let web2py try to connect 
until I have these set.
 
Looking for feedback on the following approach.  It works (so far) but 
wondering if there is a simpler approach or a pattern that has already been 
worked out ?
 
1) I have defined the DAL and tables for the user's app in a models 
subfolder, so that the initial web2py connection will not immediately try 
to connect to this database.
2)  I have a 0conn.py model file, something like:
CONN_FUNCTION='localconn'
if session.localconn:
    # Good news, I already have the connection details as a session 
variable.
    pass
elif not session.redir:
    #redirect to the screen with the form to specify the connection details 
, and update the session parameters
    #set redir to True so that it doesn't start an infinite loop of 
redirects each time the model is called.
    session.redir = True
    redirect(URL('LocalTD', 'default', CONN_FUNCTION))
elif session.redir and request.function == CONN_FUNCTION:
    # This is a proper redirect to the conn setting, let it go
    pass
else:
    print "This should really be a redirect, what's going on ?"
    print "I have a session.localtdconn: %s, redir : %s" % 
(session.localtdconn, session.redir)
3) in the standard SQLITE db.py I have defined a connection table that 
stores all of the connection parameters.
   The function CONN_FUNCTION (from above) has a form that retrieves this 
info and allows the user to update it. if the form is accepted, it will 
also set the session variables.
   CONN_FUNCTION is called the first time the app is opened to confirm the 
connection details, update the table if necessary, and sets the session 
variables.
 
4) finally my models/local.py model file specifies DAL something like:
     dbc = DAL('drivername'://DSN=session.localconn['dsn']; \
                                         UID=session.localconn['dbuser']; \
                                         PWD=session.localconn['pwd']; 
etc.....
   This model file should only be called if the session.localconn variable 
is already set.
 
Any comments on this apprach ?
 
Thanks
Andrew W
 
 

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to