About Pyramid

99 views
Skip to first unread message

Biswas, Pinakee

unread,
Jun 20, 2012, 7:17:37 AM6/20/12
to pylons-...@googlegroups.com

Hi,

 

I have been going through Pyramid documentation for the platform we are building.

 

It’s probably a bit too early to ask this considering we have just started on Pyramid. But it would be quite helpful in understanding if you could please let me know the following:

 

We have gone through the documentation for migration from Pylons to Pyramid but some of the things we are not clear:

 

1.       I think there is no controller in Pyramid and I think the Views probably plays the role (for what is there in Pylons). In Pylons, I could have multiple controllers (or python files/modules in controller folder to say in crude way). I think in Pyramid, it would probably be the same (new python modules) but route needs to be defined. The view.py is provided when a Project is created.

2.       In Pylons, lib folder contained 3rd party code and any other code that doesn’t fit in the main application. Is there anything similar in Pyramid? Or any similar convention?

 

Looking forward to your help…

 

Thanks,

Pinakee

 

 

P Please don't print this e-mail unless you really need to, this will preserve trees on planet earth.

----------------------------Disclaimer-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The information contained in this message (including any attachments) is confidential and may be privileged. If you have received it by mistake please notify the sender by return e-mail and permanently delete this message and any attachments from your system. Please note that e-mails are susceptible to change and malwares. VVIDIA COMMUNICATIONS PVT LTD. (including its group companies) shall not be liable for the improper or incomplete transmission of the information contained in this communication nor for any delay in its receipt or damage to your system.

-------------------------------------------------------------------------------------------------------------------------Disclaimer----------------------------------------------------------------------------------------------------------

 

image001.png

Jonathan Vanasco

unread,
Jun 20, 2012, 10:26:07 AM6/20/12
to pylons-discuss


On Jun 20, 7:17 am, "Biswas, Pinakee" <pina...@vvidiacom.com> wrote:

> 1.       I think there is no controller in Pyramid and I think the Views
> probably plays the role (for what is there in Pylons). In Pylons, I could
> have multiple controllers (or python files/modules in controller folder to
> say in crude way). I think in Pyramid, it would probably be the same (new
> python modules) but route needs to be defined. The view.py is provided when
> a Project is created.

Yes.

views in Pyramid are similar to Controllers in Pylons.

There is also a pyramid_handlers package (
http://docs.pylonsproject.org/projects/pyramid_handlers/en/latest/?awesome
) which largely emulates the Pylons style controllers.

Pyramid is a lot more configurable than Pylons, so you can have both
Pyramid views and pyramid_handlers controllers in the same application
if you want.

/views.py is just a file that was created by an application scaffold.

You can replace it with /views/__init__.py

It is only read when you `config.scan("cliquedin.views")` on
application startup ( usually in __init__.py or routes.py )


> 2.       In Pylons, lib folder contained 3rd party code and any other code
> that doesn't fit in the main application. Is there anything similar in
> Pyramid? Or any similar convention?

Your Pyramid application is really just a Python package. It expects
certain files in certain places, and those files to do certain things
-- but you have plenty of namespaces to work with.

I prefer to structure my lib folder like this:

/lib
/lib/handlers.py ( the base handler configuration that the views
inherit from )
/lib/helpers/ ( a directory for helper modules )
/lib/constants.py ( i have some constants that never change, like
States & countries )
/lib/forms.py ( i consolidate all my formencode forms, so i can re-use
them )
/lib/ext ( directory for external 3rd party code which isn't
installable by PyPi )


Mike Orr

unread,
Jun 20, 2012, 12:07:33 PM6/20/12
to pylons-...@googlegroups.com
On Wed, Jun 20, 2012 at 4:17 AM, Biswas, Pinakee <pin...@vvidiacom.com> wrote:

Hi,

 

I have been going through Pyramid documentation for the platform we are building.

 

It’s probably a bit too early to ask this considering we have just started on Pyramid. But it would be quite helpful in understanding if you could please let me know the following:

 

We have gone through the documentation for migration from Pylons to Pyramid but some of the things we are not clear:

 

1.       I think there is no controller in Pyramid and I think the Views probably plays the role (for what is there in Pylons). In Pylons, I could have multiple controllers (or python files/modules in controller folder to say in crude way). I think in Pyramid, it would probably be the same (new python modules) but route needs to be defined. The view.py is provided when a Project is created.


