[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-09-15 Thread Cliff
All is good.

I just wanted to make sure I was seeing the intended behavior.

On Sep 15, 9:30 am, Massimo Di Pierro 
wrote:
> After reading this again and again... this is the intended behavior.
>
> form = SQLFORM(,hidden=...) causes the hidden fields to be passed
> with the submission, no more, no less. form.accepts(...) is not
> intended to read the received hidden fields and move them into
> form.vars. The reason is security. hidden fields can be tampered with.
> So you have to do:
>
> form.vars.a = request.vars.a # this will move the hidden field a (if
> exists) into the form
> form = SQLFORM(..., hidden=dict(a='b'))
>
> In the future we may consider having digitally signed hidden fields.
>
> On Aug 30, 12:43 pm, Cliff  wrote:
>
>
>
> > Hmmm.
>
> > I'm on 1.98.2.
>
> > This needs more investigation, but I can't do it today.
>
> > On Aug 30, 8:39 am, DenesL  wrote:
>
> > > SQLFORM with hidden fields works fine in 1.98.2:
>
> > > # model
> > > db.define_table('dog',
> > >   Field('name'),
> > >   Field('age', 'integer')
> > >   )
>
> > > # controller
> > > def newdog():
> > >   form = SQLFORM(db.dog, fields=['name'], hidden={'age': 1})
> > >   if form.accepts(request, session):
> > >     response.flash = 'ok'
> > >   elif form.errors:
> > >     response.flash = 'not ok'
> > >   return dict(form = form)
>
> > > Any new entry in the dog table will have the age field set to 1.


[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-09-15 Thread Massimo Di Pierro
After reading this again and again... this is the intended behavior.

form = SQLFORM(,hidden=...) causes the hidden fields to be passed
with the submission, no more, no less. form.accepts(...) is not
intended to read the received hidden fields and move them into
form.vars. The reason is security. hidden fields can be tampered with.
So you have to do:

form.vars.a = request.vars.a # this will move the hidden field a (if
exists) into the form
form = SQLFORM(..., hidden=dict(a='b'))

In the future we may consider having digitally signed hidden fields.

On Aug 30, 12:43 pm, Cliff  wrote:
> Hmmm.
>
> I'm on 1.98.2.
>
> This needs more investigation, but I can't do it today.
>
> On Aug 30, 8:39 am, DenesL  wrote:
>
>
>
>
>
>
>
> > SQLFORM with hidden fields works fine in 1.98.2:
>
> > # model
> > db.define_table('dog',
> >   Field('name'),
> >   Field('age', 'integer')
> >   )
>
> > # controller
> > def newdog():
> >   form = SQLFORM(db.dog, fields=['name'], hidden={'age': 1})
> >   if form.accepts(request, session):
> >     response.flash = 'ok'
> >   elif form.errors:
> >     response.flash = 'not ok'
> >   return dict(form = form)
>
> > Any new entry in the dog table will have the age field set to 1.


