Re: [web2py] Re: multiselect with part of a table

2011-08-05 Thread Nicolas Palumbo
I fixed it with a custom validator as howesc suggested.Basically i
added a second set parameter which has the selected items of other
products, without changing the items that the widget will use, but
affecting the final values variable used for persistence:
class CUSTOM_IS_IN_DB(Validator):
def __init__(
self,
dbset,
dbsetOtherProducts,

if not [x for x in values if not x in self.theset]:
values =values + self.thesetOtherProducts
return (values, None)


now that the issue is solved, due to the amount of time spent on it,
perhaps was easier to split each select in a different table... for
each category.

Thanks for the help provided


Re: [web2py] Re: multiselect with part of a table

2011-08-02 Thread Nicolas Palumbo
yes, shouldn't be what already exists in db because that may include
items of the actual selection. DOing the multiselect only useful for
adding stuff... but the actual selection + what was already selected
from the other products.
I'll see if I find a way to do that.

Thanks,
Nico

On Sat, Jul 30, 2011 at 7:58 PM, howesc how...@umich.edu wrote:
 sounds like you would need to write either a custom validator and or some
 custom handling of the form - the SQLFORM() helper assumes that what is the
 output of the validated field is exactly what you want to store in the DB,
 but it sounds like you want the output of the validated field to be made of
 data that was both submitted by the user and also by what already exists in
 the DB.

 look for custom validators in the book and see if you can build one that
 will work for you.  sounds like you have defined the requirements so that's
 a good first step!



Re: [web2py] Re: multiselect with part of a table

2011-07-30 Thread howesc
sounds like you would need to write either a custom validator and or some 
custom handling of the form - the SQLFORM() helper assumes that what is the 
output of the validated field is exactly what you want to store in the DB, 
but it sounds like you want the output of the validated field to be made of 
data that was both submitted by the user and also by what already exists in 
the DB.

look for custom validators in the book and see if you can build one that 
will work for you.  sounds like you have defined the requirements so that's 
a good first step!


Re: [web2py] Re: multiselect with part of a table

2011-07-29 Thread Nicolas Palumbo
Please is theare any chance to do this? without having to go for the 3
tables apporach?

To remind you all:
I have a multiselect like this one:
db.py:

db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
...
db.define_table('audienceInstances', Field('instances','list:reference
instance'),Field('user',db.auth_user,writable=False, readable=False))

default.py:

monitoredInstances = db.audienceInstances(db.audienceInstances.user ==
auth.user.id)
   #Generates a form for the updation of the list of monitored instances
   instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
submit_button='Update', showid=False)
   if instancesForm.accepts(request.vars, session):
   response.flash = 'list updated'
   elif instancesForm.errors:
   response.flash = 'form has errors'

With this line in index method of default.py I was able to filter the
content against the product selected in the profile:
db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),
'instance.id',db.instance._format,multiple=True)

The problem is, If I change the product in the profile and update the
list of instances with the intstances of the newly selected product, I
lost the content in database for the other instances i selected for
the previous product. Is there any way to show the current instances,
but keep track of peviously selected?

THanks,
Nico


Re: [web2py] Re: multiselect with part of a table

2011-07-27 Thread Nicolas Palumbo
any ideas?


Re: [web2py] Re: multiselect with part of a table

2011-07-26 Thread Nicolas Palumbo
I'm currently having a problem with this validation:

db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),
'instance.id',db.instance._format,multiple=True)
If the user changes the profile to other product and susbscribe to
instances shown for that product, the previously selected instances
are wiped away from the list, I'd like the instances to remain... even
if the select is updated, how can I solve this?

On Fri, Jul 15, 2011 at 5:48 PM, Nicolas Palumbo napalu...@gmail.com wrote:
 works perfect. Thanks!



Re: [web2py] Re: multiselect with part of a table

2011-07-15 Thread Nicolas Palumbo
Although this is working:

db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),'instance.id',multiple=True)

Is only showing ids , disregarding of the format defined here:

db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))

IS there any way to fix that?

Thanks,
Nico

