The stupidness has apparently set in before Labor Day Weekend.

I'm embarrassed to say that I now know that all values are passed by
reference in python :)

never EVER drink and code

On 8/30/07, Thomas G. Willis <[EMAIL PROTECTED]> wrote:
>
> Hi All, I'm at my wits end on this.
>
> I thought I'd be slick and generate my widgets from columns already
> defined to save myself some work. However, I seem to be getting a lot of
> NotEmpty() validators coming in, and I don't know where it's coming from or
> how to stop it.
>
> My Code....
> ===================================
> def widget_from_column(column,
>                        widget_class=w.TextField,
>                        label=None,
>                        required=None,
>                        max_length=None,
>                        f_validators=[],
>                        option_list=None,
>                        **kw):
>
>     print column.name
>     print column.nullable
>     print f_validators
>
>     if label==None:
>         label = column.name.title().replace('_',' ')
>
>     kw['label']=label
>
>
>
>     if column.nullable==False:
>         found=None
>         for fv in f_validators:
>             if fv.__class__.__name__ == v.NotEmpty.__name__:
>                 found=True #something is overriding this or the user
> passed one in
>                 break
>
>         if not found:
>             f_validators.append(v.NotEmpty())
>
>
>     if max_length == None:
>         if hasattr(column.type,'length'):
>             max_length == column.type.length
>         else:
>             max_length=0
>
>     if max_length >0:
>         f_validators.append(v.MaxLength(max_length))
>
>     if f_validators and len(f_validators)>0:
>         kw['validator']= v.All(*f_validators)
>
>     if option_list:
>         kw['options']=option_list
>
>     kw['name']=column.name
>
>     print f_validators
>     return widget_class(**kw)
>
>
>
> when I run this in tg-admin shell everything works the way I think it
> should, I get validators that I specify and nothing more, but when I run
> ./start-myproject.py ... every field is of css class 'requiredfield' and
> has a NotEmpty validator on it even ones where nullable == True.
>
> fwiw the fields are being added to a widgetslist class and then the
> Widgetslist is being put in a tableform ala...
>
>
>
> class AccountFields(w.WidgetsList):
>     id = fu.widget_from_column( AcctgAccount.c.id,widget_class=
> w.HiddenField)
>     institution_id = 
> fu.widget_from_column(AcctgAccount.c.institution_id,label='Acct
> Institution',
>                                            widget_class=
> w.SingleSelectField ,
>                                            option_list=
> fu.get_institution_list)
>     category_id = fu.widget_from_column(AcctgAccount.c.category_id,label='Acct
> Category',
>                                            widget_class=
> w.SingleSelectField,
>                                            option_list=
> fu.get_account_category_list)
>     code = fu.widget_from_column(AcctgAccount.c.code)
>     display_name = fu.widget_from_column(AcctgAccount.c.display_name )
>     description = fu.widget_from_column(AcctgAccount.c.description
> ,widget_class=w.TextArea,cols=50,rows=10,is_required=False)
>
> account_fields = AccountFields()
> account_form = w.TableForm(fields=account_fields,submit_text='Save')
>
>
> Any ideas?
>
> TIA
> --
> Thomas G. Willis




-- 
Thomas G. Willis

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to