I renamed controllers.py to controller.py - the idea being that this is just
the _root_ controller.
Next, I created a directory: controllers/
which contains things like:
controllers/
blog_controller.py
forum_controller.py
login_controller.py
json_api_controller.py
...
For controller.py then:
from controllers.blog_controller import BlogController
from controllers.forum_controller import ForumController
from controllers.login_controller import LoginController
from controllers.json_api_controller import JsonApiController
class Root(controllers.RootController):
blog = BlogController()
forum = ForumController()
login = LoginController()
json_api = JsonApiController()
Nothing else in the root although you might be so inclined to put an index and
default handler in there.
That's controllers.
For models I did a similar thing. Created a models directory that contains .py
source for each SQLObject. 'model.py' then just imports these.
models/
user_model.py
blog_model.py
forum_model.py
tags_model.py
Separating things out like this allows your project to start simply, with
structure, and then scale as you add more features. Which is why I advocated
quickstart creating a directory structure like this in the first place. I
might have mentioned that already. :-)
David isn't going to be the last user wondering how to scale out his TG
install. I'd say if quickstart doesn't change then best practices for doing
this need documenting somewhere and I just know that when reading this people
will wonder why TG quickstart didn't just rig the project like that in the
first place.
>
> From: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> Date: 2006/03/14 Tue AM 01:35:11 GMT
> To: "TurboGears" <[email protected]>
> Subject: [TurboGears] Re: bike shed #2: controllers.py vs. controllers
>
>
> I would like to see various examples of how multiple controller files
> are used in the real world within TG. This thread has grown so large
> and no one has shared any concrete examples yet. :) Anyone? Anyone?
>
> I have a controllers.py that must be 1000 lines now, and it is just
> getting a bit long. I need to cut it up, but am not sure of the best
> way. I know I need to create some "helper classes" to separate out
> certain functionality that is not related to url-mapping, but as far as
> having controllers.py as:
> controllers/
> __init__.py
> detail_controller.py
> add_entry_controller.py
> etc...
>
> Any pointers/examples would be great.
>
> David
>
>
>
>
-----------------------------------------
Email sent from www.ntlworld.com
Virus-checked using McAfee(R) Software
Visit www.ntlworld.com/security for more information
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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
-~----------~----~----~----~------~----~------~--~---