0

Currently working on a project with TurboGears2 and ToscaWidgets2. I have a form setup with a few static fields, name, date, and point of contact information. Inside this form I have added a sub form where the user can dynamically add numerous entries in a GrowingGridLayout. The form, its layout, and submitting information is all well and good but I'm having a hard time figuring out how to capture the information from the GrowingGridLayout once it's passed on for saving. Guess the main points are, how do I know how many entries were included in the form?

Included the code for the form:

class OnrampForm(twf.Form):
    title = "Onramp Submission Form"

    class child(twd.CustomisedTableForm):
        onramp_name = twf.TextField(validator=twc.Required)

        class Destinations (twd.GrowingGridLayout):
            environment = twf.SingleSelectField(label='Environment', validator=twc.Validator(required=True), options=[<OPTIONS>])
            location = twf.SingleSelectField(validator=twc.Required, label='Location', options=[<OPTIONS>])
            jms_type = twf.SingleSelectField(label='JMS Type', validator=twc.Validator(required=True), options=[<OPTIONS>])
            subscription_type = twf.SingleSelectField(label='Subscription Type', validator=twc.Validator(required=True), options=[<OPTIONS>])

        onramp_status = twf.SingleSelectField(prompt_text='Status', options=['Initial Release', 'Update'], validator=twc.Required)
        current_date = datetime.date.today()
        need_by_date = twd.CalendarDatePicker(validators=[twc.Required, twc.DateTimeValidator])
        need_by_date.default = current_date + datetime.timedelta(days=30)
        organization = twf.TextField(validator=twc.Required)
        poc_name = twf.TextField(validator=twc.Required)
        poc_email = twf.EmailField(validator=twc.EmailValidator)
        poc_phone = twf.TextField(validator=twc.Required)
        poc_address = twf.TextField()
        poc_city = twf.TextField()
        poc_state = twf.TextField()
        onramp_form = twf.FileField()
        submit = twf.SubmitButton(value="Submit")

    action = "/print_args"
    submit = ""
Darwin von Corax
  • 5,201
  • 3
  • 17
  • 28

1 Answers1

0

If you controller @validates against the form you should get the data into the Destination parameter which should be a list of dictionaries.

Also I just noticed you have two nested forms, that's something that might confuse TW2 pretty much. What you wanted to do is probably have OnrampForm inherit CustomisedForm and then have child inherit TableLayout. See http://turbogears.readthedocs.org/en/latest/cookbook/TwForms.html#displaying-forms

PS: note that need_by_date.default = current_date + datetime.timedelta(days=30) will always return 30 days from when the server started as you are actually storing a current_date = datetime.date.today() class variable that gets computed when the module is imported and no more.

You should use default = Deferred(lambda: datetime.date.today() + datetime.timedelta(days=30)) to achieve that

amol
  • 1,771
  • 1
  • 11
  • 15