On Thu, Jul 14, 2011 at 1:45 PM, Anthony abasta...@gmail.com wrote:
 The default validator for a list:reference field is
 IS_IN_DB(db,'table.id',multiple=True). Instead of db, you can pass a DAL
 Set to that validator to filter the returned list -- something like:

 db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==current_profile.type),'instance.id',multiple=True)


 See http://web2py.com/book/default/chapter/06#DAL,-Table,-Field and
 http://web2py.com/book/default/chapter/07#Database-Validators.

 Anthony

 On Wednesday, July 13, 2011 2:39:50 PM UTC-4, Nico Palumbo wrote:

 I have currently this multiselect generated by list:references:

 db.py:


 db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
 r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
 ...
 db.define_table('audienceInstances', Field('instances','list:reference
 instance'),Field('user',db.auth_user,writable=False, readable=False))

 default.py:

 monitoredInstances = db.audienceInstances(db.audienceInstances.user ==
 auth.user.id)
     #Generates a form for the updation of the list of monitored instances
     instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
 submit_button='Update', showid=False)
     if instancesForm.accepts(request.vars, session):
         response.flash = 'list updated'
     elif instancesForm.errors:
         response.flash = 'form has errors'

 That shows a list select among all instances. But what if I'd like to
 show a subset of that list, I mean I added a type field in instance
 table, and like to get the instances of the type the user has selected
 in its profile.

 The only way I can think of is creating a separate audienceInstances
 table for each type. Is there any othere way?

 Thanks,
 Nico



Re: [web2py] Re: multiselect with part of a table

2011-07-15 Thread Nicolas Palumbo
I fixed it like this:

db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),'instance.id',lambda
r: '%s %s' %
(db.application[r.app].name,db.server[r.server].hostname),multiple=True)


On Fri, Jul 15, 2011 at 2:52 PM, Nicolas Palumbo napalu...@gmail.com wrote:
 Although this is working:
    
 db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),'instance.id',multiple=True)

 Is only showing ids , disregarding of the format defined here:

 db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
 r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))

 IS there any way to fix that?

 Thanks,
 Nico

 On Thu, Jul 14, 2011 at 1:45 PM, Anthony abasta...@gmail.com wrote:
 The default validator for a list:reference field is
 IS_IN_DB(db,'table.id',multiple=True). Instead of db, you can pass a DAL
 Set to that validator to filter the returned list -- something like:

 db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==current_profile.type),'instance.id',multiple=True)


 See http://web2py.com/book/default/chapter/06#DAL,-Table,-Field and
 http://web2py.com/book/default/chapter/07#Database-Validators.

 Anthony

 On Wednesday, July 13, 2011 2:39:50 PM UTC-4, Nico Palumbo wrote:

 I have currently this multiselect generated by list:references:

 db.py:


 db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
 r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
 ...
 db.define_table('audienceInstances', Field('instances','list:reference
 instance'),Field('user',db.auth_user,writable=False, readable=False))

 default.py:

 monitoredInstances = db.audienceInstances(db.audienceInstances.user ==
 auth.user.id)
     #Generates a form for the updation of the list of monitored instances
     instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
 submit_button='Update', showid=False)
     if instancesForm.accepts(request.vars, session):
         response.flash = 'list updated'
     elif instancesForm.errors:
         response.flash = 'form has errors'

 That shows a list select among all instances. But what if I'd like to
 show a subset of that list, I mean I added a type field in instance
 table, and like to get the instances of the type the user has selected
 in its profile.

 The only way I can think of is creating a separate audienceInstances
 table for each type. Is there any othere way?

 Thanks,
 Nico




Re: [web2py] Re: multiselect with part of a table

2011-07-15 Thread Anthony
The table format string/function should be stored in its ._format attribute, 
so you might also be able to do:
 
db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),
 
'instance.id',db.instance._format,multiple=True)
 
 
Maybe that should actually be the default when label=None.
 
Anthony
 

