Here is a bit of syntactic sugar I use for creating fields with less 
typing.  And better consistency, of course -- there always has to be a good 
reason for my lazy keyboard-saving shortcuts!

I have a number of fields which are for specific data types, such as phone 
numbers.  I gather the "common" parts of the Field definition into a 
dictionary:

phone_fld = {'requires':IS_EMPTY_OR(IS_PHONE()),
             'widget':lambda fld,val: SQLFORM.widgets.string.widget(fld,val,
_type='tel',_class='form-control')}

When defining the field in a table, I invoke the dictionary at the end of 
the Field definition:

Field("homephone","string",length=20,label=T("Home phone"),**phone_fld),
Field("workphone","string",length=20,label=T("Work phone"),**phone_fld),
Field("cellphone","string",length=20,label=T("Cell phone"),**phone_fld),

Now the field is created exactly as I want.  I keep a list of these 
"helpers" in a module which I can call out when creating tables.  It really 
saves the typing and allow me to control how my fields are rendered on one 
place instead of scattered among all the tables.

-- Joe

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to