Plone/Zope style view overrides in Pyramid

54 Views Asked by At

I have

  • Add-on product defining a view ("my_view")
  • Application using this addon

Both application views.py are scanned by configurator during the application startup.

My application needs to have a more specific version of my_view, as addon provided generic my_view doesn't know about application specific details. What would be a good Pyramid pattern do this, so that Pyramid Configurator doesn't have a conflict? Can I register a view with the same name and context more specific IRequest or something along the lines?

1

There are 1 best solutions below

0
On

If you want to override a view it usually "just works" if the view was defined in an addon.

config.include('cool_addon')
config.add_view(...)

This works because Pyramid will see your view is closer to the top-level of the application and just has higher priority over the view defined in cool_addon. If a structure like this cannot be achieved for some reason, the brute force approach is to config.commit() the old configuration and then add your view afterward, at which point it will overwrite the old config.