How to manually render individual parts of a form

111 views
Skip to first unread message

BruceC

unread,
Jan 24, 2012, 8:13:16 PM1/24/12
to toscawidge...@googlegroups.com
Hi all, can someone explain how you would go about rendering individual parts of a form so I can customise the layout of my form? I can currently render an entire form to my mako template using ${form.display() | n}. I am looking to migrate an old Pylons app using a very old version of ToscaWidgets where the context has a 'display_child' method allowing us to display a specific form field in a specific position on the page, & I need to emulate this behaviour.

Cheers,

BruceC

Ralph Bean

unread,
Jan 25, 2012, 12:01:47 AM1/25/12
to toscawidgets-discuss
Hi BruceC,
Just for clarification, are you asking about toscawidgets2? (tw2?)
-Ralph

Excerpts from BruceC's message of Tue Jan 24 20:13:16 -0500 2012:

BruceC

unread,
Jan 25, 2012, 12:11:20 AM1/25/12
to toscawidge...@googlegroups.com
Sorry Ralph - should have clarified  - yes, I am using tw2...

Cheers,

BruceC

BruceC

unread,
Jan 26, 2012, 10:26:15 PM1/26/12
to toscawidge...@googlegroups.com
I should also clarify that I am trying to use tw2 in a Pyramid app. I need to be very specific with the layout of my forms, & simply rendering a complete form does not give enough control over the placement of the form widgets in my html. As I mentioned, the app I am looking to migrate is using a ***very*** old version of toscawidgets 1 (ie ToscaWidgets-0.1a2dev_r3397) which was hacked to provide the ability to render the form tag, & then to render each individual widget (& associated error fields) manually in a mako template.

Is this possible with tw2? I did notice the TableLayout/ListLayout/RowLayout widgets in tw2.forms - should I be looking at using those instead? My preference is to be able to refer to widgets & form-components by name in a template if possible...

pyramid_simpleform (a Pyramid add-on) allows this level of control, but it does not have the power of an integrated widget/validation system that Tosca has...Deform & Colander are also nice, but do not offer a method for manual layout of widgets in a template, so I'm really hoping that tw2 offers a way to do this :)

Cheers,

BruceC

Ralph Bean

unread,
Jan 26, 2012, 11:05:06 PM1/26/12
to toscawidgets-discuss
Hi Bruce,
Thanks for pinging again; got a little backlogged this week.

I think this is what you want::


In [1]: import tw2.forms as twf

In [2]: class MyForm(twf.Form):
...: title = 'My Form!'
...: class child(twf.TableForm):
...: title = twf.TextField
...: director = twf.TextField
...: genres = twf.CheckBoxList(options=['numbah 1', 'numbah 2'])

In [3]: MyForm.child.child.children.director.display()
Out[3]: u'<input id="director"/>'


Is that sufficient for your needs?

I'm also not sure that its clear how to do this in the documentation; I'm filing a ticket to shore this up.

All the best,
Ralph

BruceC

unread,
Jan 26, 2012, 11:15:53 PM1/26/12
to ToscaWidgets-discuss
Ralph,

Thank you very very much - you 'da man!

That is exactly what I was looking for! Now I can get to work on it :)

Given that I've already spent some time posting to the Pyramid google-
discuss site trying to see if the other packages can do this, you
should mention something about this on the Pyramid google-discuss site
if you update the TW2 docs about this...

Cheers,

BruceC

Ralph Bean

unread,
Jan 26, 2012, 11:27:20 PM1/26/12
to toscawidgets-discuss
Excerpts from BruceC's message of Thu Jan 26 23:15:53 -0500 2012:

> Given that I've already spent some time posting to the Pyramid google-
> discuss site trying to see if the other packages can do this, you
> should mention something about this on the Pyramid google-discuss site
> if you update the TW2 docs about this...

Cool. I'll go chime in on it.

Graham Higgins

unread,
Jan 27, 2012, 1:31:19 PM1/27/12
to toscawidge...@googlegroups.com
I'm also (very happily) using tw2 in my Pyramid projects (will have a publicly-accessible URL soon). I've been making very good use of Ralph's fine array of tw2 eye candy extensions and, while I have the opportunity: thank you hugely, Ralph.

So, I haz a question - have the team had any thoughts at all about a Python 3 port? I'm assembling a set of Python 3 versions of my favourite add-ons and the section labelled "tw2" is noticeably blank. I appreciate that tw2 is still under development and that time/effort is at an enormous premium when it's available at all but I was just idly wondering, 'cos I'll obviously have a go myself at scoping the issue at least and if there's work that's already been done towards this end, I'd much prefer to start from there.

Just askin', like.

Cheers,

Graham.


Graham Higgins

unread,
Jan 27, 2012, 1:32:43 PM1/27/12
to toscawidge...@googlegroups.com
Ooops, I didn't mean to try and hijack the thread, sorry, /me lays the blame on Friday generally.

Ralph Bean

unread,
Jan 27, 2012, 2:19:32 PM1/27/12
to toscawidgets-discuss

Excerpts from Graham Higgins's message of Fri Jan 27 13:31:19 -0500 2012:

> I'm also (very happily) using tw2 in my Pyramid projects (will have a
> publicly-accessible URL soon). I've been making very good use of Ralph's
> fine array of tw2 eye candy extensions and, while I have the opportunity:
> thank you hugely, Ralph.

Awesome! Glad to know someone is using it. :)

> So, I haz a question - have the team had any thoughts at all about a Python
> 3 port? I'm assembling a set of Python 3 versions of my favourite add-ons
> and the section labelled "tw2" is noticeably blank. I appreciate that tw2
> is still under development and that time/effort is at an enormous premium
> when it's available at all but I was just idly wondering, 'cos I'll
> obviously have a go myself at scoping the issue at least and if there's
> work that's already been done towards this end, I'd much prefer to start
> from there.

There's been no concrete effort to port to Python 3 yet, but the idea is exciting to me. Can you file a ticket for it at http://bitbucket.org/paj/tw2core ? We've been noticeably inactive in general the past few months but I've a mind to sprint on tw2 bugs and get out of this 'beta' label before PyCon US. Seems like post-beta is a good time to start up with python 3.

Graham Higgins

unread,
Jan 28, 2012, 9:20:48 AM1/28/12
to toscawidge...@googlegroups.com


On Friday, 27 January 2012 19:19:32 UTC, Ralph Bean wrote:
 

There's been no concrete effort to port to Python 3 yet, but the idea is exciting to me.  Can you file a ticket for it at http://bitbucket.org/paj/tw2core ?  



Cheers,

Graham

Ralph Bean

unread,
Jan 28, 2012, 9:46:04 AM1/28/12
to toscawidgets-discuss
Excerpts from Graham Higgins's message of Sat Jan 28 09:20:48 -0500 2012:
> Done - https://bitbucket.org/paj/tw2core/issue/103

Graham, thanks so much. That reference work is incredibly valuable.

Yours,
Ralph

Reply all
Reply to author
Forward
0 new messages