Hi,
thanks for your help, I can now have checkboxes in the form, but I can't 
change the "destinataire" field from "id" to "email" :
def sabonner():
    abo = db.abonnement
    abo.mailinglist_id.widget = SQLFORM.widgets.checkboxes.widget
    form = SQLFORM(abo)
    return dict(form=form)

Where can I specify wich fields can be exposed in the form?
thanks


Le lundi 6 août 2012 21:02:44 UTC+2, Cliff Kachinske a écrit :
>
> For starters, I'm not sure the syntax is correct for multiple validators. 
>  The Web2py manual states they need to be in the form of a list.
>
> http://web2py.com/books/default/chapter/29/7#Validators
>
> Also notice I have cleaned up the closing parends.
>
> db.abonnement.destinataire_id.requires = [
>    IS_IN_DB(db, 'destinataire.id', '%(email)s',), 
>    IS_NOT_IN_DB(db(db.abonnement.mailinglist_id==request.vars.
> mailinglist_id), 'abonnement.destinataire_id')
> )]
>
> To change from a dropdown box to checkboxes, you would use widgets.  Check 
> out http://web2py.com/books/default/chapter/29/7#Widgets
>
> On Monday, August 6, 2012 12:52:54 PM UTC-4, goabbear wrote:
>>
>> Hi all,
>> I have tried django before and I want to give a try to web2py because it 
>> looks more language natural, but I run into a problem (sorry if my question 
>> is stupid) :
>> in db.py :
>> ########################
>>
>> db.define_table('destinataire',
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('email', unique=True, 
>> required=True, length=30),
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('nom', length=30),
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('prenom', length=30),
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('entreprise', length=30),
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('fax', length=10),
>>                 format = '%(email)s')
>>
>> db.define_table('mailinglist',
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('nom', unique=True, 
>> required=True, length=30),
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('description', 
>> required=True, length=150),
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('declencheur', 
>> required=True, length=30),
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('public', 'boolean'),
>>                 format = '%(nom)s')
>>
>> db.define_table('abonnement',
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('destinataire_id', 
>> db.destinataire),
>>                 Field 
>> <http://127.0.0.1:8000/examples/global/vars/Field>('mailinglist_id', 
>> db.mailinglist)
>>                 )
>>
>> db.destinataire.email.requires = IS_NOT_IN_DB 
>> <http://127.0.0.1:8000/examples/global/vars/IS_NOT_IN_DB>(db, 
>> db.destinataire.email)
>> db.destinataire.email.requires = IS_EMAIL 
>> <http://127.0.0.1:8000/examples/global/vars/IS_EMAIL>()
>> db.destinataire.email.requires = IS_NOT_EMPTY 
>> <http://127.0.0.1:8000/examples/global/vars/IS_NOT_EMPTY>()
>>
>> db.mailinglist.nom.requires = IS_NOT_IN_DB 
>> <http://127.0.0.1:8000/examples/global/vars/IS_NOT_IN_DB>(db, 
>> db.mailinglist.nom)
>> db.mailinglist.nom.requires = IS_NOT_EMPTY 
>> <http://127.0.0.1:8000/examples/global/vars/IS_NOT_EMPTY>()
>> db.mailinglist.description.requires = IS_NOT_EMPTY 
>> <http://127.0.0.1:8000/examples/global/vars/IS_NOT_EMPTY>()
>> db.mailinglist.declencheur.requires = IS_NOT_EMPTY 
>> <http://127.0.0.1:8000/examples/global/vars/IS_NOT_EMPTY>()
>>
>> #l'abonnement d'un destinataire à une mailinglist doit être unique
>> #tiré de http://osdir.com/ml/web2py/2010-07/msg01889.html
>> db.abonnement.destinataire_id.requires = IS_IN_DB 
>> <http://127.0.0.1:8000/examples/global/vars/IS_IN_DB>(db, 'destinataire.id', 
>> '%(email)s',
>>     _and=IS_NOT_IN_DB 
>> <http://127.0.0.1:8000/examples/global/vars/IS_NOT_IN_DB>(db(db.abonnement.mailinglist_id==request
>>  <http://127.0.0.1:8000/examples/global/vars/request>.vars.mailinglist_id), 
>> 'abonnement.destinataire_id'))
>>
>> ########################
>>
>> As described, a "destinataire" can make multiple subscriptions "abonnement" 
>> to "mailinglist", and a mailinglist have multiple subscribers.
>>
>> I don't understand how to give a user the possibility to make a subscription 
>> to multiple mailinglists in one form like :
>>
>> enter email : _____
>>
>> select mailinglists : 
>>
>> ml1 X
>>
>> ml2 X
>>
>> ml3 .
>>
>> where the user select each mailinglist he wants to subscribe with a checkbox.
>>
>> Thanks for any help
>>
>>

-- 



Reply via email to