Toscawidget resources (Retrieval, injection and rendering)
37 views
Skip to first unread message
Yohan Jarosz
unread,
Apr 9, 2013, 4:55:03 AM4/9/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to toscawidge...@googlegroups.com
Dear community,
I have a few questions about resources:
1) How can I have access to the resources of a widget within a controller? (a tw2.forms.Dynfrom for instance) When I do :
from tw2.core import core resources = core.request_local().get('resources', None)
as in tw2.core.resources._ResourceInjector class, I get nothing... Is there a method on the widget that I can retrieve the resources with ? I can't figure it out.
2) I want to render manually a controller method, but then my resources coming from a widget are not injected in the final rendering. I can overcome this problem by calling it via an HTTP request internally but perhaps there is an other way to do it ?
What I'm doing :
from pylons.templating import render_mako as render form = render('bs/templates/plugin_validate.mak', {'page': 'foo', ...}) # => no injection of resources
but perhaps I need to post this on turbogears discuss.
3) And finally, I need to write down the resources directly in the output instead of the link :
e.g. write <head><script type="text/javascript">alert('foo');</script></head> instead of <head><script src="/static/foo.js" type="text/javascript">
So is there a way to retrieve directly the file from a JSLink?
The reason for what I want to do this is because a third-party application on anoter site is fetching my pages and widgets (with ajax and JSONP) and thus cannot access the javascript as a link in the source. This is why I need to write it down.
Thx a lot
Yohan
(I'm using tw2 and turbogears 2.1.5)
Luca Verardi
unread,
Apr 9, 2013, 5:51:18 AM4/9/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to toscawidge...@googlegroups.com
Hi Yohan,
With Turbogears 2.x i use this method: in lib/base.py i inject my js or css like this
class BaseController(TGController): def __call__(self, environ, start_response): from foo.your.module import sexymenu sexymenu.req().prepare()
Yohan Jarosz
unread,
Apr 9, 2013, 7:03:11 AM4/9/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to toscawidge...@googlegroups.com
Hello Luca,
Resource injection is working automatically for an HTTP request, what I want is to fetch resources manually. This is related to this question thread-turbogears/jji4h0O8rwg/n-pZBFWT6JEJ and the response, but it is not up to date...
Yohan
Moritz Schlarb
unread,
Apr 9, 2013, 1:41:15 PM4/9/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to toscawidge...@googlegroups.com
The availability of the ressources should be independent of whether you actually use the widget at all - and it has to be that way since there will be separate HTTP requests for each.
These URLs get resolved by the ToscaWidgets middleware.
So what you primarily want to is to get the actual URLs of the ressources, right?
In my TG2 app, they are
/resources/<widgetpackagename>/static/... (look at the rendered HTML of any page containing your widget).
Does that help you?
Yohan Jarosz
unread,
Apr 9, 2013, 3:06:12 PM4/9/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to toscawidge...@googlegroups.com
Yes I know that. What I want is not get the URL of the resources but list all resources from a widget and then open all the resources from that widget from a system path to write them in the rendered HTML. Because links cannot be resolved by a third-party application : A link such <script src="/bs/tw2/resources/tw2.jquery/static/jquery/1.7.1/jquery.js" type="text/javascript"/> is read by my application, but cannot be read from another application.