> On Nov 11, 2015, at 7:14 AM, kk <[email protected]> wrote:
> 
> Hi Paul, thanks for clearing this out for me,
> However I have a couple of confusions which I have added in-line to your 
> reply.
> 
> 
> 
> On Wednesday 11 November 2015 05:21 PM, Paul Everitt wrote:
>> 
>> When you are starting, most people define their routes in their __init__ 
>> main() function, and their views in a views.py module which they read with 
>> config.scan(‘.views’). You can go a LONG way with just this. Feel free to 
>> stop reading at this point. :)
> :) Well, My application is big enough so I have to stop reading at this point.
> 
>> 
>> Later, people start organizing their code base by component: a todo 
>> directory, a user directory, etc. Each of those then have a views.py module 
>> in them. However, they still leave the route definition in the top-level 
>> __init__.py, to control ordering.
> 
> Oh,  don't understand this, because I would still need scanning right?  So do 
> I scann packages or individual files, as in package/module?
> And I would like to know if I have to do the double work of first writing the 
> roots and then also do the 
> @view_config(route_name=view_name)?
> This is a different query all together and I did mail it on a different 
> thread, but now that we are discussing, I thought of asking this.
> The Reason I am asking is can I just use config.add_view and not write roots 
> at all?

No, you still need to do routes, for the reasons explained in the other email.

(Pyramid does have a non-route approach to URL mapping called traversal, but 
you should only introduce it after learning routes.)
> 
>> 
>> After that, though, there is a further level of Pyramid zen:
>> 
>> - Have a todo/__init__.py with an includeme function, which is the single 
>> place for wiring up everything in the todo subpackage
>> 
>> - The includeme function does the view registration
> 
> So again the same question, will I have to do the double work under this 
> situation or will I just do config.ad_view() in the includeme function?

Yes, although it isn’t “double work”. A route is different than a view, because 
one route can lead to multiple views. It’s like asking “can’t you just do my 
database, template, view, and route in one line?” They are different things.

Doing routes and views as one thing introduces problems and magic. Python 
doesn’t like magic. Python believes explicit is better than implicit. So does 
Pyramid.

> 
>> 
>> - It *also* does route definition
>> 
>> - The top-level package then pulls in todo etc. using config.include with a 
>> route prefix to avoid ordering and collision problems:
> 
> So the top level package will still need roots is it?
> My condition is very simple, I will just have a single package with many 
> modules, each being a class based view.
> For example a view_voucher.py having add, update, insert and delete (aka crud 
> ) system.

Do you have anything about a “Voucher” besides views? E.g. templates, database 
models, tests, etc. If so, you might want an organization of:

./app
        __init__.py
        /voucher
                __init__.py
                views.py
                templates/
                models.py
                tests

In this approach:

- voucher/__init__.py does all the route and view registration for Voucher 
inside an “includeme”:

        
http://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/configuration/whirlwind_tour.html#the-includeme-convention

- app/__init__.py uses config.include(‘.voucher’) etc. for each part of your 
application

> Similarly there will be a view_user, view_account view_product etc.
> 
> So I am trying to figure out how a single package can be scanned, or do I 
> have to write individual config.add_view statements for all my 
> package/module/view_function or class?
> I am sorry if I am sounding too naive, but  have used Pylons before and the 
> system was very simple, there used to be a controllers directory and I had 
> all my controller modules/classes there.

Yes, magic directory names and magic scanning. If your goal is the least amount 
of work:

- __init__.py does all the config.add_route (you can’t avoid that duplication)

- __init__.py does config.scan(‘.’) to go look everywhere for @view_config

—Paul

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply via email to