Two applications in one TurboGears project

1 view
Skip to first unread message

James

unread,
Jan 22, 2009, 3:15:52 PM1/22/09
to TurboGears
Hi all,
What's the best way for me to create two "applications" in one TG
project?

I have a working user-facing TG application which needs to stay as-is
(for the most part). What I need is an admin application that uses the
exact same model and configuration as the existing application.

Simply adding the admin functionality to a separate controller on the
user app won't work for me: there are hundreds of instances of the
user app while I need exactly one admin app, and it will various
scheduled tasks that I don't want running on the existing user
application.

A passable alternative would be to use svn:externals to 'import' the
existing model definition and configuration files into a completely
separate new app, but it seems a fairly clunky solution...

My ideal scenario is to have a new top-level module with its own
controllers, templates, static content, etc., but which uses the model
from the existing user application.

My efforts so far have been to manually create this module, and point
the admin app at the existing model from app.cfg, e.g.:
identity.provider='sqlalchemy'
identity.saprovider.model.user="user_app.model.User"

With this set-up:
- identity.provider is set properly when running the second
application, but attempt to use @identity.require cause the server to
hang and I need to kill -9
- when running JUST the new app's unit tests, identity.provider is NOT
set, and nothing works (RequestRequiredException when creating Users)
- when running BOTH the new app's and existing apps' tests,
identity.provider is set as expected

There is a passing mention here: http://docs.turbogears.org/1.0/CreatingBigApplications
"TurboGears expects that there is a loadable module in
<yourpackage>.model", which I don't have...

Is there any way for me to have two distinct controller / view stacks
on top of one model?

Thanks!
James

Jorge Vargas

unread,
Jan 22, 2009, 4:35:14 PM1/22/09
to turbo...@googlegroups.com
you have many ways to tackle this. The first step is what you point
out, you need a "model package"

Now if you give it a little setup you could do wonders, there is this
thing call "namespace package" whic his simply a package which is
build out of other packages. So you will have 3 packages which are
"all your application", lets call it webbuilder

1- webbuilder.model
2- webuilder.app
3- webbuilder.admin

2 and 3 will depend (both setup.py) and import from 1 so everything
that's common goes there. As a bonus webbuilder.model is standalone so
you could even build a cli for it or some GUI other client or what
not.

Chris Perkins has a great explanation on how to convert your project
over to namespaces http://percious.com/blog/archives/13

If this is a new project I'll recommend you try it out with tg2, I
have a running project with this setup, I never had the change with
tg1...

hope that helps

James

unread,
Jan 22, 2009, 5:10:31 PM1/22/09
to TurboGears
> Now if you give it a little setup you could do wonders, there is this
> thing call "namespace package" whic his simply a package which is
> build out of other packages. So you will have 3 packages which are
> "all your application", lets call it webbuilder
>
> 1- webbuilder.model
> 2- webuilder.app
> 3- webbuilder.admin
>
> 2 and 3 will depend (both setup.py) and import from 1 so everything
> that's common goes there. As a bonus webbuilder.model is standalone so
> you could even build a cli for it or some GUI other client or what
> not.
>
> Chris Perkins has a great explanation on how to convert your project
> over to namespaceshttp://percious.com/blog/archives/13

This is great - thanks Jorge!

Unfortunately I'm tied to 1.0 for now, but even so, I'll definitely
try use this method.

Jorge Vargas

unread,
Jan 22, 2009, 7:00:25 PM1/22/09
to turbo...@googlegroups.com
On Thu, Jan 22, 2009 at 4:10 PM, James <rent.lu...@gmail.com> wrote:
>
>> Now if you give it a little setup you could do wonders, there is this
>> thing call "namespace package" whic his simply a package which is
>> build out of other packages. So you will have 3 packages which are
>> "all your application", lets call it webbuilder
>>
>> 1- webbuilder.model
>> 2- webuilder.app
>> 3- webbuilder.admin
>>
>> 2 and 3 will depend (both setup.py) and import from 1 so everything
>> that's common goes there. As a bonus webbuilder.model is standalone so
>> you could even build a cli for it or some GUI other client or what
>> not.
>>
>> Chris Perkins has a great explanation on how to convert your project
>> over to namespaceshttp://percious.com/blog/archives/13
>
> This is great - thanks Jorge!
>

welcome

> Unfortunately I'm tied to 1.0 for now, but even so, I'll definitely
> try use this method.

in that case then you must use the TGBig template, otherwise it will be a hack.

Reply all
Reply to author
Forward
0 new messages