Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_static_view problems when used with include() #266

Closed
mcdonc opened this issue Sep 8, 2011 · 3 comments
Closed

add_static_view problems when used with include() #266

mcdonc opened this issue Sep 8, 2011 · 3 comments

Comments

@mcdonc
Copy link
Member

mcdonc commented Sep 8, 2011

From the maillist, jazg reports:

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.

@mcdonc
Copy link
Member Author

mcdonc commented Sep 9, 2011

#1 above is fixed by a recent commit (cda7f6b)

#2 is incorrect. All names must be unique in the site (they indicate a global URL prefix).

#3 Can you please try the latest trunk? I am unable to reproduce this.

@mcdonc
Copy link
Member Author

mcdonc commented Sep 9, 2011

About #2, I understand now. In the presence of a route prefix, the name should be nonglobal because it's prefixed by the route prefix in the URL. It's a bit tricky at the moment because we use the name as a global identifier for pyramid.url.static_url (aka request.static_url) API to be able to generate static URLs against individual static views, e.g.:

request.static_url('foo:bar/baz.html')

I'll try to fix it somehow.

I still need some sort of repeatable test case for #3 though.

@mcdonc mcdonc closed this as completed in bc9357f Sep 9, 2011
@mcdonc
Copy link
Member Author

mcdonc commented Sep 9, 2011

#2 was fixed with the above commit, and I can't repeat #3, so calling it closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant