And I am confused again... Again...

5 views
Skip to first unread message

Jason Brower

unread,
May 2, 2009, 11:21:13 AM5/2/09
to Web2py Mailing List
I suppose your used to it by now. :D
This works... except for the validators... they aren't stoping me from
entering more than one student_name

from datetime import datetime, date, time
now = datetime.utcnow()
today = date.today()

db = SQLDB('sqlite://database.db')

db.define_table('student',
SQLField('student_name', 'string'),
SQLField('certificate_number', 'integer'),
SQLField('security_number', 'string'),
SQLField('grade_point_average', 'double'),
SQLField('thesis_name', 'string'),
SQLField('thesis_grade', 'integer'))

db.student.student_name.requires = IS_NOT_IN_DB(db,
"student.student_name")
db.student.certificate_number.requires = IS_NOT_IN_DB(db,
"student.certificate_number")
db.student.thesis_grade.requires = IS_IN_SET(range(1,6))
db.student.grade_point_average.requires = IS_FLOAT_IN_RANGE(1,5)
db.student.student_name.requires = IS_NOT_EMPTY()
db.student.certificate_number.requires = IS_NOT_EMPTY()


DenesL

unread,
May 2, 2009, 12:13:44 PM5/2/09
to web2py Web Framework
You are redefining the requires for student_name:

On May 2, 10:21 am, Jason Brower <encomp...@gmail.com> wrote:
> db.student.student_name.requires = IS_NOT_IN_DB(db,
> "student.student_name")
...
> db.student.student_name.requires = IS_NOT_EMPTY()

Jason Brower

unread,
May 2, 2009, 1:22:01 PM5/2/09
to web...@googlegroups.com
And that dunce light points at Encompass.
Thanks!
Jason

Yarko Tymciurak

unread,
May 2, 2009, 5:25:58 PM5/2/09
to web...@googlegroups.com
Also, note, that you are trying to combine two FORM validators.

Since the first requirement belongs on the DAL / on db checking, so the database can raise an error, then your second requirement is _clearly_ (correct?) a form validator:  you want the form to not be accepted if it is submitted without a name...

So you mean is more clearly said like this:

  db.define_table('student',
       SQLField('student_name', 'string', uniq=True),
....

Since you probably don't want student name dropdown boxes in the form, then this will work:

  db.student.student_name.requires = [ IS_NOT_IN_DB(db,"student.student_name") ]
  ....
  db.student.student_name.requires.append( IS_NOT_EMPTY() )


Regards,
- Yarko

DenesL

unread,
May 2, 2009, 9:07:04 PM5/2/09
to web2py Web Framework
On May 2, 4:25 pm, Yarko Tymciurak <yark...@gmail.com> wrote:

> Since you probably don't want student name dropdown boxes in the form, then
> this will work:
>
>   db.student.student_name.requires = [
> IS_NOT_IN_DB(db,"student.student_name") ]

Dropdown boxes are only created for values required to be in a
definite set or a database, i.e. IS_IN_SET or IS_IN_DB validators. If
you don't want the dropdown then you put in a list.

Jason Brower

unread,
May 3, 2009, 12:29:03 AM5/3/09
to web...@googlegroups.com
Wow, thanks Yarko.

weheh

unread,
May 3, 2009, 1:55:47 PM5/3/09
to web2py Web Framework
I like the conciseness of how Massimo does this:

db.student.student_name.requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB
(db,"student.student_name")]


On May 3, 12:29 am, Jason Brower <encomp...@gmail.com> wrote:
> Wow, thanks Yarko.
>
>
>
> On Sat, 2009-05-02 at 16:25 -0500, Yarko Tymciurak wrote:
> > Also, note, that you are trying to combine two FORM validators.
>
> > Since the first requirement belongs on the DAL / on db checking, so
> > the database can raise an error, then your second requirement is
> > _clearly_ (correct?) a form validator:  you want the form to not be
> > accepted if it is submitted without a name...
>
> > So you mean is more clearly said like this:
>
> >   db.define_table('student',
> >        SQLField('student_name', 'string', uniq=True),
> > ....
>
> > Since you probably don't want student name dropdown boxes in the form,
> > then this will work:
>
> >   db.student.student_name.requires =
> > [ IS_NOT_IN_DB(db,"student.student_name") ]
> >   ....
> >   db.student.student_name.requires.append( IS_NOT_EMPTY() )
>
> > Regards,
> > - Yarko
>
> > On Sat, May 2, 2009 at 12:22 PM, Jason Brower <encomp...@gmail.com>
> > wrote:
>
> >         And that dunce light points at Encompass.
> >         Thanks!
> >         Jason
>
> >         On Sat, 2009-05-02 at 09:13 -0700, DenesL wrote:
> >         > You are redefining the requires for student_name:
>
> >         > On May 2, 10:21 am, Jason Brower <encomp...@gmail.com>
> >         wrote:
> >         > > db.student.student_name.requires = IS_NOT_IN_DB(db,
> >         > > "student.student_name")
> >         > ...
> >         > > db.student.student_name.requires = IS_NOT_EMPTY()- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages