[web2py] Re: SQLFORM.factory and list:integer error

2013-06-20 Thread Martin Barnard
That code listing is from dal.py. I didn't really want to poke too much at 
that as I haven't had time to examine it too deeply. 

I should probably upgrade to latest web2py before trying anything else :)

*/scurries off to upgrade the server...*

On Thursday, June 20, 2013 12:45:28 AM UTC+3, Niphlod wrote:

 it's a bug reproduceable only if you leave one empty field.
 BTW, you're parsing it wrong given a single field filled with 1234, 
 you get [1,2,3,4] back.

 you should do

 vars = form.vars.employees
 if vars:
 if isinstance(vars, (list, tuple)):
 for a in vars:
 ids.append(a)
 else:
 ids.append(vars)

 Anyway, I'll submit an issue with the fix.


- 









-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: SQLFORM.factory and list:integer error

2013-06-20 Thread Martin Barnard
Upgraded, but the error is still there. It's failing at the SQLFORM 
validation in dal.py, I don't even get the chance to access session 
variables myself. Also, list:integer fields leave an empty field behind

Is there a way from within the DAL to remove empty entries on list:integer 
(as I can't rely on my users to not create empty entries when using the 
form)?

def index():


form=SQLFORM.factory(
Field('employees', 'list:integer' ),
)
my_emps=[]
if form.process(session=None).accepted:
mvars=form.vars.employees
if mvars:
response.flash=myvars
for a in mvars:
my_emps.append(a)
else:
my_emps.append(mvars)

return dict(form=form, my_emps=my_emps)


Error:


Traceback (most recent call last):
  File /home/www-data/web2py/gluon/restricted.py, line 212, in restricted
exec ccode in environment
  File /home/www-data/web2py/applications/experiment/controllers/default.py, 
line 196, in module
  File /home/www-data/web2py/gluon/globals.py, line 194, in lambda
self._caller = lambda f: f()
  File /home/www-data/web2py/applications/experiment/controllers/default.py, 
line 127, in index
if form.process(session=None).accepted:
  File /home/www-data/web2py/gluon/html.py, line 2188, in process
self.validate(**kwargs)
  File /home/www-data/web2py/gluon/html.py, line 2127, in validate
if self.accepts(**kwargs):
  File /home/www-data/web2py/gluon/sqlhtml.py, line 1571, in accepts
self.vars.id = self.table.insert(**fields)
  File /home/www-data/web2py/gluon/dal.py, line 8598, in insert
ret =  self._db._adapter.insert(self, self._listify(fields))
  File /home/www-data/web2py/gluon/dal.py, line 1203, in insert
query = self._insert(table,fields)
  File /home/www-data/web2py/gluon/dal.py, line 1194, in _insert
values = ','.join(self.expand(v, f.type) for f, v in fields)
  File /home/www-data/web2py/gluon/dal.py, line 1194, in genexpr
values = ','.join(self.expand(v, f.type) for f, v in fields)
  File /home/www-data/web2py/gluon/dal.py, line 1376, in expand
return str(self.represent(expression,field_type))
  File /home/www-data/web2py/gluon/dal.py, line 1805, in represent
obj = map(int,obj)
ValueError: invalid literal for int() with base 10: ''







On Thursday, June 20, 2013 2:31:51 PM UTC+3, Martin Barnard wrote:

 That code listing is from dal.py. I didn't really want to poke too much at 
 that as I haven't had time to examine it too deeply. 

 I should probably upgrade to latest web2py before trying anything else :)

 */scurries off to upgrade the server...*

 On Thursday, June 20, 2013 12:45:28 AM UTC+3, Niphlod wrote:

 it's a bug reproduceable only if you leave one empty field.
 BTW, you're parsing it wrong given a single field filled with 1234, 
 you get [1,2,3,4] back.

 you should do

 vars = form.vars.employees
 if vars:
 if isinstance(vars, (list, tuple)):
 for a in vars:
 ids.append(a)
 else:
 ids.append(vars)

 Anyway, I'll submit an issue with the fix.


- 









-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: SQLFORM.factory and list:integer error

2013-06-20 Thread Niphlod
you upgraded, but the patch isn't there. as you may notice, the exception 
raises at the exact same line as before.

I just sent an email to Massimo to let him know that ATM the fix isn't in 
trunk

