Pylons/pyramid — Issue #396: Configurator doesn't load defaults for views specified using dotted Python names (strings)
Author: davidjb
Created: 2012-01-09 04:21:45+00:00
State: open

When I have class as a view callable in Pyramid, which has been decorated with `@view_defaults`, if I attempt to add this view to my Configurator using its dotted name, class functions decorated with `@view_config` do not receive the defaults.

There seems to be two issues here. Firstly, the code here: https://github.com/Pylons/pyramid/blob/master/pyramid/config/views.py#L562 doesn't attempt to look up the dotted name. Thus, the call checking if the view is a class will fail as `view` is a string. Can this be fixed using something like:

view = arg[0].maybe_dotted(view)
if inspect.isclass(view):
defaults = getattr(view, '__view_defaults__', {}).copy()
defaults.update(kw)

Tested in Pyramid 1.3a4, appears present in git master.

FWIW, I'm adding my view to the config like so:

config.add_view('myprofiles.views.ProfileView',
route_name='listing',
renderer='templates/my_listing.pt')