Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1484 (closed enhancement: fixed)

Opened 12 years ago

Last modified 12 years ago

Decouple twForms from Genshi (widgets converted to Mako)

Reported by: roger.demetrescu Owned by: alberto
Priority: normal Milestone:
Component: ToscaWidgets Version: 1.0.3
Severity: normal Keywords:


Inspired by the thread below, this is my first attempt to convert all twForms widgets from genshi to mako:


Of course the final code should allow the choice of which engine must be used: Genshi or Mako or ...?

Please notice that there's still a test failing when my patch is applied:

ERROR: test_unicode_value_redisplays_if_validation_fails (tests.test_forms.TestUnicode)

If anybody is willing to help solving this issue, your help is much appreciated.. :)

And finally, to help you test the widgets, I've hacked the examples/wsgi_app.py, so you just have to run:

python wsgi_app.py

Feedbacks are very welcomed ! ;)


ToscaWidgets-01.patch Download (6.0 KB) - added by roger.demetrescu 12 years ago.
ToscaWidgetsForms-01.patch Download (19.0 KB) - added by roger.demetrescu 12 years ago.

Change History

Changed 12 years ago by roger.demetrescu

Changed 12 years ago by roger.demetrescu

comment:1 Changed 12 years ago by roger.demetrescu

  • Owner changed from anonymous to alberto
  • Component changed from TurboGears to toscaWidgets

comment:2 follow-up: ↓ 5 Changed 12 years ago by guest

Shouldn't this be done as a separate package, like twFormsMako?

It would be even better if the templates was separated from logic in twForms itself so user could choose the template engine he wants.

Maybe it's possible to create an installable monkeypatcher egg that replace original twForms class settings before the better implementation will be ready?

Why don't use WebHelpers? in templates? It simplifies templates a lot and already used by most of Mako users AFAIK.

comment:3 Changed 12 years ago by roger.demetrescu

Hi "guest" :)

You are right. Indeed I believe genshi's and mako's version of templates should be in separate packages...

When I volunteered my self to convert the templates, Alberto told me it would be enough to just do the conversion... After that, Alberto would decide how this templates would be distributed (I am not a setuptools expert).

That's why I wrote "first attempt" in the ticket's text. My intention was to release the templates, so more users could find any errors, before Alberto spends his time splitting the packages.

Regarding WebHelpers?, I confess I've never used it. It could be used, but it's up to Alberto decide it... :)

Thanks for the feedback.


comment:4 Changed 12 years ago by alberto

  • Status changed from new to closed
  • Resolution set to fixed

Hi Roger,

Thanks for the patches! I've committed some changes into ToscaWidgets? between [3412] and [3415] to make Mako less painful to use with TW (so your hacks are not needed :) and on the way fixed a couple of bugs which Mako has uncovered [3411].

I've decided not to split packages since I think it would be overkill to distribute a package with only template files (and would require a small change in the API to support a widget with different templates in different paths). Maybe this changes sometime in the future...

I've bundled the templates in in twForms itself since [3416]. To use the mako flavours all is needed is to override the "engine_name" attribute and set it to "mako" when subclassing a widget, initializing it or even display it. To override it process-wide the FormField.engine_name and {DataGrid.engine_name can be monkey-patched.

There's no support for app-wide override yet, that would require some more thought and possibly an API change. When a use-case pops up we can think about it then... ;)

Thanks! :)


comment:5 in reply to: ↑ 2 Changed 12 years ago by alberto

Replying to guest:

Why don't use WebHelpers? in templates? It simplifies templates a lot and already used by most of Mako users AFAIK.

WebHelpers? can be used in your own templates if you place them inside the namespace that is being sent to the templates. You can either do this by using a mixin class like this when you make your custom widgets:

class WebHelpersMixin:
    params = ["helpers"]
    helpers = webhelpers

Or you can also provide an extra_vars func when loading the engines that makes them available at all widgets like shown  here.

I would rather not use them in twForms itself to avoid a dependency with WebHelpers?.


Note: See TracTickets for help on using tickets.