Re: [web2py] Re: bug in SQLFORM.factory?

2010-01-27 Thread Frederik Wagner
Hi,

both version do save a None (actually all form.accepts, FORM.accepts,
SQLFORM.accepts do).

Wouldn't be the correct behavior to consistently and always convert a
False value to 'F'? Am I missing something?

Thanks a lot!
Frederik

On Wed, Jan 27, 2010 at 4:59 PM, mdipierro mdipie...@cs.depaul.edu wrote:
 On a second look I believe FORM.accepts behave correctly. Since it is
 not supposed to convert None to 'F'. Only SQLFORM.accepts does that.

 On Jan 27, 8:24 am, mdipierro mdipie...@cs.depaul.edu wrote:
 Why

 def test1():
 form=SQLFORM.factory(Field(bool,boolean))

 if FORM.accepts(form, request.vars, session, keepvalues=True):
 db.test.insert(bool=request.vars.bool)

 return dict(form=form,list=db().select(db.test.ALL))

 and not

 def test1():
 form=SQLFORM.factory(Field(bool,boolean))

 if form.accepts(request.vars, session, keepvalues=True):
 db.test.insert(bool=request.vars.bool)

 return dict(form=form,list=db().select(db.test.ALL))

 ?

 Please check the latter, it should work fine. I check why the former
 does not.

 On Jan 27, 1:50 am, Frederik Wagner fner...@googlemail.com wrote:

  Hi .*,

  it seems to me that there is a bug saving boolean fields with
  SQLFORM.factory forms.
  If I define a boolean field in a table and use the standard SQLFORM to
  make an input form, the accept function will save 'T' of 'F' to the
  DB.
  Whereas in the case where I create a form with SQLFORM.factory, do a
  FORM.accept and an explicit db.insert, instead of 'F' there will be a
  NULL on the DB.

  Here a test setup:

  DB:
  db.define_table('test',Field('bool','boolean'))

  CONTROLLER:
  def test1():
  form=SQLFORM.factory(Field(bool,boolean))

  if FORM.accepts(form, request.vars, session, keepvalues=True):
  db.test.insert(bool=request.vars.bool)

  return dict(form=form,list=db().select(db.test.ALL))

  def test2():
  form=SQLFORM(db.test)

  if form.accepts(request.vars, session, keepvalues=True):
  response.flash = 'done'

  return dict(form=form,list=db().select(db.test.ALL))

  test1 gives 'True' ('T') and 'None' (NULL) and test2 'True' ('T') and
  'False' ('F').

  A bug or my problem? :-)

  Bye
  Frederik



 --
 You received this message because you are subscribed to the Google Groups 
 web2py-users group.
 To post to this group, send email to web...@googlegroups.com.
 To unsubscribe from this group, send email to 
 web2py+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/web2py?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] bug in SQLFORM.factory?

2010-01-26 Thread Frederik Wagner
Hi .*,

it seems to me that there is a bug saving boolean fields with
SQLFORM.factory forms.
If I define a boolean field in a table and use the standard SQLFORM to
make an input form, the accept function will save 'T' of 'F' to the
DB.
Whereas in the case where I create a form with SQLFORM.factory, do a
FORM.accept and an explicit db.insert, instead of 'F' there will be a
NULL on the DB.

Here a test setup:

DB:
db.define_table('test',Field('bool','boolean'))

CONTROLLER:
def test1():
form=SQLFORM.factory(Field(bool,boolean))

if FORM.accepts(form, request.vars, session, keepvalues=True):
db.test.insert(bool=request.vars.bool)

return dict(form=form,list=db().select(db.test.ALL))


def test2():
form=SQLFORM(db.test)

if form.accepts(request.vars, session, keepvalues=True):
response.flash = 'done'

return dict(form=form,list=db().select(db.test.ALL))


test1 gives 'True' ('T') and 'None' (NULL) and test2 'True' ('T') and
'False' ('F').

A bug or my problem? :-)

Bye
Frederik

-- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py:35612] mySQL and ON DELETE RESTRICT

2009-11-19 Thread Frederik Wagner

Hi,

it might be that I'm missing something, but:t
In a table definition I'm using a foreign key reference with the
ondelete='RESTRICT'. Following the sql.log and the Table schemes on
the DB, this is correctly used in the CREATE TABLE statements
.
When I'm inserting some data with references and then delete the
referenced data set (let's say a Table 'domain' and a 'host' which has
a reference to 'domain', then deleting a 'domain' entry)., I do not
get errors through web2py complaining that there are references left:

1. using SQLlite: web2py and on sqlite interface the referenced entry
is deleted without complaint.
2. using MySQL: web2py does delete the entry, but the cmdline of MySQL
gives an error as expected.

So how can web2py override the MySQL database constrain of ON DELETE RESTRICT?
For SQLlite is suppose it is just a missing feature in SQLlite...

