[web2py] Re: Customizing Fields the lazy way

2018-04-16 Thread Anthony
Looks good. A few suggestions: - There is no benefit to using a class with a single static method here -- just extract the new() method and make it a standalone function (maybe call it field_factory). - If you rename kwargs in the new() function to something else (e.g., fargs), t

Re: [web2py] Re: Customizing Fields the lazy way

2018-04-16 Thread Richard Vézina
Thanks Joe, I will have a better read... I had fix my issue, my customization of the plugin introduce a couple of problem... I ends up refactoring the and only load data when all the controlled field has to be updated "once". It fix 80% of the loading time issue the rest of the issue is user relat

[web2py] Re: Customizing Fields the lazy way

2018-04-15 Thread Joe Barnhart
Actually, I borrowed Anthony's excellent idea and made a "factory" class for my field definitions. First I defined a factory class: class Field_Factory(object): from gluon import Field @staticmethod def new(**kwargs): default = dict(**kwargs) def inner(name, **kwargs)

Re: [web2py] Re: Customizing Fields the lazy way

2018-03-15 Thread Richard Vézina
I found a pretty unclean workaround... You have to set the widget like this : db.tablename.REFERENCEDTABLEOFCHILDFIELD.widget = \ lazy_options_widget(on_key='no_table_PARENTFIELDNAME__selected', off_key='PARENTFIELDNAME__unselected',

Re: [web2py] Re: Customizing Fields the lazy way

2018-03-15 Thread Richard Vézina
I wonder if we could we also make field lazy that way in context of custom form... I find some issue with some of my custom form where I use Field() to define my field that will be use... This form is also dynamic, I manipulate field visibility and lazy_option_widget() to make some field depend of

[web2py] Re: Customizing Fields the lazy way

2017-03-26 Thread Joe Barnhart
That's kinda clever. I may think of that! -- Joe On Thursday, March 23, 2017 at 4:19:05 PM UTC-7, Anthony wrote: > > Note, you might as well also add 'type': 'string' to your dictionary, and > maybe 'length': 20. You can also give yourself some flexibility by creating > a function: > > def ph

[web2py] Re: Customizing Fields the lazy way

2017-03-23 Thread Anthony
Note, you might as well also add 'type': 'string' to your dictionary, and maybe 'length': 20. You can also give yourself some flexibility by creating a function: def phone_field(name, **kwargs): defaults = {'type': 'string', 'length': 20, 'requires': IS_EMPTY_