How use **tgbig** to break controllers.py into multiple files??

15 views
Skip to first unread message

sebe...@spawar.navy.mil

unread,
Jan 18, 2007, 2:38:16 AM1/18/07
to TurboGears
I did ''tg-admin quickstart -t tgbig myproject'' and noticed it now has
a controllers directory and root.py file.

Maybe I'm slow today but I don't see how to use this to break up all
controllers into seperate files.

Can I just create multiple classes in separate files that //all
subclass RootController// and then append to __init__.py //more
imports//? *What* imports?

perhaps add something like this to __init__.py ??


from myproject.controllers.anotherfile1 import
AnotherRootControllerSubClass1
from myproject.controllers.anotherfile2 import
AnotherRootControllerSubClass2
from myproject.controllers.anotherfile3 import
AnotherRootControllerSubClass3
...etc. ??

Thanks

Chris

Jorge Godoy

unread,
Jan 18, 2007, 6:36:47 AM1/18/07
to turbo...@googlegroups.com
"sebe...@spawar.navy.mil" <sebe...@spawar.navy.mil> writes:

> I did ''tg-admin quickstart -t tgbig myproject'' and noticed it now has
> a controllers directory and root.py file.
>
> Maybe I'm slow today but I don't see how to use this to break up all
> controllers into seperate files.
>
> Can I just create multiple classes in separate files that //all
> subclass RootController// and then append to __init__.py //more
> imports//? *What* imports?

This is just Python code. All modularization rules apply. You can code as
you code Python without any problems.

--
Jorge Godoy <jgo...@gmail.com>

Christopher Arndt

unread,
Jan 18, 2007, 7:01:04 AM1/18/07
to turbo...@googlegroups.com
sebe...@spawar.navy.mil schrieb:

> Can I just create multiple classes in separate files that //all
> subclass RootController

No, you have only one RootController, the other controllers should subclass
turbogears.controllers.Controller

> and then append to __init__.py //more
> imports//?

Yep.

> perhaps add something like this to __init__.py ??
>
> from myproject.controllers.anotherfile1 import
> AnotherRootControllerSubClass1
> from myproject.controllers.anotherfile2 import
> AnotherRootControllerSubClass2
> from myproject.controllers.anotherfile3 import
> AnotherRootControllerSubClass3

from myproject.controllers.anotherfile1 import AnotherControllerSubClass1
from myproject.controllers.anotherfile2 import AnotherControllerSubClass2
from myproject.controllers.anotherfile3 import AnotherControllerSubClass3

class MyRoot(controllers.RootController):
foo = AnotherControllerSubClass1()
bar = AnotherControllerSubClass2()
blah = AnotherControllerSubClass3()


Chris

Damjan

unread,
Jan 18, 2007, 11:36:40 AM1/18/07
to TurboGears
> No, you have only one RootController, the other controllers should subclass
> turbogears.controllers.Controller
...

> class MyRoot(controllers.RootController):
> foo = AnotherControllerSubClass1()
> bar = AnotherControllerSubClass2()
> blah = AnotherControllerSubClass3()

refactoring my controller modules I've noticed that it's a bit
confusing that you don't instantiate the RootController but you need to
explicitly create instances of all the other Controller classes.

Alberto Valverde

unread,
Jan 18, 2007, 11:47:06 AM1/18/07
to turbo...@googlegroups.com

The RootController is instantiated in start-yourapp.py which is,
technically, part of your app too ;)

Alberto

Reply all
Reply to author
Forward
0 new messages