Re: [web2py] Re: Dynamic virtual fields

2012-06-29 Thread Richard Vézina
I try what Jay suggest, that works, but since eval is risky and not required, here what I come up with : inputs_list = [] for a in my_dict: inputs_list.append(Field(my_dict[a]['field_name']+'_f1', type='boolean', widget=SQLFORM.widgets.checkboxes.widget, req

[web2py] Re: Dynamic virtual fields

2011-04-10 Thread Jay
Good one Serbitar. Much better than my solution. When I saw your "I dont get it" post, I was reminded of why JavaScript functions return functions instead of values. So they can capture the scope too. Now you have to call this every time you have to access this table, is that right? On Apr 10, 5

[web2py] Re: Dynamic virtual fields

2011-04-10 Thread Serbitar
OK got it. Lambda functions dont save their scope. Here is the right code: list = ["a","b","c","d"] fields = [] for entry in list: fields += [Field(entry, type="string")] db.define_table('test', *fields) class MyVirtualFields(object): pass def get_func(value): def func(self):

[web2py] Re: Dynamic virtual fields

2011-04-09 Thread Serbitar
Strange. My example from earlier does not work. It returns always the last call from func. list = ["a","b","c","d"] fields = [] for entry in list: fields += [Field(entry, type="string")] db.define_table('test', *fields) class MyVirtualFields(object): pass for entry in list: def func

[web2py] Re: Dynamic virtual fields

2011-04-09 Thread Serbitar
Next question is: How do I attach a label to a virtual field?

[web2py] Re: Dynamic virtual fields

2011-04-09 Thread Serbitar
Right. My problem was not the function itself, but how to generally create a dynamic virtual field with dynamic fields as computation variables (in this case from a given list). On Apr 10, 12:02 am, Anthony wrote: > To create virtual fields, you first have to define a class, such as: > > class My

[web2py] Re: Dynamic virtual fields

2011-04-09 Thread Serbitar
Have the solution: Dynamic Fields: list = ["a","b","c","d"] fields = [] for entry in list: fields += [Field(entry, type="string")] db.define_table('test', *fields) Dynamic virtual Fields: class MyVirtualFields(object): pass for entry in list: def func(self): return getattr

[web2py] Re: Dynamic virtual fields

2011-04-09 Thread Anthony
On Saturday, April 9, 2011 7:34:25 AM UTC-4, Serbitar wrote: > > Sorry, misstyped and sent the message early. So once again: > > I can create database fields from a list like this: > > list = ["a","b","c","d"] > fields = [] > for entry in list: > fields += [Field(entry, type="string")] >

[web2py] Re: Dynamic virtual fields

2011-04-09 Thread Serbitar
Hm, that might be a last resort. I am trying to do something more in line with settatr, but unfortunately, even the fields to compute the virtual fields are variables and not strings in the function, which is also named after the virtual table instead of being a string argument. Seems quite tricky.

[web2py] Re: Dynamic virtual fields

2011-04-09 Thread Jay
I use this method for generating totally dynamic forms. 1. Create an array, say out 2. Append "Field(, , )" to this array for all fields I need - note this is a string, no function calls 3. Wrap the above in an SQLFORM statement. formstring = 'SQLFORM.factory(' +','.join(out)+')' 4. Then eval th

[web2py] Re: Dynamic virtual fields

2011-04-09 Thread Serbitar
Sorry, misstyped and sent the message early. So once again: I can create database fields from a list like this: list = ["a","b","c","d"] fields = [] for entry in list: fields += [Field(entry, type="string")] db.define_table('test', *fields) Now I want to have a virtual field for each field i