Re: [web2py] Re: SyntaxError: Object exists and cannot be redefined: lunid

2011-06-08 Thread Mike Veltman
 On Tuesday, June 7, 2011 2:26:45 AM UTC-4, Gwayne aka Mike Veltman wrote:
   On Monday, June 6, 2011 9:15:27 PM UTC-4, Gwayne aka Mike Veltman wrote:
And that was it...

Thank you very much. Mmmm, this should go in the book..
   
   There's also this method of pre-populating a form field:
   http://web2py.com/book/default/chapter/07#Pre-populating-the-form
  
  Yes I know, but I did read in the mailing list that that was not a smart
  idea.
 
 I wasn't aware of that. Why is it not a smart idea?
 

I am trying to find it it was actually in the mailing list a discussion about 
it and the suggestion was to use the default. 

  Also those vars do not exist before I create the form. So you would get a
  error if you do so.
 
 But is there any reason you couldn't make the assignment right after the
 form is created (i.e., instead of assigning a new default right before the
 form creation, assign a value to the form var right after creation)?
 
 Anthony

Maybe I just do it plain wrong :-)

form = SQLFORM(db.lvstorage)
form.vars.lunid = 2 # Does not work

Thats how I did it.

Now I have a complicated system :) My goal is/was to make the lunid 
autoincrement with each submit.

Now I use this (btw I am not a programmer so, suggestions are always welcome.)

  if not request.vars.newrecord: # For the newrecord button 
newrecord = False

if request.vars.newrecord: # For the newrecord button
session.lunid = 2   
newrecord = True
 
if not request.args or newrecord == True:  # If called directly from 
menu or newmenu button

if session.lunid == 2:
# Default settings for the page
db.lvstorage.lunid.default = 2
db.lvstorage.setup_id.default = 1
db.lvstorage.lvsize_id.default = 2
db.lvstorage.storagemap_id.default = 1  
session.setup_id = 1
session.storagemap_id = 1
session.lvsize_id = 2  

else:  
if session.lunid == 31: # Lunid 31 is managed by the 
controller so skip it
session.lunid = 32

if request.vars.setup_id : # To make sure that if the var does 
not exist it will not change the session var
session.setup_id = request.vars.setup_id
if request.vars.lvsize_id :
session.lvsize_id = request.vars.lvsize_id
if request.vars.storagemap_id :
session.storagemap_id = request.vars.storagemap_id

db.lvstorage.lunid.default = int(session.lunid)
db.lvstorage.setup_id.default = session.setup_id
db.lvstorage.lvsize_id.default = session.lvsize_id
db.lvstorage.storagemap_id.default = session.storagemap_id

if request.vars.checkbox: # If checkbox is used do not increase 
lunid
pass
else: 
session.lunid = int(session.lunid) + 1 # Increase lun id

form = SQLFORM(db.lvstorage)

With regards,
Mike Veltman




[web2py] Re: SyntaxError: Object exists and cannot be redefined: lunid

2011-06-07 Thread Mike Veltman
 On Monday, June 6, 2011 9:15:27 PM UTC-4, Gwayne aka Mike Veltman wrote:
  And that was it...
  
  Thank you very much. Mmmm, this should go in the book..
 
 There's also this method of pre-populating a form field:
 http://web2py.com/book/default/chapter/07#Pre-populating-the-form

Yes I know, but I did read in the mailing list that that was not a smart idea.

Also those vars do not exist before I create the form. So you would get a 
error if you do so.

I still have one problem that if I do keepvalues=True it will not override. So 
there I probably have to use the form.vars.name = fieldvalue trick

Lets test that.


With regards,
Mike Veltman




Re: [web2py] Re: SyntaxError: Object exists and cannot be redefined: lunid

2011-06-07 Thread Anthony
On Tuesday, June 7, 2011 2:26:45 AM UTC-4, Gwayne aka Mike Veltman wrote: 

  On Monday, June 6, 2011 9:15:27 PM UTC-4, Gwayne aka Mike Veltman wrote:
   And that was it...
   
   Thank you very much. Mmmm, this should go in the book..
  
  There's also this method of pre-populating a form field:
  http://web2py.com/book/default/chapter/07#Pre-populating-the-form 

 Yes I know, but I did read in the mailing list that that was not a smart 
 idea.

I wasn't aware of that. Why is it not a smart idea?
 

 Also those vars do not exist before I create the form. So you would get a 
 error if you do so.

But is there any reason you couldn't make the assignment right after the 
form is created (i.e., instead of assigning a new default right before the 
form creation, assign a value to the form var right after creation)?
 
Anthony


  

[web2py] Re: SyntaxError: Object exists and cannot be redefined: lunid

2011-06-06 Thread Massimo Di Pierro
db.lvstorage.lunid = 4

should be (I guess)

db.lvstorage.lunid.default = 4

