Cool. Thanks for sharing.
On Thursday, December 1, 2011 8:19:05 PM UTC-5, rochacbruno wrote: > > > > On Thu, Dec 1, 2011 at 11:01 PM, Anthony <[email protected]> wrote: > >> Also, isn't it sometimes useful to put code in a model file that you want >> to run on every (or nearly every) request without having to do an import? > > > Yes, some helping functions and objects i think is very useful to have in > modules, but not Auth, Crud, Mail, db and defined tables. obviously I am > talking about a large app. for small apps I see no problem on having [auth, > crud, service, db, mail, etc..] loaded in every request even if it is only > an ajax callback or another simple page. > > But for large apps which uses ajax a lot, I think it is not needed to load > all that objects/instances or define all tables in every request. So in > that cases I am going to use /modules. I created a template app with > basemodels and handlers. so I call then directly in controller only what I > need and when I need to use. > > For example, I dont need crud and auth for some counter functions that I > use as ajax callbacks. > > Example, in a system where I have 100+ tables in DB, so I need an simple > ajax callback to return something related to only one of the tables, why I > need to define every one of them? In this ajax callback I dont need auth, > crud service or nothing more.. I only need access to one table to return a > simple string. > > in controller: > > def myajaxcallback(): > from datamodel.myobject import MyClass > myobject = MyClass('myparams') > return myobject.counter() > > in module: > > from gluon import current > from basemodel import BaseModel # a place where I have code which uses > class attributes to define the tables > > class MyClass(BaseModel): > def __init__(self, params): > from mydb import DataBase # a custom subclass of DAL > self.db = DataBase([theonlytableIneed]) # will return DAL > instance with only the table I need defined > > def counter(self): > arg = current.request.args(0) > return self.db(self.db.theonlytableIneed.field == > arg).select(cache=(cahe.ram, 300)) > > > I already tried to use submodels but I find it very useful for small apps, > but large apps need more class based system to be more reusable. > > > > > > -- > > Bruno Rocha > [http://rochacbruno.com.br] > >

