pyramid_duh.route module

Utilities for traversal

class pyramid_duh.route.IModelResource(model=None)[source]

Bases: pyramid_duh.route.ISmartLookupResource

Resource base class for wrapping models in a sqlalchemy database

Notes

Requires any parent node to set the ‘request’ attribute

create_model(name)[source]

Override this if you wish to allow ‘PUT’ request to create a model

db[source]

Access the SQLAlchemy session on the request

Override this if your session is named something other than ‘db’

get_model(name)[source]

Retrieve a model from the database

Override this for custom queries

class pyramid_duh.route.ISmartLookupResource[source]

Bases: object

Resource base class that allows hierarchical lookup of attributes

Potential use case: /user/1234/post/5678

At the /user/1234 point in traversal you can set a ‘user’ attribute on the resource. At the ‘post/5678’ point in traversal you can set a ‘post’ attribute on that resource. Then the request can access both of them from the context directly:

def get_user_post(context, request):
    user = context.user
    if user.is_cool():
        return context.post
class pyramid_duh.route.IStaticResource[source]

Bases: pyramid_duh.route.ISmartLookupResource

Simple resource base class for static-mapping of paths

subobjects = {}[source]