Okay I have been experimenting for a while, there are still a few
issues related to add_static_view:

#1:

"""
from pyramid.config import Configurator
from paste.httpserver import serve

def static_include_1(config):
    config.add_static_view('static_1', '/path/to/static_1')

def static_include_2(config):
    config.add_static_view('static_2', '/path/to/static_2')

if __name__ == '__main__':
    config = Configurator()
    config.include(static_include_1, route_prefix='prefix_1')
    config.include(static_include_2, route_prefix='prefix_2')
    serve(config.make_wsgi_app())
"""

If I set up more than one static view, and at least one of them is
under a prefix, the remaining ones will continue to use the first
prefix. So the second one is "/prefix_1/static_2/" when it should be "/
prefix_2/static_2".

The reason for this seems to be because StaticURLInfo keeps the
original config it was called with, so add_route always sees the
original config's route_prefix. I can work around it by manually
updating the StaticURLInfo.config attribute here:

def static_include_2(config):
    from pyramid.interfaces import IStaticURLInfo
    info = config.registry.queryUtility(IStaticURLInfo)
    info.config = config
    # info.config.route_prefix = config.route_prefix # this works too
    config.add_static_view('static_2', '/path/to/static_2')

#2:

If I use the same name for both static views, like both "static"
instead of "static_1" and "static_2", there will be a route name
conflict. add_static_view should probably be updated to take the
prefix into account and make sure to use the full path for route
names: "prefix_1/static/" and "prefix_2/static/"

#3:

Including debugtoolbar is still causing prefixes to be ignored when
including a function that calls add_static_view. Although basic
includes like this one do still get prefixes applied:

def basic_include(config):
    config.add_route('home', '/')
    config.add_view(lambda request: Response('hello'),
route_name='home')

I don't know if it's debugtoolbar itself that causes the problem or
something to do with tweens or addons in general, but the toolbar is
the only one I have tried so far.



On Sep 3, 9:43 pm, Chris McDonough <[email protected]> wrote:
> On Sat, 2011-09-03 at 19:55 -0400, Chris McDonough wrote:
> > On Sat, 2011-09-03 at 16:16 -0700, jazg wrote:
> > > Using the same script but changing these two functions:
>
> > > """
> > > def level1_include(config):
> > >     config.add_route('level1', '/')
> > >     #config.include(level2_include, route_prefix='/level2')
> > >     config.include(level2_include)
>
> > > def level2_include(config):
> > >     #config.add_route('level2', '/')
> > >     config.add_route('level2', '/level2/')
> > > """
>
> > > I want this to have the very same effect, because even though I
> > > haven't included level2_include with a second prefix, it should still
> > > carry over the "/level1" prefix because I'm calling it from within
> > > level1_include. Instead it just creates the route "/level2/" at the
> > > root.
>
> > Yes, that is a bug.  Thanks for the report.
>
> > > My actual problem is concerning add_static_view:
>
> > add_static_view will work itself out once I fix the bug.  I don't think
> > the debugtoolbar is involved in this particular bug (although we may
> > find a separate bug involving the toolbar).  Tracking the original bug
> > here:
>
> >https://github.com/Pylons/pyramid/issues/260
>
> I've fixed this on the Pyramid trunk (details are in the issue).  Maybe
> you could give it a shot and see if it also fixes your add_static_view
> issue:
>
>    $ git pull git://github.com/Pylons/pyramid.git
>    $ cd pyramid
>    $ {yourvirtualenv}/bin/python setup.py develop
>
> - C

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to