Pylons / pyramid_layout

Pyramid add-on for managing UI layouts.
Other
24 stars 26 forks source link

Can't override layouts and panels from an included package #4

Closed pauleveritt closed 11 years ago

pauleveritt commented 11 years ago

From Robert Forkel:

I have a library of layouts and panels which may be used in several apps so they get all registered in the includeme function of the library. But some apps may have to override a panel or a layout. But re-registering didn't work (ConfigurationConflictError) and there's no "remove_panel" method on the configurator. So how would i go about when I'd like to register a panel class (possibly derived from the panel in the library) instead of it's base class which has been registered before?

Example of problem:

from pyramid.config import Configurator from pyramid_layout.layout import layout_config

@layout_config(template='templates/mytemplate.pt') class AppLayout(object): def init(self, context, request): self.context = context self.request = request

@layout_config(template='templates/mytemplate.pt') class DerivedLayout(AppLayout): pass

def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ config = Configurator(settings=settings) config.include('pyramid_layout')

config.add_layout(AppLayout, 'templates/mytemplate.pt')

config.add_layout(DerivedLayout, 'templates/mytemplate.pt')

config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.scan() return config.make_wsgi_app()

xrotwang commented 11 years ago

ok. chris rossi clued me in on configuration contexts and i rewrote my sample accordingly - making it more real-world-like as well. and voila! when AppLayout and DerivedLayout are defined in different modules (one scanned from an includeme function the other one from a scan in the main function) it works as expected, i.e. DerivedLayout is registered, AppLayout is not. So i'd say it works as advertised and the issue is invalid.

chrisrossi commented 11 years ago

Thanks Robert!