I was just trying this out and found two problems.

this is trivial but worth mentioning. the last two lines of the
model.template file, are not creating a valid python comment, in case
you will want to mv model.template model.py

The whole idea with the __init__.py and different module objects is
really nice, but it has a little flaw (recursive import), in fact the
"identity" template is currently broken that way.

you are importing the identity (and other modules) into __init__.py
but those modules are importing the metadata object to be used
locally.

I cycle around this problem for some time until I figure out what was
going on and I remember how pylons[1] solves this. They simple have
the metadata defined in it's own module and it's imported by everyone
that wants to use it.

it seems a little idiotic at first but it's the only real way to solve
this if we want model objects to be in different modules and be
exposed united as mypackage.module.

I see two possible solutions:
add a meta.py, but instead of the weird way pylons works (with 2
global variables in meta.py modified from __init__.py. Simply make
meta.py a one liner creating the metadata object and a big comment
explaining why it's there to resolve the possible recursive import.

or

simply forget about importing things into __init__.py and "pollute"
client call so it will have to call into the models. package.

To be honest I prefer the second approach it's uglier and refactoring
will not be as nice, but the first approach is very hard to gasp until
it's too late.


a third and probably not great solution will be to have a way to
instantiate the metadata instance from within TurboGears, but then it
isn't trivial when you need several MetaData instances.

[1] 
http://pylonshq.com/project/pylonshq/browser/pylons/templates/default_project/%2Bpackage%2B/model


On Mon, Jul 21, 2008 at 9:26 PM, Mark Ramm <[EMAIL PROTECTED]> wrote:
>
> model.template is just a sample file for some specific model code.
> The point is that you may want to separate your model objects into
> several modules within the model package.   The code in __init__ is
> required, and is what gets executed when someone does an import
> {{package}}.model
>
> Hope that helps.
>
> On Mon, Jul 21, 2008 at 9:56 PM, Lukasz Szybalski <[EMAIL PROTECTED]> wrote:
>>
>> Hello,
>> I just created tg2 app with paster quickstart, and I was wondering why
>> the folder structure includes model.template?
>>
>> model
>> |   |   |-- __init__.py
>> |   |   |-- identity.py
>> |   |   `-- model.template
>>
>>
>> Compared to tg1.
>>
>> I see that __init__.py  has session data, and mode.template has sample
>> table/ python classes.
>>
>> Is the stuff in __init__ required to create a session ?
>>
>> Isn't the model.tempalate should be called either model.py or {{package}}.py?
>>
>>
>> Lucas
>>
>> >
>>
>
>
>
> --
> Mark Ramm-Christensen
> email: mark at compoundthinking dot com
> blog: www.compoundthinking.com/blog
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to