[web2py] Re: Set username as default

2012-02-07 Thread Ross Peoples
I usually do this:

default = auth.user.username.upper() if auth.user else None


[web2py] Re: Set username as default

2012-02-07 Thread Massimo Di Pierro
db.IQWAGFTY.TYUUSR.default=dba.auth_user(auth.user_id).username.upper()





On Feb 7, 1:31 pm, Omi Chiba ochib...@gmail.com wrote:
 I want to set username (Not id) to table when the record is created
 using import_from_csv_file.
 The following model cause error because when you open the website
 auth.user_id is None.

 Can we set if statement says auth.user_id !=none,
 dba.auth_user(auth.user_id).username.upper() else  ?

 Model
 ---
 db.define_table('IQWAGFTY',
     Field('TYPRCD', length=15),
     Field('TYUUSR', length=128,
 default=dba.auth_user(auth.user_id).username.upper()),
     Field('TYUDAT', 'datetime', default=request.now),
     primarykey=['TYPRCD'])

 I added the following after the table definition but strangely,
 import_from_csv_file doesn't pick up the default value if it's
 defined after define_table.

 if (auth.user_id != None):

 db.IQWAGFTY.default=dba.auth_user(auth.user_id).username.upper()


[web2py] Re: Set username as default

2012-02-07 Thread Omi Chiba
Thank you both !!
It works perfectly.

On Feb 7, 1:36 pm, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 db.IQWAGFTY.TYUUSR.default=dba.auth_user(auth.user_id).username.upper()

 On Feb 7, 1:31 pm, Omi Chiba ochib...@gmail.com wrote:







  I want to set username (Not id) to table when the record is created
  using import_from_csv_file.
  The following model cause error because when you open the website
  auth.user_id is None.

  Can we set if statement says auth.user_id !=none,
  dba.auth_user(auth.user_id).username.upper() else  ?

  Model
  ---
  db.define_table('IQWAGFTY',
      Field('TYPRCD', length=15),
      Field('TYUUSR', length=128,
  default=dba.auth_user(auth.user_id).username.upper()),
      Field('TYUDAT', 'datetime', default=request.now),
      primarykey=['TYPRCD'])

  I added the following after the table definition but strangely,
  import_from_csv_file doesn't pick up the default value if it's
  defined after define_table.

  if (auth.user_id != None):

  db.IQWAGFTY.default=dba.auth_user(auth.user_id).username.upper()