On Friday, July 15, 2011 11:56:13 AM UTC-4, Nico Palumbo wrote:

 I fixed it like this:
 
 db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),'
 instance.id',lambda
 r: '%s %s' %
 (db.application[r.app].name,db.server[r.server].hostname),multiple=True) 


 On Fri, Jul 15, 2011 at 2:52 PM, Nicolas Palumbo napa...@gmail.com 
 wrote:
  Although this is working:

  
 db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),'
 instance.id',multiple=True)
 
  Is only showing ids , disregarding of the format defined here:
 
  
 db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
  r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
 
  IS there any way to fix that?
 
  Thanks,
  Nico
 
  On Thu, Jul 14, 2011 at 1:45 PM, Anthony abas...@gmail.com wrote:
  The default validator for a list:reference field is
  IS_IN_DB(db,'table.id',multiple=True). Instead of db, you can pass a 
 DAL
  Set to that validator to filter the returned list -- something like:
 
  
 db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==current_profile.type),'
 instance.id',multiple=True)
 
 
  See http://web2py.com/book/default/chapter/06#DAL,-Table,-Field and
  http://web2py.com/book/default/chapter/07#Database-Validators.
 
  Anthony
 
  On Wednesday, July 13, 2011 2:39:50 PM UTC-4, Nico Palumbo wrote:
 
  I have currently this multiselect generated by list:references:
 
  db.py:
 
 
  
 db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
  r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
  ...
  db.define_table('audienceInstances', Field('instances','list:reference
  instance'),Field('user',db.auth_user,writable=False, readable=False))
 
  default.py:
 
  monitoredInstances = db.audienceInstances(db.audienceInstances.user ==
  auth.user.id)
  #Generates a form for the updation of the list of monitored 
 instances
  instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
  submit_button='Update', showid=False)
  if instancesForm.accepts(request.vars, session):
  response.flash = 'list updated'
  elif instancesForm.errors:
  response.flash = 'form has errors'
 
  That shows a list select among all instances. But what if I'd like to
  show a subset of that list, I mean I added a type field in instance
  table, and like to get the instances of the type the user has selected
  in its profile.
 
  The only way I can think of is creating a separate audienceInstances
  table for each type. Is there any othere way?
 
  Thanks,
  Nico
 
 



Re: [web2py] Re: multiselect with part of a table

2011-07-15 Thread Anthony
On Friday, July 15, 2011 12:27:19 PM UTC-4, Anthony wrote: 

 The table format string/function should be stored in its ._format 
 attribute, so you might also be able to do:
  
 db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),
  
 'instance.id',db.instance._format,multiple=True)

 
 
In fact, it looks like this is what the DAL does by default -- but since you 
have overridden the default validator, you have to specify 
db.instance._format explicitly.
 
Anthony
 


Re: [web2py] Re: multiselect with part of a table

2011-07-15 Thread Nicolas Palumbo
works perfect. Thanks!


[web2py] Re: multiselect with part of a table

2011-07-14 Thread Nicolas Palumbo
any alternatives?

On Wed, Jul 13, 2011 at 3:39 PM, Nicolas Palumbo napalu...@gmail.com wrote:
 I have currently this multiselect generated by list:references:

 db.py:

 db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
 r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
 ...
 db.define_table('audienceInstances', Field('instances','list:reference
 instance'),Field('user',db.auth_user,writable=False, readable=False))

 default.py:

 monitoredInstances = db.audienceInstances(db.audienceInstances.user ==
 auth.user.id)
    #Generates a form for the updation of the list of monitored instances
    instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
 submit_button='Update', showid=False)
    if instancesForm.accepts(request.vars, session):
        response.flash = 'list updated'
    elif instancesForm.errors:
        response.flash = 'form has errors'

 That shows a list select among all instances. But what if I'd like to
 show a subset of that list, I mean I added a type field in instance
 table, and like to get the instances of the type the user has selected
 in its profile.

 The only way I can think of is creating a separate audienceInstances
 table for each type. Is there any othere way?

 Thanks,
 Nico



[web2py] Re: multiselect with part of a table

2011-07-14 Thread Anthony
The default validator for a list:reference field is 
IS_IN_DB(db,'table.id',multiple=True). Instead of db, you can pass a DAL 
Set to that validator to filter the returned list -- something like:
 
db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==current_profile.type),'instance.id',multiple=True)
 
 
 
See http://web2py.com/book/default/chapter/06#DAL,-Table,-Field and 
http://web2py.com/book/default/chapter/07#Database-Validators.
 
Anthony
 
On Wednesday, July 13, 2011 2:39:50 PM UTC-4, Nico Palumbo wrote:

 I have currently this multiselect generated by list:references: 

 db.py: 


 db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
 r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
 ...
 db.define_table('audienceInstances', Field('instances','list:reference
 instance'),Field('user',db.auth_user,writable=False, readable=False)) 

 default.py: 

 monitoredInstances = db.audienceInstances(db.audienceInstances.user ==
 auth.user.id)
 #Generates a form for the updation of the list of monitored instances
 instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
 submit_button='Update', showid=False)
 if instancesForm.accepts(request.vars, session):
 response.flash = 'list updated'
 elif instancesForm.errors:
 response.flash = 'form has errors' 

 That shows a list select among all instances. But what if I'd like to
 show a subset of that list, I mean I added a type field in instance
 table, and like to get the instances of the type the user has selected
 in its profile. 

 The only way I can think of is creating a separate audienceInstances
 table for each type. Is there any othere way? 

 Thanks,
 Nico