Re: Using modeling framework in long run

Sebastien Bigaret <[email protected]> 19 Jul 2004 22:16:00 +0200
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>
John Lenton <[email protected]> wrote:
> On 19 Jul 2004 21:00:29 +0200, Sebastien Bigaret wrote:
> > 
> > Second, the framework does not anymore relies that heavily on code
> > generation, but how could you know since this hasn't been publicly
> > announced yet :/ ... (esp. because it's not fully documented)
> 
> I'm not clear on one issue: how do I add validators to dynamicly
> created packages?

You add validators, along w/ any necessary business logic, by defining your
own classes. Now I guess the question is how ;)

  The simplest way is w/ the metaclass approach, when you declare your
  own class with '__metaclass__=CustomObjectMeta' (also look at the
  sections beginning with <<if __name__ ==...>> in dynamic.py for
  examples)

There is an other solution if you want to stay away from metaclasses,
but it requires more work. For example:

  Say you want to have classes in Package.Modules.Classes:

  - in your package's __init__.py:

    * load the model,
    * change its packageName into 'PackageBase' (instead of Package)
    * build the classes (either with dynamic.build() or build_with_metaclass())
    * revert the model's packageName to its original value 'Package'

  - then, define a subclass for each entity, inheriting from
    'PackageBase.Module.Class'. They'll inherit from the dynamically
    built classes, the framework will use the derived classes which hold
    the dedicated validators, etc.

-- Sébastien.


> -- 
> John Lenton ([email protected]) -- Random fortune:
> bash: fortune: command not found
Hey, keep an eye on your bash, looks like it is trying to escape and
seek fortune ;P



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idG21&alloc_id040&op=click