Great advice, I'll do that :)

Thanks, Bruno!

On Aug 22, 4:46 pm, Bruno Rocha <rochacbr...@gmail.com> wrote:
> I guess it is not wrong, but I do not recommend too much code in
> controllers, controllers should be for decide the app flow.
>
> I reccomend you to create a module in /modules
>
> # modules/myobjects.py
> from gluon import *
> request = current.request
> class Myobjects(object):
>     def showsearch(self, db):
>         search
> = db(db.listing.title==request.args(0)).select(db.listing.ALL)
>         items = []
>         for person in search:
>             items.append(DIV(A(person.first_name, _href=URL('listing',args=
> person.id))))
>
>        return TAG[''](*items)
> # modules/myobjects.py
>
> then in controller you do:
>
> # controllers/default.py
>
> def search():
>     from myobjects import Myobjects
>     return dict(showsearch=Myobjects.showsearch(db))
>
> # controllers/deafault.py
>
> Note that you need to pass 'db' instance to the module
>
> I think the controller code looks much better in this way, needs web2py
> 1.97+
>
>
>
>
>
>
>
>
>
> On Mon, Aug 22, 2011 at 2:10 AM, Jarrod Cugley <jcug...@gmail.com> wrote:
> > Is there anything wrong with doing this inside default.py controller?:
>
> > def search():
> >    def showsearch():
> >        search =
> > db(db.listing.title==request.args(0)).select(db.listing.ALL)
> >        items = []
> >        for person in search:
> >            items.append(DIV(A(person.first_name, _href=URL('listing',
> > args=person.id))))
>
> >        return TAG[''](*items)
> >    return dict(showsearch=showsearch())
>
> > That is, nesting functions inside functions, I'm not getting an error,
> > it's working as intended but is this a horrible practice to get into?
> > Is there an ideal way?
>
> --
>
> --
> Bruno Rocha
> [ About me:http://zerp.ly/rochacbruno]
> [ Aprenda a programar:http://CursoDePython.com.br]
> [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
> [ Consultoria em desenvolvimento web:http://www.blouweb.com]

Reply via email to