Thanks for help,
Frederik

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~--~~~~--~~--~--~---



[web2py:35071] Re: Validator IS_IN_DB display string from joined tables

2009-11-11 Thread Frederik Wagner

great! thanks a lot!

On Tue, Nov 10, 2009 at 6:20 PM, mdipierro mdipie...@cs.depaul.edu wrote:

 It seems I was wrong. This is not possible but not diffciult to
 implement. Give me a couple of days.

 On Nov 10, 10:15 am, Frederik Wagner fner...@googlemail.com wrote:
 thanks for the fast reply, but it does not work for me



 On Tue, Nov 10, 2009 at 3:45 PM, mdipierro mdipie...@cs.depaul.edu wrote:

  Yes you can do it with a bit of extra work:

  db.define_table('person',Field('name'))
  db.define_table('dog',Field('name'),Field('owner',db.person))
  db.define_table('walk',Field('dog',db.dog),Field('when','datetime'))

  db.dog.owner.requires = IS_IN_DB(db,'person.id','%(name)s')
  class ComputedDogAttributes:
 def owner_name(dog): return dog.owner.name
  db.dog.virtualfields.append(ComputedDogAttributes())
  db.walk.dog.requires = IS_IN_DB(db,'dog.id','%(name)s by %(owner_name)
  s')

  Actually I have not tried it. If you do please let us know.

 trying to insert a walk (after inserting a person and a walk), gives

 Traceback (most recent call last):
   File /root/web2py/gluon/restricted.py, line 184, in restricted
 exec ccode in environment
   File /root/web2py/applications/test/controllers/appadmin.py, line
 304, in module
   File /root/web2py/gluon/globals.py, line 103, in lambda
 self._caller = lambda f: f()
   File /root/web2py/applications/test/controllers/appadmin.py, line
 123, in insert
 form = SQLFORM(db[table], ignore_rw=ignore_rw)
   File /root/web2py/gluon/sqlhtml.py, line 613, in __init__
 inp = self.widgets.options.widget(field, default)
   File /root/web2py/gluon/sqlhtml.py, line 199, in widget
 options = requires0.options()
   File /root/web2py/gluon/validators.py, line 346, in options
 self.build_set()
   File /root/web2py/gluon/validators.py, line 333, in build_set
 records = self.dbset.select(*self.fields, **dd)
   File /root/web2py/gluon/sql.py, line 2901, in select
 rows = response(query)
   File /root/web2py/gluon/sql.py, line 2896, in response
 db._execute(query)
   File /root/web2py/gluon/sql.py, line 846, in lambda
 self._execute = lambda *a, **b: self._cursor.execute(*a, **b)
 OperationalError: no such column: dog.owner_name

 Actually, why is it not possible to do a
 db.walk.dog.requires = IS_IN_DB(db,'dog.id','%(name)s by %(owner.name)s')
 directly?

 probably I'm missing some python knowledge.

 Thanks
 Frederik



  On Nov 10, 4:35 am, Frederik Wagner fner...@googlemail.com wrote:
  Hi .*,

  is there a possibility in the Validator IS_IN_DB to have the display
  string show attributes from multiple (joined) tables?
  E.g.: If I  say somthing like

  IS_IN_DB( db( (table1.id == table2.id_table1) , 'table1.id',
  '%(table1.attribute)s %(table2.attribute)s')

  It tried somthing like this, but the problem is, that the placeholder
  are always assumed to be attributes of the table used in the second
  parameterfield, here 'table1'. Such that the used attributes are
  'table1.table1.attribute' and 'table1.table2.attribute', which is
  clearly an error.

  I hope I could make the problem clear?

  Thanks a lot for help.
  Bye!
  Frederik
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~--~~~~--~~--~--~---



[web2py:35075] borken IPV4 validator?

2009-11-11 Thread Frederik Wagner

Hi .*,

I already filed it as a bug some days ago, but should have ask here
before. Could it be, that the IS_IPV4 provider validates erroneous
IPv4's?

Reproduction in the shell:
1. type:
  a=IS_IPV4()
2. type e.g.:
  a('123.123')
which gives a validated output ('123.123', None), also an IP like
'123.1123' is valid!
I would have expect to see a ('123.123', 'enter valid IPv4 address').

I'm using web2py 1.72.3 (on Linux)

Thanks and bye,
Frederik

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~--~~~~--~~--~--~---



[web2py:35093] Re: borken IPV4 validator?

2009-11-11 Thread Frederik Wagner

On Wed, Nov 11, 2009 at 5:15 PM, Jonathan Lundell jlund...@pobox.com wrote:

 On Nov 11, 2009, at 2:32 AM, Frederik Wagner wrote:

 I already filed it as a bug some days ago, but should have ask here
 before. Could it be, that the IS_IPV4 provider validates erroneous
 IPv4's?

 Reproduction in the shell:
 1. type:
  a=IS_IPV4()
 2. type e.g.:
  a('123.123')
 which gives a validated output ('123.123', None), also an IP like
 '123.1123' is valid!
 I would have expect to see a ('123.123', 'enter valid IPv4 address').

 I'm using web2py 1.72.3 (on Linux)

 There's a bug in the regex. At the very least, the period needs to be escaped 
 (\.).

perfect, thanks again...


 Massimo, if you want to make that patch, go ahead. I'll make up a set of 
 doctests that also test the min/max conditions and get them to you later.
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~--~~~~--~~--~--~---



[web2py:35012] Validator IS_IN_DB display string from joined tables

2009-11-10 Thread Frederik Wagner

Hi .*,

is there a possibility in the Validator IS_IN_DB to have the display
string show attributes from multiple (joined) tables?
E.g.: If I  say somthing like

IS_IN_DB( db( (table1.id == table2.id_table1) , 'table1.id',
'%(table1.attribute)s %(table2.attribute)s')

It tried somthing like this, but the problem is, that the placeholder
are always assumed to be attributes of the table used in the second
parameterfield, here 'table1'. Such that the used attributes are
'table1.table1.attribute' and 'table1.table2.attribute', which is
clearly an error.

I hope I could make the problem clear?

Thanks a lot for help.
Bye!
Frederik

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~--~~~~--~~--~--~---



[web2py:35035] Re: Validator IS_IN_DB display string from joined tables

2009-11-10 Thread Frederik Wagner

thanks for the fast reply, but it does not work for me

On Tue, Nov 10, 2009 at 3:45 PM, mdipierro mdipie...@cs.depaul.edu wrote:

 Yes you can do it with a bit of extra work:

 db.define_table('person',Field('name'))
 db.define_table('dog',Field('name'),Field('owner',db.person))
 db.define_table('walk',Field('dog',db.dog),Field('when','datetime'))

 db.dog.owner.requires = IS_IN_DB(db,'person.id','%(name)s')
 class ComputedDogAttributes:
def owner_name(dog): return dog.owner.name
 db.dog.virtualfields.append(ComputedDogAttributes())
 db.walk.dog.requires = IS_IN_DB(db,'dog.id','%(name)s by %(owner_name)
 s')

 Actually I have not tried it. If you do please let us know.

trying to insert a walk (after inserting a person and a walk), gives

Traceback (most recent call last):
  File /root/web2py/gluon/restricted.py, line 184, in restricted
exec ccode in environment
  File /root/web2py/applications/test/controllers/appadmin.py, line
304, in module
  File /root/web2py/gluon/globals.py, line 103, in lambda
self._caller = lambda f: f()
  File /root/web2py/applications/test/controllers/appadmin.py, line
123, in insert
form = SQLFORM(db[table], ignore_rw=ignore_rw)
  File /root/web2py/gluon/sqlhtml.py, line 613, in __init__
inp = self.widgets.options.widget(field, default)
  File /root/web2py/gluon/sqlhtml.py, line 199, in widget
options = requires0.options()
  File /root/web2py/gluon/validators.py, line 346, in options
self.build_set()
  File /root/web2py/gluon/validators.py, line 333, in build_set
records = self.dbset.select(*self.fields, **dd)
  File /root/web2py/gluon/sql.py, line 2901, in select
rows = response(query)
  File /root/web2py/gluon/sql.py, line 2896, in response
db._execute(query)
  File /root/web2py/gluon/sql.py, line 846, in lambda
self._execute = lambda *a, **b: self._cursor.execute(*a, **b)
OperationalError: no such column: dog.owner_name


Actually, why is it not possible to do a
db.walk.dog.requires = IS_IN_DB(db,'dog.id','%(name)s by %(owner.name)s')
directly?

probably I'm missing some python knowledge.

Thanks
Frederik


 On Nov 10, 4:35 am, Frederik Wagner fner...@googlemail.com wrote:
 Hi .*,

 is there a possibility in the Validator IS_IN_DB to have the display
 string show attributes from multiple (joined) tables?
 E.g.: If I  say somthing like

 IS_IN_DB( db( (table1.id == table2.id_table1) , 'table1.id',
 '%(table1.attribute)s %(table2.attribute)s')

 It tried somthing like this, but the problem is, that the placeholder
 are always assumed to be attributes of the table used in the second
 parameterfield, here 'table1'. Such that the used attributes are
 'table1.table1.attribute' and 'table1.table2.attribute', which is
 clearly an error.

 I hope I could make the problem clear?

 Thanks a lot for help.
 Bye!
 Frederik
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~--~~~~--~~--~--~---



[web2py:34948] Validators during db.insert

2009-11-09 Thread Frederik Wagner

Hi .*,

is there a way of making web2py run the validators configured in the
model on a dataset inserted via a direct db.table.insert statement? It
looks like I'm able to insert any kind of data, it's validated...

Thanks and Bye,
Frederik

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~--~~~~--~~--~--~---