__xml_fields__ and __add_fields__

40 views
Skip to first unread message

basicth...@gmail.com

unread,
May 20, 2012, 12:23:03 AM5/20/12
to TurboGears
Trying to get an __add_fields__ to NOT be escaped to the links will
just work.

class PlotboxTableFiller(TableFiller):
__model__ = Plotbox
__add_fields__ = {'config_zip_url':None}

def config_zip_url(self, obj):
url = '<a href="">%s://%s/configs/%d/config.zip</a>' % \
(request.environ['wsgi.url_scheme'],
request.environ['HTTP_HOST'], obj.plotbox_id)
return url

class PlotboxTable(TableBase):
__model__ = Plotbox
__omit_fields__ = ['plotbox_id', 'password', 'netmask',
'__actions__']
__add_fields__ = {'config_zip_url':None}
__xml_fields__ = ['config_zip_url']


But I get the following displayed.

<a href="">http://127.0.0.1:8080/configs/10/config.zip</a>

How can I get it so me __add_fields__ are not escaped?

Thanks.

Alessandro Molina

unread,
May 20, 2012, 8:48:24 AM5/20/12
to turbo...@googlegroups.com
If I'm not wrong xml_fields has to be a dictionary even thought the
value is not used.
> --
> You received this message because you are subscribed to the Google Groups "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.
>
Message has been deleted
Message has been deleted
Message has been deleted

Bob Tanner

unread,
May 21, 2012, 3:39:32 PM5/21/12
to turbo...@googlegroups.com
Why does someone keep deleting my posts and replies to this topic?

Bob Tanner

unread,
May 21, 2012, 3:56:53 PM5/21/12
to turbo...@googlegroups.com
More information.

Seems if I map the column names using the __header__ stuff then the __xml_fields__ stuff does not work.


class PlotboxTable(TableBase):
    __model__ = Plotbox
    __omit_fields__ = ['plotbox_id', 'password', 'netmask', '__actions__']
    __xml_fields__ = ['config_zip_url']
    __add_fields__ = {'config_zip_url':None}
   
    __headers__ = {
        'server_name':'Server Name',
        'share_name':'Share Name',
        'username':'Username',
        'ip_address':'IP Address',
        'server_ip_address':'Server IP Address',
        'network_card':'NDIS Driver',
        'config_zip_url':'Download Config'
    }
   
plotbox_table = PlotboxTable(DBSession)

My "Download Config" columns are like this:

<a href="/configs/1/config.zip">1 config.zip</a>

If I comment out the __headers__ then I get links that work.


Bob Tanner

unread,
May 21, 2012, 4:00:38 PM5/21/12
to turbo...@googlegroups.com
    __headers__ = {
        'server_name':'Server Name',
        'share_name':'Share Name',
        'username':'Username',
        'ip_address':'IP Address',
        'server_ip_address':'Server IP Address',
        'network_card':'NDIS Driver',
#        'config_zip_url':'Download Config'
    }

Just commenting out the config_zip_url and I get links that work.

basicth...@gmail.com

unread,
May 21, 2012, 12:04:12 PM5/21/12
to TurboGears
Changed the code to use a dictionary.

class PlotboxTable(TableBase):
__model__ = Plotbox
__omit_fields__ = ['plotbox_id', 'password', 'netmask',
'__actions__']
__add_fields__ = {'config_zip_url':None}
#__xml_fields__ = ['config_zip_url']
__xml_fields__ = {'config_zip_url':None}

But still the config_zip_url is escaped.

I guess the question is can __add_fields__ be tagged as
__xml_fields__ ?


On May 20, 7:48 am, Alessandro Molina <alessandro.mol...@gmail.com>
wrote:
> If I'm not wrong xml_fields has to be a dictionary even thought the
> value is not used.
>
> On Sun, May 20, 2012 at 6:23 AM, basictheprog...@gmail.com

basicth...@gmail.com

unread,
May 20, 2012, 9:24:50 PM5/20/12
to TurboGears


On May 20, 7:48 am, Alessandro Molina <alessandro.mol...@gmail.com>
wrote:
> If I'm not wrong xml_fields has to be a dictionary even thought the
> value is not used.


http://moksha.csh.rit.edu/tg2tut/sprox/table.html

class DirectorMovieTable(TableBase):
__model__ = Movie
__omit_fields__ = ['movie_id', 'genre_id', '__actions__']
__xml_fields__ = ['directors']
__add_fields__ = {'related_movies':None}


I can try it as a dictionary.

basicth...@gmail.com

unread,
May 21, 2012, 12:01:08 PM5/21/12
to TurboGears
Changed the code to try a dictionary.

class PlotboxTable(TableBase):
__model__ = Plotbox
__omit_fields__ = ['plotbox_id', 'password', 'netmask',
'__actions__']
__add_fields__ = {'config_zip_url':None}
#__xml_fields__ = ['config_zip_url']
__xml_fields__ = {'config_zip_url':None}

It is still escaping the config_zip_url.


On May 20, 7:48 am, Alessandro Molina <alessandro.mol...@gmail.com>
wrote:

ozwyzard

unread,
Sep 5, 2012, 4:13:29 AM9/5/12
to turbo...@googlegroups.com
If I understand your question correctly, you are trying to get a table entry as an href .  If it is still an issue for you, the following worked for me:

1) from genshi import XML
2) use __add_fields__ to add a field
3) define the added field function to return XML('<a href="%s">Link</a>' % url)
Reply all
Reply to author
Forward
0 new messages