http://code.google.com/p/web2py/issues/detail?id=1547

On Thursday, June 20, 2013 4:29:51 PM UTC+2, Martin Barnard wrote:

 Upgraded, but the error is still there. It's failing at the SQLFORM 
 validation in dal.py, I don't even get the chance to access session 
 variables myself. Also, list:integer fields leave an empty field behind

 Is there a way from within the DAL to remove empty entries on list:integer 
 (as I can't rely on my users to not create empty entries when using the 
 form)?

 def index():
 
 
 form=SQLFORM.factory(
 Field('employees', 'list:integer' ),
 )
 my_emps=[]
 if form.process(session=None).accepted:
 mvars=form.vars.employees
 if mvars:
 response.flash=myvars
 for a in mvars:
 my_emps.append(a)
 else:
 my_emps.append(mvars)

 return dict(form=form, my_emps=my_emps)


 Error:


 Traceback (most recent call last):
   File /home/www-data/web2py/gluon/restricted.py, line 212, in restricted
 exec ccode in environment
   File 
 /home/www-data/web2py/applications/experiment/controllers/default.py, line 
 196, in module
   File /home/www-data/web2py/gluon/globals.py, line 194, in lambda
 self._caller = lambda f: f()
   File 
 /home/www-data/web2py/applications/experiment/controllers/default.py, line 
 127, in index
 if form.process(session=None).accepted:
   File /home/www-data/web2py/gluon/html.py, line 2188, in process
 self.validate(**kwargs)
   File /home/www-data/web2py/gluon/html.py, line 2127, in validate
 if self.accepts(**kwargs):
   File /home/www-data/web2py/gluon/sqlhtml.py, line 1571, in accepts
 self.vars.id = self.table.insert(**fields)
   File /home/www-data/web2py/gluon/dal.py, line 8598, in insert
 ret =  self._db._adapter.insert(self, self._listify(fields))
   File /home/www-data/web2py/gluon/dal.py, line 1203, in insert
 query = self._insert(table,fields)
   File /home/www-data/web2py/gluon/dal.py, line 1194, in _insert
 values = ','.join(self.expand(v, f.type) for f, v in fields)
   File /home/www-data/web2py/gluon/dal.py, line 1194, in genexpr
 values = ','.join(self.expand(v, f.type) for f, v in fields)
   File /home/www-data/web2py/gluon/dal.py, line 1376, in expand
 return str(self.represent(expression,field_type))
   File /home/www-data/web2py/gluon/dal.py, line 1805, in represent
 obj = map(int,obj)
 ValueError: invalid literal for int() with base 10: ''







 On Thursday, June 20, 2013 2:31:51 PM UTC+3, Martin Barnard wrote:

 That code listing is from dal.py. I didn't really want to poke too much 
 at that as I haven't had time to examine it too deeply. 

 I should probably upgrade to latest web2py before trying anything else :)

 */scurries off to upgrade the server...*

 On Thursday, June 20, 2013 12:45:28 AM UTC+3, Niphlod wrote:

 it's a bug reproduceable only if you leave one empty field.
 BTW, you're parsing it wrong given a single field filled with 1234, 
 you get [1,2,3,4] back.

 you should do

 vars = form.vars.employees
 if vars:
 if isinstance(vars, (list, tuple)):
 for a in vars:
 ids.append(a)
 else:
 ids.append(vars)

 Anyway, I'll submit an issue with the fix.


- 









-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: SQLFORM.factory and list:integer error

2013-06-19 Thread Niphlod
it's a bug reproduceable only if you leave one empty field.
BTW, you're parsing it wrong given a single field filled with 1234, you 
get [1,2,3,4] back.

you should do

vars = form.vars.employees
if vars:

if form.vars.employees:
 if  

