other ways to do it without using current.

in the module (ex. tools.py):

 def regte_verwysing(regte, tabel, veld, db):
     lys = db(db[tabel].article == regte).select(db[tabel][veld])
     verwysings = [x[veld] for x in lys]
     return verwysings

in the model (ex. db.py):

import tools.py
def regte_verwysing(regte, tabel, veld):
      return tools.regte_verwysing(regte, tabel, veld, db)


If you like closures.

in the module (ex. tools.py):

def regte_verwysing(db):
 def f(regte, tabel, veld):
     lys = db(db[tabel].article == regte).select(db[tabel][veld])
     verwysings = [x[veld] for x in lys]
     return verwysings
  return f

in the model (ex. db.py):

import tools.py
regte_verwysing = tools.regte_verwysing(db) #<- returns a callable
with args (regte, tabel, veld)

you can then call regte_verwysing(regte, tabel, veld) in your code

mic

2012/2/10 Johann Spies <johann.sp...@gmail.com>:
> On 9 February 2012 18:14, Bruno Rocha <rochacbr...@gmail.com> wrote:
>>
>> I dont know exactly how it works, but I had problems serializing db in to
>> current, so Massimo said to always pass it explicitly to classes ad
>> functions, I remember that SQLITE worked, but not Postgres.
>
>
> Anthony's advice to me earlier in this thread is working with PostgreSQL:
>
> In db.py:
>
>
> from gluon import current
> current.db = db
>
> and in the module:
>
> from gluon import *
> def regte_verwysing(regte, tabel, veld):
>     db = current.db
>     lys = db(db[tabel].article == regte).select(db[tabel][veld])
>     verwysings = [x[veld] for x in lys]
>     return verwysings
>
> Regards
> Johann
> --
> Because experiencing your loyal love is better than life itself,
> my lips will praise you.  (Psalm 63:3)
>

Reply via email to