A class containing view methods is equivalent to a Pylons controller. You can't use a 'controller' variable to look it up at runtime. Instead, you have to attach each view method to the desired route using @view_config (or a few other ways).

The pyramid_handlers add-on provides a "Handler" abstraction that mimics Pylons controllers more closely.

2.       In Pylons, lib folder contained 3rd party code and any other code that doesn’t fit in the main application. Is there anything similar in Pyramid? Or any similar convention?


Not in the Pyramid scaffolds but you can easily add a /lib directory. See:

http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/pylons/index.html
Pyramid for Pylons users


 http://docs.pylonsproject.org/projects/akhet/en/latest/
Akhet (specifically the demo app, which has a 'lib' directory, and a helpers module tied to 'h' in templates)

 

Looking forward to your help…

 

Thanks,

Pinakee

 

 

P Please don't print this e-mail unless you really need to, this will preserve trees on planet earth.

----------------------------Disclaimer-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The information contained in this message (including any attachments) is confidential and may be privileged. If you have received it by mistake please notify the sender by return e-mail and permanently delete this message and any attachments from your system. Please note that e-mails are susceptible to change and malwares. VVIDIA COMMUNICATIONS PVT LTD. (including its group companies) shall not be liable for the improper or incomplete transmission of the information contained in this communication nor for any delay in its receipt or damage to your system.

-------------------------------------------------------------------------------------------------------------------------Disclaimer----------------------------------------------------------------------------------------------------------

 

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.



--
Mike Orr <slugg...@gmail.com>
image001.png

Parnell Springmeyer

unread,
Jun 20, 2012, 2:02:58 PM6/20/12
to pylons-...@googlegroups.com
1.       I think there is no controller in Pyramid and I think the Views probably plays the role (for what is there in Pylons). In Pylons, I could have multiple controllers (or python files/modules in controller folder to say in crude way). I think in Pyramid, it would probably be the same (new python modules) but route needs to be defined. The view.py is provided when a Project is created.

Views can be structured any way you want. You can create classes and make the views methods of the classes (using the @view_config decorator) in their own separate .py files; you can make them plain python functions with the @view_config decorator or declare them with the configurator in the __init__ module; you could clump them all up into one .py file, into separate .py files, etc…

It's really up to you and how big your application is.

I personally have 90% of the "controllers" separated into their own modules. So for my user's billing page, there is a "view" module named "billing.py" and inside of it is a class "class BillingView" that extends a base view. Inside the class is all of the "view" methods, like update, display, etc...

You can name the class whatever you want, it isn't significant - only to you, the programmer. I like the class based way because I can extend it with a base class that can provide a number of useful abstract methods and members.

I have a few views that are just straight python functions with a @view_config decorating it. These I will typically clump into a module based on shared functionality. So I have a lot of custom error handling views (like 4 or 5) and they are all in a "errors.py" module. Same with any others that are composed that way.

I also use traversal, so I have a separate resources.py module that defines *all* of my traversal object trees.

2.       In Pylons, lib folder contained 3rd party code and any other code that doesn’t fit in the main application. Is there anything similar in Pyramid? Or any similar convention?

I put 3rd party code inside a directory called "libraries" so: pyramid/myapp/libraries right alongside it is a directory called "views", "templates", "models", &c…

Hope that helps!!! I may write a blog post on how I've structured my Pyramid app, as I see this type of question a lot and I'm using Pyramid in a heavy production environment very successfully.

signature.asc

Biswas, Pinakee

unread,
Jun 21, 2012, 12:19:05 AM6/21/12
to pylons-...@googlegroups.com

Hi Jonathan, Mike and Parnell,

Thanks for your prompt responses and the detailed explanations. They certainly would help in designing our platform.

 

Thanks,

Pinakee

 

P Please don't print this e-mail unless you really need to, this will preserve trees on planet earth.

----------------------------Disclaimer-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The information contained in this message (including any attachments) is confidential and may be privileged. If you have received it by mistake please notify the sender by return e-mail and permanently delete this message and any attachments from your system. Please note that e-mails are susceptible to change and malwares. VVIDIA COMMUNICATIONS PVT LTD. (including its group companies) shall not be liable for the improper or incomplete transmission of the information contained in this communication nor for any delay in its receipt or damage to your system.

-------------------------------------------------------------------------------------------------------------------------Disclaimer----------------------------------------------------------------------------------------------------------

 

image001.png
Reply all
Reply to author
Forward
0 new messages