Il giorno venerdì 4 novembre 2016 16:55:21 UTC+1, Anthony ha scritto:
>
>
> You have two options. First, you can simply pass any web2py API or global
> objects as arguments to functions or class constructors in your module.
> Second, you can import the "current" object in your module. It
>
> @anthony
> why db, auth and mail must define current in models while request,
> response, session, cache, and T objects, can work on the fly in modules
> without define current (e.g. current.T) in models?
>
request, response, session, cache, and T are all web2py API objects, so
they can
a, sorry forgot to mention it about current, n anthony already mention it
*e.g.models/db.py*
from gluon import current
current.db = db
current.auth = auth
current.mail = mail
@anthony
why db, auth and mail must define current in models while request,
response, session, cache, and T objects, can
>
> *modules/test.py*
> from gluon import *
>
> def insert_table_event(time_stamp, client_ip, user_id, origin,
> description):
> current.db.auth_event.insert(time_stamp = time_stamp,
> client_ip = client_ip,
> user_id = user_id,
> origin = origin,
> description = description)
>
Note,
On Friday, November 4, 2016 at 11:09:57 AM UTC-4, Fabio Ceccarani wrote:
>
> Hi, usefull response,
> but in function defined in test.py variables as session, db, request (and
> other function defined in default.py) are not visible.
> Is it normal or there's a way to make they somehow global?
>
Hi, usefull response,
but in function defined in test.py variables as session, db, request (and
other function defined in default.py) are not visible.
Is it normal or there's a way to make they somehow global?
Or the only way is to past as argument session, db, request?
And for call funtions
i think you can pass the parameter to the modules
*e.g.*
*controllers/default.py*
def test():
table = db.test
return test.grid_0(table)
*modules/test.py*
from gluon import *
def grid_0(table):
grid = SQLFORM.grid(table)
return locals()
another way is access the dal directly from modules with
Hi,
Thanks for your reply. I tried using modules as you suggested. It works
great for simple python functions, but when I try to use DAL it dies. It
appears that functions in modules aren't aware of the model definitions.
Chapter 4 of the manual indicates that I could probably do this by
just an idea why not put it on modules?
e.g.
*controllers/default.py*
import file1
a = file1.function1(x, y)
b = file1.function2(y, z)
*modules/file1.py*
def function1(value1, value2):
code
return
def function2(value1, value2):
code
return
best regards,
stifan
--
9 matches
Mail list logo