On Jun 6, 4:12 am, Mike Veltman mike.velt...@gmail.com wrote:
 I try to pre populate a form and I think I do something wrong but I stare at
 it for a long time and what I do wrong still does not show up.

 So maybe some people can make my day better.

 Error:

 1.
 2.
 3.
 4.
 5.
 6.
 7.
 8.
 9.
 10.
 11.
 12.
 13.
 Traceback (most recent call last):
   File 
 /home/mv1965/Documents/development/eclipse/adsw2p/gluon/restricted.py, line 
 184, in restricted
     exec ccode in environment
   File 
 /home/mv1965/Documents/development/eclipse/adsw2p/applications/adeploy/com 
 piled/controllers_formdb_test_manage_lvstorage.py, line 342, in module
   File /home/mv1965/Documents/development/eclipse/adsw2p/gluon/globals.py, 
 line 137, in lambda
     self._caller = lambda f: f()
   File /home/mv1965/Documents/development/eclipse/adsw2p/gluon/tools.py, 
 line 2452, in f
     return action(*a, **b)
   File 
 /home/mv1965/Documents/development/eclipse/adsw2p/applications/adeploy/com 
 piled/controllers_formdb_test_manage_lvstorage.py, line 58, in 
 test_manage_lvstorage
   File /home/mv1965/Documents/development/eclipse/adsw2p/gluon/dal.py, line 
 4630, in __setattr__
     raise SyntaxError, 'Object exists and cannot be redefined: %s' % key
 SyntaxError: Object exists and cannot be redefined: lunid

 Controller

 @auth.requires_login()
 def test_manage_lvstorage():

         db.lvstorage.lunid = 4  
         form = SQLFORM(db.lvstorage)
         return dict(form=form)

 # Logical volume on storage
 db.define_table('lvstorage',

     Field('setup_id', db.setup,
           default=1,
           label=T('Setup ID')),
     Field('lvsize_id', db.lvsize,
           default=2,
           label=T('Size ID')),
     Field('lunid', type='integer',
           default=2,
           label=T('Lun ID')),
     Field('storagemap_id', db.storagemap,
           default=1,
           label=T('Host Group')),
     Field('created_on','datetime',default=request.now,
           label=T('Created On'),writable=False,readable=False),
     Field('modified_on','datetime',default=request.now,
           label=T('Modified On'),writable=False,readable=False,
           update=request.now),
     migrate=settings.migrate)

 # Table rules
 db.lvstorage.setup_id.requires = IS_IN_DB(db, 'setup.id', 'setup.setupname')
 db.lvstorage.lvsize_id.requires = IS_IN_DB(db, 'lvsize.id', 'lvsize.sizename')
 db.lvstorage.storagemap_id.requires = IS_IN_DB(db, 'storagemap.id',
 'storagemap.mapping')
 db.lvstorage.lunid.requires =
 IS_IN_SET([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25, 
 26,27,28,29,30,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51, 
 52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70])


[web2py] Re: SyntaxError: Object exists and cannot be redefined: lunid

2011-06-06 Thread Mike Veltman

And that was it...

Thank you very much. Mmmm, this should go in the book..


 db.lvstorage.lunid = 4
 
 should be (I guess)
 
 db.lvstorage.lunid.default = 4
 
 On Jun 6, 4:12 am, Mike Veltman mike.velt...@gmail.com wrote:
  I try to pre populate a form and I think I do something wrong but I stare
  at it for a long time and what I do wrong still does not show up.
  
  So maybe some people can make my day better.
  
  Error:
  
  1.
  2.
  3.
  4.
  5.
  6.
  7.
  8.
  9.
  10.
  11.
  12.
  13.
  Traceback (most recent call last):
File
  /home/mv1965/Documents/development/eclipse/adsw2p/gluon/restricted.py,
  line 184, in restricted exec ccode in environment
File
  /home/mv1965/Documents/development/eclipse/adsw2p/applications/adeploy/
  com piled/controllers_formdb_test_manage_lvstorage.py, line 342, in
  module File
  /home/mv1965/Documents/development/eclipse/adsw2p/gluon/globals.py,
  line 137, in lambda self._caller = lambda f: f()
File
  /home/mv1965/Documents/development/eclipse/adsw2p/gluon/tools.py, line
  2452, in f return action(*a, **b)
File
  /home/mv1965/Documents/development/eclipse/adsw2p/applications/adeploy/
  com piled/controllers_formdb_test_manage_lvstorage.py, line 58, in
  test_manage_lvstorage File
  /home/mv1965/Documents/development/eclipse/adsw2p/gluon/dal.py, line
  4630, in __setattr__ raise SyntaxError, 'Object exists and cannot be
  redefined: %s' % key SyntaxError: Object exists and cannot be redefined:
  lunid
  
  Controller
  
  @auth.requires_login()
  def test_manage_lvstorage():
  
  db.lvstorage.lunid = 4  
  form = SQLFORM(db.lvstorage)
  return dict(form=form)
  
  # Logical volume on storage
  db.define_table('lvstorage',
  
  Field('setup_id', db.setup,
default=1,
label=T('Setup ID')),
  Field('lvsize_id', db.lvsize,
default=2,
label=T('Size ID')),
  Field('lunid', type='integer',
default=2,
label=T('Lun ID')),
  Field('storagemap_id', db.storagemap,
default=1,
label=T('Host Group')),
  Field('created_on','datetime',default=request.now,
label=T('Created On'),writable=False,readable=False),
  Field('modified_on','datetime',default=request.now,
label=T('Modified On'),writable=False,readable=False,
update=request.now),
  migrate=settings.migrate)
  
  # Table rules
  db.lvstorage.setup_id.requires = IS_IN_DB(db, 'setup.id',
  'setup.setupname') db.lvstorage.lvsize_id.requires = IS_IN_DB(db,
  'lvsize.id', 'lvsize.sizename') db.lvstorage.storagemap_id.requires =
  IS_IN_DB(db, 'storagemap.id', 'storagemap.mapping')
  db.lvstorage.lunid.requires =
  IS_IN_SET([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,2
  5,
  26,27,28,29,30,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,
  51, 52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70])

With regards,
Mike Veltman




Re: [web2py] Re: SyntaxError: Object exists and cannot be redefined: lunid

2011-06-06 Thread Anthony
On Monday, June 6, 2011 9:15:27 PM UTC-4, Gwayne aka Mike Veltman wrote: 


 And that was it... 

 Thank you very much. Mmmm, this should go in the book..

 
There's also this method of pre-populating a form field: 
http://web2py.com/book/default/chapter/07#Pre-populating-the-form