Not sure what you try to do, but if myindex has to be called like this :
http://domain/app/controller/myindex... It has to be in the controller...
The functions you can put in module are sub-function, the one you use in
the main function that server pages...

For example you could have a sub-function like this in controller that
nerver render a page :

__subFunc1(arg1, arg2):
    ...
    return ...

or

subFunc2(arg1, arg2):
    ...
    return ...

You can put those functions into module to reuse them in all your
controllers.

But main functions the one that not taking argument has to be in controller
as far as I understand.

Richard

On Tue, Feb 14, 2012 at 2:28 PM, Cliff <[email protected]> wrote:

> I'm trying to DRY my code.  I have a controller like this:
>
> def myindex():
>   import mymodule
>   query = (db.sometable.is_active==True)
>   select_fields = (db.sometable.id, db.sometable.name,
> db.sometable.somefield)
>   mymodule.myindex(request, session, db, query, selectfields)
>
> Then, in mymodule.py
>
> from html import A, TABLE, THEAD, TH, TR, TD, URL
> from dal import DAL, Field, Table, Row, CALLABLETYPES
>
> def myindex(request, session, db, query, selectfields)
>  tbody = []
>  rows = db(query).select(selectfields)
>  fnames = []
>  for f in selectfields:
>    fnames.append(str(f).split('.')[-1]  # pulling out the field name
>  for row in rows:
>    print row # Diagnostic - this is not a real Row object, just a
> list of fields
>    tbody.append(row) ## EXCEPTION OCCURS HERE
>
> I get a key error - can't find row.id
> Can someone give a pointer to how to do this?
> I suppose I can build the row set in my controller, but then it won't
> be as DRY.

Reply via email to