ToscaWidgets + Pylons can not set resources directory for CSSLink

8 views
Skip to first unread message

Stou Sandalski

unread,
Jul 3, 2007, 11:03:10 PM7/3/07
to ToscaWidgets-discuss
Hi,

I just switched from FormBuild to ToscaWidgets, and can not figure out
how I can tell the framework where to find my CSS files... normally
including a simple css link inside the html page with 'href=/css/
main.css' works perfectly... and that is exactly what I want to do,
have TW simply include the exact name i place in the 'link'
parameter. However... the link that the code bellow generates has the
href of"/toscawidgets/resources/toscawidgets.resources//css/main.css"
I _do_ _not_ have a module named 'toscawidgets/resources/
toscawidgets.resources.... nor do I want it

class Foo(TableForm):
css = [CSSLink(filename='/css/main.css')]

class fields(WidgetsList):
...

I have searched the internet for literally hours and hours, looked
through the source, etc. Can someone shed light on this?

Regards,

Stou

Alberto Valverde

unread,
Jul 4, 2007, 6:14:28 AM7/4/07
to toscawidge...@googlegroups.com

The Links (CSSLink, JSLink) are designed to link to resources inside
the widget's package so they can be bundled along the widget in an
egg. To find the file in the filesystem (to serve it later)
pkg_resources.resource_filename is used which needs a packge name and
a filename with a path relative to the packages directory. This is
why CSSLink expect a modname and filename parameters.

What you're trying to do doesn't really requre TW to handle that
resource since you have control of where it's placed (unlike when you
easy_install a thirdparty widget that bundles its resources). You can
perfectly include the CSS link manually in the page that will render
the widget and it will probabbly be easier.

However, assuming you're using Pylons, you could let TW handle the
CSSLink in your example like this:

CSSLink(modname="yourappspackagename",
filename="public/css/main.css")

Keep in mind, however, that you can no longer include it manually and
be sure that the link is not included twice if a widget that includes
the above link happends to be rendered in the same page.

BTW, I'm planning to rewrite this whole resources stuff somewhen in a
future version in a much more modular way inspired by the ideas at [1]

Alberto

[1] http://blog.ianbicking.org/lxml-transformations.html

Daniele Paolella

unread,
Aug 28, 2007, 5:49:59 AM8/28/07
to ToscaWidgets-discuss
What is actually the proper way to handle Link objects in that kind of
situation? Specifying your application name as modname seems not to
free you from that '/toscawidgets/resources' prefix (using Pylons
0.9.6rc3 with TW 0.1a2dev).
A full working example would be really appreciated if additional
configuration are required somewhere.
For instance, by reading the source, you learn you can pass a prefix
argument to the TWWidgetsMiddleware to substitute the first half of
the default one, but still 'resources' survives.

Alberto Valverde

unread,
Aug 28, 2007, 9:54:05 AM8/28/07
to toscawidge...@googlegroups.com

On Aug 28, 2007, at 11:49 AM, Daniele Paolella wrote:

>
> What is actually the proper way to handle Link objects in that kind of
> situation? Specifying your application name as modname seems not to
> free you from that '/toscawidgets/resources' prefix (using Pylons
> 0.9.6rc3 with TW 0.1a2dev).

The /toscawidgets/resources prefix is neccesary so TW's middleware
knows when a request should be intercepted instead of delegated to
your app.

> A full working example would be really appreciated if additional
> configuration are required somewhere.
> For instance, by reading the source, you learn you can pass a prefix
> argument to the TWWidgetsMiddleware to substitute the first half of
> the default one, but still 'resources' survives.


As you've said, the /toscawidgets part is easy to override in
TGWidgetsMiddleware, however, the /resources part is trickier, but
possible:

from toscawidgets import resources
resources.registry = resources.ResourcesApp("/another_prefix")

Make sure resources.registry is monkey-patced *before* importing any
module that contains resources or else they'd be registered in the
resources registry you just overrided and TW will probably not be
able to serve them.

Alberto

Daniele Paolella

unread,
Aug 28, 2007, 10:11:21 AM8/28/07
to ToscaWidgets-discuss
On 28 Ago, 15:54, Alberto Valverde <albe...@toscat.net> wrote:
> The /toscawidgets/resources prefix is neccesary so TW's middleware
> knows when a request should be intercepted instead of delegated to
> your app.

Ha, this was the point I didn't understand until some brute testing.
Now that's clearer I see no use in overriding default. Many thanks
Alberto.

Reply all
Reply to author
Forward
0 new messages