[tw.forms] #32: Different default HTML escaping setting of Genshi/Mako?

3 views
Skip to first unread message

Trac from toscawidgets.org

unread,
Jun 15, 2009, 2:07:31 AM6/15/09
to toscawidge...@groups.google.com
#32: Different default HTML escaping setting of Genshi/Mako?
-------------------+--------------------------------------------------------
Reporter: wdx04 | Owner:
Type: defect | Status: new
Priority: major | Version: 0.9
Keywords: |
-------------------+--------------------------------------------------------
I'm writing a custom field getter for tw.forms.DataGrid, to render a
column as a HTML link:

class LinkColumnWrapper(object):
def __init__(self, action, id_column, display_column):
self.action = action
self.id_column= id_column
self.display_column = display_column

def __call__(self, obj):
obj_rec = obj
for id_column in self.id_column.split('.'):
obj_rec = getattr(obj_rec, id_column)
id_value = obj_rec
obj_rec = obj
for display_column in self.display_column.split('.'):
obj_rec = getattr(obj_rec, display_column)
display_value = obj_rec
assert isinstance(display_value, basestring)
return u'<a href="%s?%s=%s">%s</a>'%(self.action,
str(self.id_column), id_value, saxutils.escape(display_value))

Here is my custom grid class:

class TabletGrid(tw.forms.DataGrid):
fields = [ (u'Tablet Name', LinkColumnWrapper('tablet_assigment',
'tablet_id', 'tablet_name')), (u'IP Address', 'tablet_ip'), (u'Assigned to
User', 'user_name') ]

When the grid renders, the "<a>" are escaped to "&lt;a&gt;", which is not
the excepted behavior for me. Then I added one line to my TabletGrid class
like this:

class TabletGrid(twf.DataGrid):
engine_name = 'mako'
fields = [ (u'Tablet Name', LinkColumnWrapper('tablet_assigment',
'tablet_id', 'tablet_name')), (u'IP Address', 'tablet_ip'), (u'Assigned
Bus', 'user_name') ]

Now it works, my HTML links are not escaped by mako. It seems the default
escaping setting for mako and genshi template engines are different. Could
anyone introduce a way to unify the behavior of both template engines so a
user do not have to specify a particular template engine for each task?

--
Ticket URL: <http://toscawidgets.org/trac/tw.forms/ticket/32>
tw.forms </trac/tw.forms>
tw.forms - Form building widgets

Trac from toscawidgets.org

unread,
Jun 16, 2009, 9:26:06 AM6/16/09
to toscawidge...@groups.google.com
#32: Different default HTML escaping setting of Genshi/Mako?
-------------------+--------------------------------------------------------
Reporter: wdx04 | Owner:
Type: defect | Status: new
Priority: major | Version: 0.9
Keywords: |
-------------------+--------------------------------------------------------

Comment(by alberto):

Ive reverted the offending changes (I hope) in latest tip. Please upgrade
and report back if it fixes (or doesn't) the issue so I can make a release
ASAP.

Alberto

--
Ticket URL: <http://toscawidgets.org/trac/tw.forms/ticket/32#comment:1>

Trac from toscawidgets.org

unread,
Jun 16, 2009, 7:10:36 PM6/16/09
to toscawidge...@groups.google.com
#32: Different default HTML escaping setting of Genshi/Mako?
-------------------+--------------------------------------------------------
Reporter: wdx04 | Owner:
Type: defect | Status: new
Priority: major | Version: 0.9
Keywords: |
-------------------+--------------------------------------------------------

Comment(by anthonyt):

The problems introduced in r216 (ie commit c9e7839c6b0b) are also
responsible for #29.

I've attached a patch there (diffed off of the latest tip, fe8f0cf8c59b .

I'd be much obliged if you'd take a look / apply it.

--
Ticket URL: <http://toscawidgets.org/trac/tw.forms/ticket/32#comment:2>

Trac from toscawidgets.org

unread,
Jun 17, 2009, 5:54:54 AM6/17/09
to toscawidge...@groups.google.com
#32: Different default HTML escaping setting of Genshi/Mako?
-------------------+--------------------------------------------------------
Reporter: wdx04 | Owner:
Type: defect | Status: new
Priority: major | Version: 0.9
Keywords: |
-------------------+--------------------------------------------------------

Comment(by wdx04):

Thank you anthonyt, after applying your patch, FormField.engine_name
property is working properly but my problem remains, then I looked into
datagrid.py and found the problem: in DataGrid class, line 88, engine_name
is overrided to a hard-coded value 'genshi', so changing this property in
a base class would have no effect. By the way, I found #31 is introduced
in r216, it replaced the original attributes of 'form.mak' with something
from 'input_field.mak'. I think the author just modified the wrong file.

--
Ticket URL: <http://toscawidgets.org/trac/tw.forms/ticket/32#comment:3>

Trac from toscawidgets.org

unread,
Jun 17, 2009, 6:04:03 AM6/17/09
to toscawidge...@groups.google.com
#32: Different default HTML escaping setting of Genshi/Mako?
-------------------+--------------------------------------------------------
Reporter: wdx04 | Owner: anthonyt
Type: defect | Status: assigned
Priority: major | Version: 0.9
Keywords: |
-------------------+--------------------------------------------------------
Changes (by wdx04):

* owner: => anthonyt
* status: new => assigned


--
Ticket URL: <http://toscawidgets.org/trac/tw.forms/ticket/32#comment:4>

Trac from toscawidgets.org

unread,
Jun 18, 2009, 8:08:20 PM6/18/09
to toscawidge...@groups.google.com
#32: Different default HTML escaping setting of Genshi/Mako?
-------------------+--------------------------------------------------------
Reporter: wdx04 | Owner: anthonyt
Type: defect | Status: assigned
Priority: major | Version: 0.9
Keywords: |
-------------------+--------------------------------------------------------

Comment(by alberto):

Replying to [comment:2 anthonyt]:

> The problems introduced in r216 (ie commit c9e7839c6b0b) are also
responsible for #29.
>
> I've attached a patch there (diffed off of the latest tip, fe8f0cf8c59b
.
>
> I'd be much obliged if you'd take a look / apply it.

I'd love to apply it but I cannot find it. Perhaps you forgot to attach
it?

Thanks,
Alberto

--
Ticket URL: <http://toscawidgets.org/trac/tw.forms/ticket/32#comment:5>

Trac from toscawidgets.org

unread,
Jun 18, 2009, 8:13:27 PM6/18/09
to toscawidge...@groups.google.com
#32: Different default HTML escaping setting of Genshi/Mako?
-------------------+--------------------------------------------------------
Reporter: wdx04 | Owner: anthonyt
Type: defect | Status: assigned
Priority: major | Version: 0.9
Keywords: |
-------------------+--------------------------------------------------------

Comment(by alberto):

Replying to [comment:5 alberto]:

> Replying to [comment:2 anthonyt]:
> > The problems introduced in r216 (ie commit c9e7839c6b0b) are also
responsible for #29.
> >
> > I've attached a patch there (diffed off of the latest tip,
fe8f0cf8c59b .
> >
> > I'd be much obliged if you'd take a look / apply it.
>
> I'd love to apply it but I cannot find it. Perhaps you forgot to attach
it?

Duh, please excuse my stupidity, it's late here... #29 in is the answer,
I'll make a test for it to reproduce it and commit the patch tomorrow
morning.

Thanks again!
Alberto

--
Ticket URL: <http://toscawidgets.org/trac/tw.forms/ticket/32#comment:6>

Trac from toscawidgets.org

unread,
Jun 18, 2009, 8:18:29 PM6/18/09
to toscawidge...@groups.google.com
#32: Different default HTML escaping setting of Genshi/Mako?
------------------------+---------------------------------------------------
Reporter: wdx04 | Owner: anthonyt
Type: defect | Status: closed
Priority: major | Version: 0.9
Resolution: duplicate | Keywords:
------------------------+---------------------------------------------------
Changes (by alberto):

* status: assigned => closed
* resolution: => duplicate


Comment:

See #29

--
Ticket URL: <http://toscawidgets.org/trac/tw.forms/ticket/32#comment:7>

Reply all
Reply to author
Forward
0 new messages