[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-30 Thread Cliff
Hmmm.

I'm on 1.98.2.

This needs more investigation, but I can't do it today.

On Aug 30, 8:39 am, DenesL  wrote:
> SQLFORM with hidden fields works fine in 1.98.2:
>
> # model
> db.define_table('dog',
>   Field('name'),
>   Field('age', 'integer')
>   )
>
> # controller
> def newdog():
>   form = SQLFORM(db.dog, fields=['name'], hidden={'age': 1})
>   if form.accepts(request, session):
>     response.flash = 'ok'
>   elif form.errors:
>     response.flash = 'not ok'
>   return dict(form = form)
>
> Any new entry in the dog table will have the age field set to 1.


[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-30 Thread DenesL
SQLFORM with hidden fields works fine in 1.98.2:

# model
db.define_table('dog',
  Field('name'),
  Field('age', 'integer')
  )

# controller
def newdog():
  form = SQLFORM(db.dog, fields=['name'], hidden={'age': 1})
  if form.accepts(request, session):
response.flash = 'ok'
  elif form.errors:
response.flash = 'not ok'
  return dict(form = form)

Any new entry in the dog table will have the age field set to 1.



[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-30 Thread Cliff
The rest of the insert is working.

As a workaround I'm doing a table update right after the
form.accepts() and just before the redirect.

On Aug 29, 3:45 pm, Anthony  wrote:
> Does it insert the non-hidden fields, or is no record getting inserted at
> all?
>
>
>
>
>
>
>
> On Friday, August 26, 2011 5:43:15 AM UTC-4, Cliff wrote:
>
> > I use SQLFORM something like this:
>
> > fields = 'dog_name dog_weight dog_birtdate'.split(' ')
> > hidden = {'dog_owner' : some_known_value} # We already know who the
> > owner is
> > SQLFORM(db.dogs, fields=fields, hidden=hidden)
>
> > The hidden fields are on the form.  When I submit the form, they are
> > in request.vars, but SQLFORM does not insert them in the database.
>
> > Is this the way it's supposed to work or do I have a bug?
>
> > Thanks,
> > Cliff Kachinske


[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-29 Thread Anthony
Does it insert the non-hidden fields, or is no record getting inserted at 
all?

On Friday, August 26, 2011 5:43:15 AM UTC-4, Cliff wrote:
>
> I use SQLFORM something like this: 
>
> fields = 'dog_name dog_weight dog_birtdate'.split(' ') 
> hidden = {'dog_owner' : some_known_value} # We already know who the 
> owner is 
> SQLFORM(db.dogs, fields=fields, hidden=hidden) 
>
> The hidden fields are on the form.  When I submit the form, they are 
> in request.vars, but SQLFORM does not insert them in the database. 
>
> Is this the way it's supposed to work or do I have a bug? 
>
> Thanks, 
> Cliff Kachinske



[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-29 Thread DenesL


On Aug 29, 1:22 pm, Cliff  wrote:
> It would look something like this:
>
> db.define_table('dogs',
>     Field('dog_name'),
>     Field('dog_birthdate', 'date'),
>     Field('dog_weight', 'integer'),
>     Field('dog_owner', db.owner)
> )
> db.dogs.dog_owner.requires=IS_IN_DB(db, db.dogs.id,
>     '%(owner_name)s', zero="Choose an owner")
>

I think you want:
db.dogs.dog_owner.requires=IS_IN_DB(db, db.owner.id,
 '%(owner_name)s', zero="Choose an owner")

> Caveat: not closely checked for typos, missing commas, unclosed
> parends etc.



[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-29 Thread Cliff
It would look something like this:

db.define_table('dogs',
Field('dog_name'),
Field('dog_birthdate', 'date'),
Field('dog_weight', 'integer'),
Field('dog_owner', db.owner)
)
db.dogs.dog_owner.requires=IS_IN_DB(db, db.dogs.id,
'%(owner_name)s', zero="Choose an owner")

Caveat: not closely checked for typos, missing commas, unclosed
parends etc.

On Aug 29, 10:14 am, DenesL  wrote:
> Cliff, please post the related "dogs" table model.


[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-29 Thread Cliff
Anthony,

Good catch.

The form should be SQLFORM, the table should be db.purchase_orders.



On Aug 29, 10:18 am, Anthony  wrote:
> Did you show the correct controller code? Your form is define as a SQLTABLE
> (rather than SQLFORM), and the table argument is db.suppliers, not
> db.purchase_orders.
>
> Anthony
>
>
>
>
>
>
>
> On Monday, August 29, 2011 7:33:25 AM UTC-4, Cliff wrote:
>
> > Not sue that would help.
>
> > The insert goes into purchase_orders, not supplier_contacts.
>
> > On Aug 26, 4:16 pm, Anthony  wrote:
> > > Does it work if you set db.supplier_contacts.supplier_id.writable = True
> > in
> > > the controller function?
>
> > > On Friday, August 26, 2011 11:12:31 AM UTC-4, Cliff wrote:
>
> > > > Massimo,
>
> > > > Thank you.
>
> > > > Of course.
>
> > > > Here are are the real table defs:
> > > > +++
>
> > > > ++
> > > > db.define_table('purchase_orders',
> > > >     Field('issue_date', 'date'),
> > > >     Field('number', length=24, requires=IS_NOT_EMPTY(),
> > > >           required=True, notnull=True, comment='Required'),
> > > >     Field('supplier', db.suppliers),
> > > >     Field('shipto', db.locations, label='Ship To'),
> > > >     Field('billto', db.locations, label='Bill To'),
> > > >     Field('del_terms', db.del_terms, label='Delivery Terms'),
> > > >     Field('currency', db.currencies),
> > > >     Field('pmt_terms', db.pmt_terms, label='Payment Terms'),
> > > >     Field('project_no', length=12, label='Project Number'),
> > > >     Field('taxable', 'list:string', default='No'),
> > > >     Field('po_contact', db.contacts,
> > > >             label='Purchase Order Contact'),
> > > >     Field('ap_contact',  db.contacts,
> > > >             label='Accounts Payable Contact'),
> > > >     Field('vendor_rep',  db.contacts,
> > > >             label='Vendor Representative'),
> > > >     Field('documentation_required', 'list:reference documentation',
> > > >             comment='Click to select.  Use Ctrl key for multiple
> > > > selection.')
> > > >     )
> > > > db.purchase_orders.taxable.requires = IS_IN_SET(['Yes', 'No'])
> > > > db.purchase_orders.shipto.requires = IS_IN_DB(db, db.locations.id, '%
> > > > (name)s',
> > > >         zero='Choice required')
> > > > db.purchase_orders.billto.requires = IS_IN_DB(db, db.locations.id, '%
> > > > (name)s',
> > > >         zero='Choice required')
> > > > db.purchase_orders.supplier.requires = IS_IN_DB(db, db.suppliers.id,
> > '%
> > > > (name)s',
> > > >         zero='Choice required')
> > > > db.purchase_orders.del_terms.requires = IS_IN_DB(db, db.del_terms.id,
> > > > '%(name)s',
> > > >         zero='Choice required')
> > > > db.purchase_orders.currency.requires = IS_IN_DB(db, db.currencies.id,
> > > > '%(name)s',
> > > >         zero='Choice required')
> > > > db.purchase_orders.pmt_terms.requires = IS_IN_DB(db, db.pmt_terms.id,
> > > > '%(name)s',
> > > >         zero='Choice required')
> > > > db.purchase_orders.po_contact.requires = IS_IN_DB(
> > > >         db(), db.contacts.id, '%(first_name)s, %(middle_name)s, %
> > > > (last_name)s, %(generation)s ',
> > > >         zero='Choice required')
> > > > db.purchase_orders.ap_contact.requires = IS_IN_DB(
> > > >         db(), db.contacts.id, '%(first_name)s',
> > > >         zero='Choice required')
> > > > db.purchase_orders.vendor_rep.requires = IS_IN_DB(
> > > >         db(), db.supplier_contacts.id, '%(first_name)s',
> > > >         zero='Choice required')
>
> > > > db.define_table('suppliers',
> > > >     Field('name', length=256, required=True, notnull=True),
> > > >     Field('address', length=64),
> > > >     Field('address_2', length=64),
> > > >     Field('city', length=32),
> > > >     Field('state', length=24),
> > > >     Field('zip', length=18),
> > > >     Field('website', length=512, requires=IS_URL()),
> > > >     format = '%(name)s'
> > > >     )
>
> > > > db.define_table(
> > > >     'supplier_contacts',
> > > >     Field('supplier_id', db.suppliers),
> > > >     Field('first_name', length=32, required=True, notnull=True),
> > > >     Field('middle_name', length=32),
> > > >     Field('last_name', length=32, required=True, notnull=True),
> > > >     Field('generation', length=16),
> > > >     Field('email', length=512,
> > > >           requires=IS_EMPTY_OR(IS_EMAIL('invalid email'))),
> > > >     Field('mobile', length=18, label='Mobile phone'),
> > > >     Field('land_line', length=18),
> > > >     Field('fax', length=18),
> > > >     format='%(first_name)s, %(middle_name)s, %(last_name)s, %
> > > > (generation)s'
> > > >     )
> > > > db.supplier_contacts.supplier_id.requires = IS_IN_DB(
> > > >     db, db.suppliers.id, '%(name)s', zero='Choose'
> > > >     )
> > > > db.supplier_contacts.supplier_id.readable = False
> > > > db.supplier_contacts.supplier_id.writable = False
>
> > > > +++
>
> > > > +

[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-29 Thread Anthony
Did you show the correct controller code? Your form is define as a SQLTABLE 
(rather than SQLFORM), and the table argument is db.suppliers, not 
db.purchase_orders.

Anthony

On Monday, August 29, 2011 7:33:25 AM UTC-4, Cliff wrote:
>
> Not sue that would help. 
>
> The insert goes into purchase_orders, not supplier_contacts. 
>
> On Aug 26, 4:16 pm, Anthony  wrote: 
> > Does it work if you set db.supplier_contacts.supplier_id.writable = True 
> in 
> > the controller function? 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > On Friday, August 26, 2011 11:12:31 AM UTC-4, Cliff wrote: 
> > 
> > > Massimo, 
> > 
> > > Thank you. 
> > 
> > > Of course. 
> > 
> > > Here are are the real table defs: 
> > > +++ 
>
> > > ++ 
> > > db.define_table('purchase_orders', 
> > > Field('issue_date', 'date'), 
> > > Field('number', length=24, requires=IS_NOT_EMPTY(), 
> > >   required=True, notnull=True, comment='Required'), 
> > > Field('supplier', db.suppliers), 
> > > Field('shipto', db.locations, label='Ship To'), 
> > > Field('billto', db.locations, label='Bill To'), 
> > > Field('del_terms', db.del_terms, label='Delivery Terms'), 
> > > Field('currency', db.currencies), 
> > > Field('pmt_terms', db.pmt_terms, label='Payment Terms'), 
> > > Field('project_no', length=12, label='Project Number'), 
> > > Field('taxable', 'list:string', default='No'), 
> > > Field('po_contact', db.contacts, 
> > > label='Purchase Order Contact'), 
> > > Field('ap_contact',  db.contacts, 
> > > label='Accounts Payable Contact'), 
> > > Field('vendor_rep',  db.contacts, 
> > > label='Vendor Representative'), 
> > > Field('documentation_required', 'list:reference documentation', 
> > > comment='Click to select.  Use Ctrl key for multiple 
> > > selection.') 
> > > ) 
> > > db.purchase_orders.taxable.requires = IS_IN_SET(['Yes', 'No']) 
> > > db.purchase_orders.shipto.requires = IS_IN_DB(db, db.locations.id, '% 
> > > (name)s', 
> > > zero='Choice required') 
> > > db.purchase_orders.billto.requires = IS_IN_DB(db, db.locations.id, '% 
> > > (name)s', 
> > > zero='Choice required') 
> > > db.purchase_orders.supplier.requires = IS_IN_DB(db, db.suppliers.id, 
> '% 
> > > (name)s', 
> > > zero='Choice required') 
> > > db.purchase_orders.del_terms.requires = IS_IN_DB(db, db.del_terms.id, 
> > > '%(name)s', 
> > > zero='Choice required') 
> > > db.purchase_orders.currency.requires = IS_IN_DB(db, db.currencies.id, 
> > > '%(name)s', 
> > > zero='Choice required') 
> > > db.purchase_orders.pmt_terms.requires = IS_IN_DB(db, db.pmt_terms.id, 
> > > '%(name)s', 
> > > zero='Choice required') 
> > > db.purchase_orders.po_contact.requires = IS_IN_DB( 
> > > db(), db.contacts.id, '%(first_name)s, %(middle_name)s, % 
> > > (last_name)s, %(generation)s ', 
> > > zero='Choice required') 
> > > db.purchase_orders.ap_contact.requires = IS_IN_DB( 
> > > db(), db.contacts.id, '%(first_name)s', 
> > > zero='Choice required') 
> > > db.purchase_orders.vendor_rep.requires = IS_IN_DB( 
> > > db(), db.supplier_contacts.id, '%(first_name)s', 
> > > zero='Choice required') 
> > 
> > > db.define_table('suppliers', 
> > > Field('name', length=256, required=True, notnull=True), 
> > > Field('address', length=64), 
> > > Field('address_2', length=64), 
> > > Field('city', length=32), 
> > > Field('state', length=24), 
> > > Field('zip', length=18), 
> > > Field('website', length=512, requires=IS_URL()), 
> > > format = '%(name)s' 
> > > ) 
> > 
> > > db.define_table( 
> > > 'supplier_contacts', 
> > > Field('supplier_id', db.suppliers), 
> > > Field('first_name', length=32, required=True, notnull=True), 
> > > Field('middle_name', length=32), 
> > > Field('last_name', length=32, required=True, notnull=True), 
> > > Field('generation', length=16), 
> > > Field('email', length=512, 
> > >   requires=IS_EMPTY_OR(IS_EMAIL('invalid email'))), 
> > > Field('mobile', length=18, label='Mobile phone'), 
> > > Field('land_line', length=18), 
> > > Field('fax', length=18), 
> > > format='%(first_name)s, %(middle_name)s, %(last_name)s, % 
> > > (generation)s' 
> > > ) 
> > > db.supplier_contacts.supplier_id.requires = IS_IN_DB( 
> > > db, db.suppliers.id, '%(name)s', zero='Choose' 
> > > ) 
> > > db.supplier_contacts.supplier_id.readable = False 
> > > db.supplier_contacts.supplier_id.writable = False 
> > 
> > > +++ 
>
> > > ++ 
> > 
> > > This is the actual call from the controller: 
> > > # we already know the supplier_id and vendor_rep 
> > > hidden['supplier']=supplier_id 
> > >  

[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-29 Thread DenesL

Cliff, please post the related "dogs" table model.


[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-29 Thread Cliff
Not sue that would help.

The insert goes into purchase_orders, not supplier_contacts.

On Aug 26, 4:16 pm, Anthony  wrote:
> Does it work if you set db.supplier_contacts.supplier_id.writable = True in
> the controller function?
>
>
>
>
>
>
>
> On Friday, August 26, 2011 11:12:31 AM UTC-4, Cliff wrote:
>
> > Massimo,
>
> > Thank you.
>
> > Of course.
>
> > Here are are the real table defs:
> > +++
> > ++
> > db.define_table('purchase_orders',
> >     Field('issue_date', 'date'),
> >     Field('number', length=24, requires=IS_NOT_EMPTY(),
> >           required=True, notnull=True, comment='Required'),
> >     Field('supplier', db.suppliers),
> >     Field('shipto', db.locations, label='Ship To'),
> >     Field('billto', db.locations, label='Bill To'),
> >     Field('del_terms', db.del_terms, label='Delivery Terms'),
> >     Field('currency', db.currencies),
> >     Field('pmt_terms', db.pmt_terms, label='Payment Terms'),
> >     Field('project_no', length=12, label='Project Number'),
> >     Field('taxable', 'list:string', default='No'),
> >     Field('po_contact', db.contacts,
> >             label='Purchase Order Contact'),
> >     Field('ap_contact',  db.contacts,
> >             label='Accounts Payable Contact'),
> >     Field('vendor_rep',  db.contacts,
> >             label='Vendor Representative'),
> >     Field('documentation_required', 'list:reference documentation',
> >             comment='Click to select.  Use Ctrl key for multiple
> > selection.')
> >     )
> > db.purchase_orders.taxable.requires = IS_IN_SET(['Yes', 'No'])
> > db.purchase_orders.shipto.requires = IS_IN_DB(db, db.locations.id, '%
> > (name)s',
> >         zero='Choice required')
> > db.purchase_orders.billto.requires = IS_IN_DB(db, db.locations.id, '%
> > (name)s',
> >         zero='Choice required')
> > db.purchase_orders.supplier.requires = IS_IN_DB(db, db.suppliers.id, '%
> > (name)s',
> >         zero='Choice required')
> > db.purchase_orders.del_terms.requires = IS_IN_DB(db, db.del_terms.id,
> > '%(name)s',
> >         zero='Choice required')
> > db.purchase_orders.currency.requires = IS_IN_DB(db, db.currencies.id,
> > '%(name)s',
> >         zero='Choice required')
> > db.purchase_orders.pmt_terms.requires = IS_IN_DB(db, db.pmt_terms.id,
> > '%(name)s',
> >         zero='Choice required')
> > db.purchase_orders.po_contact.requires = IS_IN_DB(
> >         db(), db.contacts.id, '%(first_name)s, %(middle_name)s, %
> > (last_name)s, %(generation)s ',
> >         zero='Choice required')
> > db.purchase_orders.ap_contact.requires = IS_IN_DB(
> >         db(), db.contacts.id, '%(first_name)s',
> >         zero='Choice required')
> > db.purchase_orders.vendor_rep.requires = IS_IN_DB(
> >         db(), db.supplier_contacts.id, '%(first_name)s',
> >         zero='Choice required')
>
> > db.define_table('suppliers',
> >     Field('name', length=256, required=True, notnull=True),
> >     Field('address', length=64),
> >     Field('address_2', length=64),
> >     Field('city', length=32),
> >     Field('state', length=24),
> >     Field('zip', length=18),
> >     Field('website', length=512, requires=IS_URL()),
> >     format = '%(name)s'
> >     )
>
> > db.define_table(
> >     'supplier_contacts',
> >     Field('supplier_id', db.suppliers),
> >     Field('first_name', length=32, required=True, notnull=True),
> >     Field('middle_name', length=32),
> >     Field('last_name', length=32, required=True, notnull=True),
> >     Field('generation', length=16),
> >     Field('email', length=512,
> >           requires=IS_EMPTY_OR(IS_EMAIL('invalid email'))),
> >     Field('mobile', length=18, label='Mobile phone'),
> >     Field('land_line', length=18),
> >     Field('fax', length=18),
> >     format='%(first_name)s, %(middle_name)s, %(last_name)s, %
> > (generation)s'
> >     )
> > db.supplier_contacts.supplier_id.requires = IS_IN_DB(
> >     db, db.suppliers.id, '%(name)s', zero='Choose'
> >     )
> > db.supplier_contacts.supplier_id.readable = False
> > db.supplier_contacts.supplier_id.writable = False
>
> > +++
> > ++
>
> > This is the actual call from the controller:
> >             # we already know the supplier_id and vendor_rep
> >             hidden['supplier']=supplier_id
> >             hidden['vendor_rep'=vendor_rep
> >             field_lst = 'issue_date number shipto billto del_terms
> > currency pmt_terms project_no taxable po_contact ap_contact
> > documentation_required'.split(' ')
> >             form = SQLTABLE(db.suppliers, fields=field_lst,
> > hidden=hidden)
>
> > On Aug 26, 8:39 am, Massimo Di Pierro 
> > wrote:
> > > Can I see the model?
>
> > > On Aug 26, 4:43 am, Cliff  wrote:
>
> > > > I use SQLFORM something like this:
>
> > > > fields = 'dog_name dog_weight dog_birtdate'.split(' ')
> > > > hidden = {'dog_owner' : some_known_value} # We alr

[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-26 Thread Anthony
Does it work if you set db.supplier_contacts.supplier_id.writable = True in 
the controller function?

On Friday, August 26, 2011 11:12:31 AM UTC-4, Cliff wrote:
>
> Massimo, 
>
> Thank you. 
>
> Of course. 
>
> Here are are the real table defs: 
> +++ 
> ++ 
> db.define_table('purchase_orders', 
> Field('issue_date', 'date'), 
> Field('number', length=24, requires=IS_NOT_EMPTY(), 
>   required=True, notnull=True, comment='Required'), 
> Field('supplier', db.suppliers), 
> Field('shipto', db.locations, label='Ship To'), 
> Field('billto', db.locations, label='Bill To'), 
> Field('del_terms', db.del_terms, label='Delivery Terms'), 
> Field('currency', db.currencies), 
> Field('pmt_terms', db.pmt_terms, label='Payment Terms'), 
> Field('project_no', length=12, label='Project Number'), 
> Field('taxable', 'list:string', default='No'), 
> Field('po_contact', db.contacts, 
> label='Purchase Order Contact'), 
> Field('ap_contact',  db.contacts, 
> label='Accounts Payable Contact'), 
> Field('vendor_rep',  db.contacts, 
> label='Vendor Representative'), 
> Field('documentation_required', 'list:reference documentation', 
> comment='Click to select.  Use Ctrl key for multiple 
> selection.') 
> ) 
> db.purchase_orders.taxable.requires = IS_IN_SET(['Yes', 'No']) 
> db.purchase_orders.shipto.requires = IS_IN_DB(db, db.locations.id, '% 
> (name)s', 
> zero='Choice required') 
> db.purchase_orders.billto.requires = IS_IN_DB(db, db.locations.id, '% 
> (name)s', 
> zero='Choice required') 
> db.purchase_orders.supplier.requires = IS_IN_DB(db, db.suppliers.id, '% 
> (name)s', 
> zero='Choice required') 
> db.purchase_orders.del_terms.requires = IS_IN_DB(db, db.del_terms.id, 
> '%(name)s', 
> zero='Choice required') 
> db.purchase_orders.currency.requires = IS_IN_DB(db, db.currencies.id, 
> '%(name)s', 
> zero='Choice required') 
> db.purchase_orders.pmt_terms.requires = IS_IN_DB(db, db.pmt_terms.id, 
> '%(name)s', 
> zero='Choice required') 
> db.purchase_orders.po_contact.requires = IS_IN_DB( 
> db(), db.contacts.id, '%(first_name)s, %(middle_name)s, % 
> (last_name)s, %(generation)s ', 
> zero='Choice required') 
> db.purchase_orders.ap_contact.requires = IS_IN_DB( 
> db(), db.contacts.id, '%(first_name)s', 
> zero='Choice required') 
> db.purchase_orders.vendor_rep.requires = IS_IN_DB( 
> db(), db.supplier_contacts.id, '%(first_name)s', 
> zero='Choice required') 
>
> db.define_table('suppliers', 
> Field('name', length=256, required=True, notnull=True), 
> Field('address', length=64), 
> Field('address_2', length=64), 
> Field('city', length=32), 
> Field('state', length=24), 
> Field('zip', length=18), 
> Field('website', length=512, requires=IS_URL()), 
> format = '%(name)s' 
> ) 
>
>
> db.define_table( 
> 'supplier_contacts', 
> Field('supplier_id', db.suppliers), 
> Field('first_name', length=32, required=True, notnull=True), 
> Field('middle_name', length=32), 
> Field('last_name', length=32, required=True, notnull=True), 
> Field('generation', length=16), 
> Field('email', length=512, 
>   requires=IS_EMPTY_OR(IS_EMAIL('invalid email'))), 
> Field('mobile', length=18, label='Mobile phone'), 
> Field('land_line', length=18), 
> Field('fax', length=18), 
> format='%(first_name)s, %(middle_name)s, %(last_name)s, % 
> (generation)s' 
> ) 
> db.supplier_contacts.supplier_id.requires = IS_IN_DB( 
> db, db.suppliers.id, '%(name)s', zero='Choose' 
> ) 
> db.supplier_contacts.supplier_id.readable = False 
> db.supplier_contacts.supplier_id.writable = False 
>
> +++ 
> ++ 
>
> This is the actual call from the controller: 
> # we already know the supplier_id and vendor_rep 
> hidden['supplier']=supplier_id 
> hidden['vendor_rep'=vendor_rep 
> field_lst = 'issue_date number shipto billto del_terms 
> currency pmt_terms project_no taxable po_contact ap_contact 
> documentation_required'.split(' ') 
> form = SQLTABLE(db.suppliers, fields=field_lst, 
> hidden=hidden) 
>
>
>
> On Aug 26, 8:39 am, Massimo Di Pierro  
> wrote: 
> > Can I see the model? 
> > 
> > On Aug 26, 4:43 am, Cliff  wrote: 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > > I use SQLFORM something like this: 
> > 
> > > fields = 'dog_name dog_weight dog_birtdate'.split(' ') 
> > > hidden = {'dog_owner' : some_known_value} # We already know who the 
> > > owner is 
> > > SQLFORM(db.dogs, fields=fields, hidden=hidden) 
> > 
> > > The hidden fields are on the form.  When I submit the form, they are 
> > > in request.vars, but SQLFOR

[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-26 Thread Cliff
Massimo,

Thank you.

Of course.

Here are are the real table defs:
+++
++
db.define_table('purchase_orders',
Field('issue_date', 'date'),
Field('number', length=24, requires=IS_NOT_EMPTY(),
  required=True, notnull=True, comment='Required'),
Field('supplier', db.suppliers),
Field('shipto', db.locations, label='Ship To'),
Field('billto', db.locations, label='Bill To'),
Field('del_terms', db.del_terms, label='Delivery Terms'),
Field('currency', db.currencies),
Field('pmt_terms', db.pmt_terms, label='Payment Terms'),
Field('project_no', length=12, label='Project Number'),
Field('taxable', 'list:string', default='No'),
Field('po_contact', db.contacts,
label='Purchase Order Contact'),
Field('ap_contact',  db.contacts,
label='Accounts Payable Contact'),
Field('vendor_rep',  db.contacts,
label='Vendor Representative'),
Field('documentation_required', 'list:reference documentation',
comment='Click to select.  Use Ctrl key for multiple
selection.')
)
db.purchase_orders.taxable.requires = IS_IN_SET(['Yes', 'No'])
db.purchase_orders.shipto.requires = IS_IN_DB(db, db.locations.id, '%
(name)s',
zero='Choice required')
db.purchase_orders.billto.requires = IS_IN_DB(db, db.locations.id, '%
(name)s',
zero='Choice required')
db.purchase_orders.supplier.requires = IS_IN_DB(db, db.suppliers.id, '%
(name)s',
zero='Choice required')
db.purchase_orders.del_terms.requires = IS_IN_DB(db, db.del_terms.id,
'%(name)s',
zero='Choice required')
db.purchase_orders.currency.requires = IS_IN_DB(db, db.currencies.id,
'%(name)s',
zero='Choice required')
db.purchase_orders.pmt_terms.requires = IS_IN_DB(db, db.pmt_terms.id,
'%(name)s',
zero='Choice required')
db.purchase_orders.po_contact.requires = IS_IN_DB(
db(), db.contacts.id, '%(first_name)s, %(middle_name)s, %
(last_name)s, %(generation)s ',
zero='Choice required')
db.purchase_orders.ap_contact.requires = IS_IN_DB(
db(), db.contacts.id, '%(first_name)s',
zero='Choice required')
db.purchase_orders.vendor_rep.requires = IS_IN_DB(
db(), db.supplier_contacts.id, '%(first_name)s',
zero='Choice required')

db.define_table('suppliers',
Field('name', length=256, required=True, notnull=True),
Field('address', length=64),
Field('address_2', length=64),
Field('city', length=32),
Field('state', length=24),
Field('zip', length=18),
Field('website', length=512, requires=IS_URL()),
format = '%(name)s'
)


db.define_table(
'supplier_contacts',
Field('supplier_id', db.suppliers),
Field('first_name', length=32, required=True, notnull=True),
Field('middle_name', length=32),
Field('last_name', length=32, required=True, notnull=True),
Field('generation', length=16),
Field('email', length=512,
  requires=IS_EMPTY_OR(IS_EMAIL('invalid email'))),
Field('mobile', length=18, label='Mobile phone'),
Field('land_line', length=18),
Field('fax', length=18),
format='%(first_name)s, %(middle_name)s, %(last_name)s, %
(generation)s'
)
db.supplier_contacts.supplier_id.requires = IS_IN_DB(
db, db.suppliers.id, '%(name)s', zero='Choose'
)
db.supplier_contacts.supplier_id.readable = False
db.supplier_contacts.supplier_id.writable = False

+++
++

This is the actual call from the controller:
# we already know the supplier_id and vendor_rep
hidden['supplier']=supplier_id
hidden['vendor_rep'=vendor_rep
field_lst = 'issue_date number shipto billto del_terms
currency pmt_terms project_no taxable po_contact ap_contact
documentation_required'.split(' ')
form = SQLTABLE(db.suppliers, fields=field_lst,
hidden=hidden)



On Aug 26, 8:39 am, Massimo Di Pierro 
wrote:
> Can I see the model?
>
> On Aug 26, 4:43 am, Cliff  wrote:
>
>
>
>
>
>
>
> > I use SQLFORM something like this:
>
> > fields = 'dog_name dog_weight dog_birtdate'.split(' ')
> > hidden = {'dog_owner' : some_known_value} # We already know who the
> > owner is
> > SQLFORM(db.dogs, fields=fields, hidden=hidden)
>
> > The hidden fields are on the form.  When I submit the form, they are
> > in request.vars, but SQLFORM does not insert them in the database.
>
> > Is this the way it's supposed to work or do I have a bug?
>
> > Thanks,
> > Cliff Kachinske


[web2py] Re: SQLFORM not handling hidden fields? Or do I have a bug?

2011-08-26 Thread Massimo Di Pierro
Can I see the model?

On Aug 26, 4:43 am, Cliff  wrote:
> I use SQLFORM something like this:
>
> fields = 'dog_name dog_weight dog_birtdate'.split(' ')
> hidden = {'dog_owner' : some_known_value} # We already know who the
> owner is
> SQLFORM(db.dogs, fields=fields, hidden=hidden)
>
> The hidden fields are on the form.  When I submit the form, they are
> in request.vars, but SQLFORM does not insert them in the database.
>
> Is this the way it's supposed to work or do I have a bug?
>
> Thanks,
> Cliff Kachinske