Question

I am looking at moving a web app from pylons to pyramid (formally repoze.bfg) because traversal will fit my app much better than url dispatch.

Currently, when I have a obj with a number of views, I have the view names prefixed with a '+' in the url. e.g.:

/path/to/obj/   (default view)
/path/to/obj/+custom_view1
/path/to/obj/+custom_view2
/path/to/obj/+edit
/path/to/obj/+delete
/path/to/obj/sub_obj/

Pyramid has a feature to handle this is a nice way, but it uses the prefix "@@". Is there a way to change this to "+" so that I can keep my urls the same (you know what they say about cool urls,) and use this feature.

Was it helpful?

Solution

Yes and no, you can change view prefix from "@@" but the new prefix should also be 2-symbold length, see sources for traverser.

Subclassing ResourceTreeTraverser and then registering it instead of the default one should do the trick:

from pyramid.traversal import ResourceTreeTraverser as BaseResourceTreeTraverser

class ResourceTreeTraverser(BaseResourceTreeTraverser):
    VIEW_SELECTOR = "++"

from pyramid.config import Configurator
from pyramid.interfaces import ITraverser
from zope.interface import Interface

config = Configurator()
config.registry.registerAdapter(ResourceTreeTraverser, (Interface,), ITraverser)

Personally, I think VIEW_SELECTOR should be refactored to allow any length view prefixes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top