On Wednesday, June 19, 2013 8:22:52 PM UTC+2, Martin Barnard wrote:

 I'm trying to figure out why I get an error with the following code:

 def index():
 ids=[]
 form=SQLFORM.factory(
 Field('employees', 'list:integer'),
 )
 if form.process().accepts:
 if form.vars.employees:
 for v in form.vars.employees:
 ids.append(v)


 Generally gives me a typerror: 
 type 'exceptions.ValueError' invalid literal for int() with base 10: ''
 which is pointing to: web2py/gluon/dal.py, line 1779, in represent


 172.16.180.10.2013-06-19.21-09-19.05836ac3-19f9-486a-9cae-a121a7c19593
 type 'exceptions.ValueError' invalid literal for int() with base 10: ''
 VERSIONweb2py™(2, 4, 2, 'stable', datetime.datetime(2013, 3, 4, 3, 26, 
 21))PythonPython 2.7.3: /usr/bin/python (prefix: /usr)TRACEBACK

 1.
 2.
 3.
 4.
 5.
 6.
 7.
 8.
 9.
 10.
 11.
 12.
 13.
 14.
 15.
 16.
 17.
 18.
 19.
 20.
 21.
 22.
 23.
 24.

 Traceback (most recent call last):
   File /home/www-data/web2py/gluon/restricted.py, line 212, in restricted
 exec ccode in environment
   File /home/www-data/web2py/applications/experiment/controllers/default.py 
 https://172.16.180.11/admin/default/edit/experiment/controllers/default.py, 
 line 193, in module
   File /home/www-data/web2py/gluon/globals.py, line 193, in lambda
 self._caller = lambda f: f()
   File /home/www-data/web2py/applications/experiment/controllers/default.py 
 https://172.16.180.11/admin/default/edit/experiment/controllers/default.py, 
 line 128, in index
 if form.accepts(request.vars):
   File /home/www-data/web2py/gluon/sqlhtml.py, line 1528, in accepts
 self.vars.id = self.table.insert(**fields)
   File /home/www-data/web2py/gluon/dal.py, line 8442, in insert
 ret =  self._db._adapter.insert(self, self._listify(fields))
   File /home/www-data/web2py/gluon/dal.py, line 1199, in insert
 query = self._insert(table,fields)
   File /home/www-data/web2py/gluon/dal.py, line 1190, in _insert
 values = ','.join(self.expand(v, f.type) for f, v in fields)
   File /home/www-data/web2py/gluon/dal.py, line 1190, in genexpr
 values = ','.join(self.expand(v, f.type) for f, v in fields)
   File /home/www-data/web2py/gluon/dal.py, line 1366, in expand
 return str(self.represent(expression,field_type))
   File /home/www-data/web2py/gluon/dal.py, line 1779, in represent
 obj = map(int,obj)
 ValueError: invalid literal for int() with base 10: ''

 ERROR SNAPSHOT [image: help]

 type 'exceptions.ValueError'(invalid literal for int() with base 10: '')

 inspect attributes
 Frames

- 

*File /home/www-data/web2py/gluon/restricted.py in restricted at line 
212* code arguments variables
- 

*File 
/home/www-data/web2py/applications/experiment/controllers/default.py in 
module at line 193* code arguments variables
- 

*File /home/www-data/web2py/gluon/globals.py in lambda at line 193* 
code arguments variables
- 

*File 
/home/www-data/web2py/applications/experiment/controllers/default.py in 
index at line 128* code arguments variables
- 

*File /home/www-data/web2py/gluon/sqlhtml.py in accepts at line 1528* 
code arguments variables
- 

*File /home/www-data/web2py/gluon/dal.py in insert at line 8442* code 
arguments variables
- 

*File /home/www-data/web2py/gluon/dal.py in insert at line 1199* code 
arguments variables
- 

*File /home/www-data/web2py/gluon/dal.py in _insert at line 1190* code 
arguments variables
- 

*File /home/www-data/web2py/gluon/dal.py in genexpr at line 1190* 
code arguments variables
- 

*File /home/www-data/web2py/gluon/dal.py in expand at line 1366* code 
arguments variables
- 

*File /home/www-data/web2py/gluon/dal.py in represent at line 1779* 
code arguments variables
Function argument list

(self=gluon.dal.BaseAdapter object, obj=['4004', ''], 
fieldtype='list:integer')
Code listing

1774.
1775.
1776.
1777.
1778.
1779.

1780.
1781.
1782.
1783.

elif not isinstance(obj, (list, tuple)):
obj = [obj]
if field_is_type('list:string'):
obj = map(str,obj)
else:
obj = map(int,obj)

# we don't want to bar_encode json objects
if isinstance(obj, (list, tuple)) and (not fieldtype == json):
obj = bar_encode(obj)
if obj is None:

Variablesbuiltininttype 'int'obj['4004', '']builtinmapbuilt-in 
function map



-- 

--- 
You received this