ToscaWidgets2

I’ve been working on some migrating some ToscaWidgets1 (TW1) to ToscaWidgets2 (TW2).

The google group mentions the lack of documentation and I’m here to say, “Ain’t that the truth!”.

I spent hours trying to figure out how to set the default value of a EmailField. You’d think there would be example code showing you how to do this very common task. I read through the Widget Design white paper paying close attention to the “Deep Children” section. But could not figure it out.

Played around on the ToscaWidget Browser and could not figure it out.

I don’t remember what my search terms where but I stumbled upon this over at stackoverflow.com and buried inside the TW1 code was the value={‘key’:’value’} and that was the answer.

Let’s look at some code snippets.

Here is a snippet from my widget.

import tw2.core as twc
import tw2.forms as twf
from tg import lurl

class ArchiveEmailForm(twf.FormPage):
    title = 'Archive Email'

    class child(twf.TableForm):
        user1 = twf.EmailField()
        password1 = twf.PasswordField()

And a snippet from the controller.

    @expose('archiveemail.templates.archive')
    def archive(self, *args, **kw):
        """Handle the 'archive' page."""

        w = ArchiveEmailForm(value={'user2':'[email protected]'}).req()
        return dict(widget=w, page='archive')

And the result. Just hoping this will save someone else time.

Archive Email.jpg