Injecting static content in TurboGears

Something that you usually need to do when providing a library or a reusable wsgi application is installing static data with the library itself. This can be quickly performed by adding something like package_data = {”:[‘*.html’, ‘*.js’, ‘*.css’, ‘*.png’]} to your But then how can we let our turbogears application serve that? For html files (genshi templates) the solution is quite simple, you can just expose them by using @expose(‘librarypackage.templatesdir.template’). For example supposing we are installing libcool with its templates in libcool/templates you can do @expose(‘libcool.templates.index’) For js and css files you can add them to your pages by creating a tw.api.JSLink or tw.api.CSSLink object. Just create inside your library something like: cool_js = tw.api.JSLink(modname = __name__, filename = ‘static/cool.js’) […]

Quick fix for ToscaWidget 0.9.6 bug with ListForm

There is a little bug in ToscaWidget 0.9.6 when creating a form with a ListForm. The solution can be to use a TableForm or to fix the ListForm itself. The problem is inside the genshi template for the ListForm and can be fixed by changing tw.forms-0.9.6-py2.5.egg/tw/forms/templates/list_form.html in each line where there is a call to field.display(value_for(field), **args_for(field)) this must be surrounded with XML(…) so that the result from field.display won’t be escaped by genshi. This should fix the problem when you see the XML code instead of the form itself inside your web page.

Force tw.jquery to include jquery for you and avoid double inclusion if you are using a jquery widget

One big problem when facing ToscaWidgets is when you have to use widgets that use javascript libraries and you are already importing them for your own use. That usually ends up in a double import of the javascript library that in the best case is useless and in the worst one breaks everything. Looking around inside ToscaWidgets documentation you can end up finding that each Resource has an inject method that inserts the resource inside your template. As JSLink is a subclass of tw.api.Resource you can end up injecting the needed <script> tag inside your template and this will let ToscaWidgets know that you have already imported that javascript file. For example if you are using tw.jquery to let ToscaWidgets […]

On Sprox

Lately I have tried to use Sprox with Elixir. First of all I have to thank percious. He is incredibly reliable and helpful. There is actually a bug in sprox that makes him threat one-to-many relationships as one-to-one relationships and makes it show a single selection field instead of a multiple selection field. This can be avoided changing the field type to sprox.widgets.PropertyMultipleSelectField but percious has been so kind to fix it on the fly while I was testing the problem for him and now sprox correctly detects the field type by default. Bad enough there is a big problem with Elixir. As Sprox probably creates internal instances of the Entity you pass to him this causes an  undesidered behaviour. […]