Do you have a complete traceback?

On Nov 9, 4:04 am, Bruno Rocha <rochacbr...@gmail.com> wrote:
> Hello,
>
> I'm trying to reach a new development model with web2py, and my goal is an
> application without models. (or almost no models)
>
> why? Well, not always want to have db, auth, all tables defined in the
> db, for example, where an ajax request is my intention to pass an ID and
> perform a static function that does not need any of that, I would still
> have to load db , auth, etc..
>
> I so not want to use conditional models (subfolders) because I find more
> easily to manage imports on top of my controllers or even inside my actions
> only when it is needed.
>
> Now with the use of current object it seems easier to avoid models, I'm
> almost there! but still encounter problems, follows:
>
> Imagine that the app has no file on models and all is contained in modules.
>
> - modules/custom.py
>
> *from gluon import DAL
>
> > class DataBase(DAL):
> >     def __init__(self):
> >         DAL.__init__(self, uri="....", migrate_enabled=True,...,...,...,..)
> > *
>
> In the above module define an extension of DAL that creates an object of
> the type DAL with all params setted
> I know it is not very recommended to extend DAL in this way, but I want a
> "ready and done" db just to import without the need to pass params
> everytime, and I already tested defining the db = DAL() in models/0.py
> which does not works too, raises the same error.
>
> modules/datamodel/article.py
>
> *class Article(object):
>
> > **     def __init__(self, db):
> > **          self.db = db
> > **          self.define_table()*
>
>           *self*.*set_validators()*
>
> *
>
> > **     def define_table(self):*
>
>          *from gluon.dal import Field*
>
> ***         self.entity = self.db.define_table("article",
>
> > **                                      Field("title"),
> > **                                      Field("category", "reference
> > category") # if I change it to "integer" everything works fine
> > **                                      )*
>
> *     def set_validators(self): *
>
>          *from gluon.validators import IS_IN_DB*
>
> *         self.entity.category.requires = IS_IN_DB(self.db, "category.id")*
>
> In the above module defines the object instance that will receive
> the article DAL
>
> - Modules / datamodel / category.py
>
> *class Category(object):
>
> > **    def __init__(self, db):
> > **        self.db = db
> > **        self.define_table()*
>
> *
>
> > **    def define_table(self):
> > **        self.entity = self.db.define_table("category", Field("name"))*
>
> My intention is to import everything I need in the top of controllers
> so in controller/appadmin.py I have in the first lines.
>
> *from custom import DataBase
>
> > **from datamodel.article import Article
> > **from datamodel.category import Category**
> > **db = DataBase()
> > **category = Category(db)
> > **article = Article(db)*
>
>  *
>
> > **def test_function():
> > **     return SQLFORM(article.entity).process()*
>
> Why not work? I always get the message *"Can not operate
> in a closed database"(SQLITE)* or *"Cursor already been closed"(POSTGRES)*
>
> if I remove "reference <type>" from my Fields, it works very well, and I am
> planning to work only with "integers" as references if it cannot be solved.
>
> The real code is in:https://github.com/rochacbruno/Movucaand it is a bit
> more complex than the example code I wrote here. (just clone it in to
> web2py trunk version app folder)
>
> Any hint about it?
>
> Thank you.
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]

Reply via email to