[web2py] Re: howto subset a select element

2012-08-14 Thread lucas
ok, what if i have a nested type select field like:

db.define_table('class_assignments',
Field('class_id', db.classes, requires=IS_IN_DB(db, db.classes.id, 
'%(class_title)s (%(id)s)'), writable=False, readable=False),
Field('lecture_id', db.lectures, 
requires=IS_IN_DB(db(db.lectures.user_id == auth.user_id), db.lectures.id, 
'%(title)s (%(id)s)')),
Field('lecture_item_id', db.lecture_items, requires=IS_IN_DB(db, 
db.lecture_items.id, '%(title)s (%(id)s)')),
...

where in this case i want the user to select the lecture_id first, and then 
the lecture_item_id would be a subset or a detail list of the master 
lecture_id.  i tried:

Field('lecture_item_id', db.lecture_items, 
requires=IS_IN_DB(db(db.lecture_items.lecture_id == lecture_id), 
db.lecture_items.id, '%(title)s (%(id)s)')),

and:

Field('lecture_item_id', db.lecture_items, 
requires=IS_IN_DB(db(db.lecture_items.lecture_id == 
db.class_assignments.lecture_id), db.lecture_items.id, '%(title)s 
(%(id)s)')),

but both attempts failed.  so how do i do a subselect kind of model?  thanx 
in advance, lucas

-- 





[web2py] Re: howto subset a select element

2012-08-14 Thread Anthony
You can't do that all at once when you respond to the initial request 
because it depends on user input, so you have to populate the second select 
via Ajax on the client side once the first selection is made. See 
herehttp://stackoverflow.com/questions/8146260/best-practice-for-populating-dropdown-based-on-other-dropdown-selection-in-web2p/8152910#8152910for
 some ideas.

Anthony

On Tuesday, August 14, 2012 2:49:28 PM UTC-4, lucas wrote:

 ok, what if i have a nested type select field like:

 db.define_table('class_assignments',
 Field('class_id', db.classes, requires=IS_IN_DB(db, db.classes.id, 
 '%(class_title)s (%(id)s)'), writable=False, readable=False),
 Field('lecture_id', db.lectures, 
 requires=IS_IN_DB(db(db.lectures.user_id == auth.user_id), db.lectures.id, 
 '%(title)s (%(id)s)')),
 Field('lecture_item_id', db.lecture_items, requires=IS_IN_DB(db, 
 db.lecture_items.id, '%(title)s (%(id)s)')),
 ...

 where in this case i want the user to select the lecture_id first, and 
 then the lecture_item_id would be a subset or a detail list of the master 
 lecture_id.  i tried:

 Field('lecture_item_id', db.lecture_items, 
 requires=IS_IN_DB(db(db.lecture_items.lecture_id == lecture_id), 
 db.lecture_items.id, '%(title)s (%(id)s)')),

 and:

 Field('lecture_item_id', db.lecture_items, 
 requires=IS_IN_DB(db(db.lecture_items.lecture_id == 
 db.class_assignments.lecture_id), db.lecture_items.id, '%(title)s 
 (%(id)s)')),

 but both attempts failed.  so how do i do a subselect kind of model?  
 thanx in advance, lucas



-- 





[web2py] Re: howto subset a select element

2012-08-14 Thread lucas
ok, moving along,

what if i want the option of allowing the user to leave:
   ...
   Field('lecture_item_id', db.lecture_items, requires=IS_IN_DB(db, 
db.lecture_items.id, '%(title)s (%(id)s)')),
   ...

blank.  meaning, if the user choses it in the select element, fine, it 
should be in the referencing table, however, it is ok to leave it blank and 
the controller will handle it according to design.  how do i define that 
requires?

thanx again in advance, i am really learning the poop out of this system.  
lucas

-- 





[web2py] Re: howto subset a select element

2012-08-14 Thread Anthony
IS_EMPTY_OR(IS_IN_DB(db, db.lecture_items.id, '%(title)s (%(id)s)'))

Anthony

On Tuesday, August 14, 2012 10:59:42 PM UTC-4, lucas wrote:

 ok, moving along,

 what if i want the option of allowing the user to leave:
...
Field('lecture_item_id', db.lecture_items, requires=IS_IN_DB(db, 
 db.lecture_items.id, '%(title)s (%(id)s)')),
...

 blank.  meaning, if the user choses it in the select element, fine, it 
 should be in the referencing table, however, it is ok to leave it blank and 
 the controller will handle it according to design.  how do i define that 
 requires?

 thanx again in advance, i am really learning the poop out of this system.  
 lucas


-- 





[web2py] Re: howto subset a select element

2012-08-13 Thread Anthony
The first argument to IS_IN_DB and IS_NOT_IN_DB can be a Set object rather 
than the entire db:

IS_IN_DB(db(db.courses.teacher = auth.user_id), db.courses.id, '%(title)s 
(%(id)s)')

See http://web2py.com/books/default/chapter/29/7#Database-validators.

Anthony

On Monday, August 13, 2012 8:21:44 AM UTC-4, lucas wrote:

 hello one and all,

 lets say i have a model like:

 db.define_table('courses',
 Field('user_id', db.auth_user, requires=IS_IN_DB(db, '%s.id' % 
 db.auth_user, '%(last_name)s, %(first_name)s (%(id)s)')),
 

 db.define_table('classes',
 Field('course_id', db.courses, requires=IS_IN_DB(db, db.courses.id, 
 '%(title)s (%(id)s)'), writable=False, readable=False),
 

 or, when a teacher is setting up a class, under the classes table, i only 
 want the courses, from the courses table, showing that have his/her 
 user_id, which is known from auth.user_id at the time of login, in the 
 select element of a SQLForm or crud form.

 so how do you present only a subset of values for the select element of a 
 form under some kind of boolean test condition?

 thanx in advance, lucas


-- 





[web2py] Re: howto subset a select element

2012-08-13 Thread lucas
oh my, that is so perfect, i love that.  i learned a new word and i am 
going to use it everywhere.  thanx anthony.

p.s. hey, when is web2py v2.0 going to be stable and released full?  
doesn't it have angularjs built into it also?

-- 





[web2py] Re: howto subset a select element

2012-08-13 Thread Anthony


 p.s. hey, when is web2py v2.0 going to be stable and released full?


I think very soon, not sure exactly when.
 

   doesn't it have angularjs built into it also?


No, where did you hear that?

Anthony 

-- 





[web2py] Re: howto subset a select element

2012-08-13 Thread Massimo Di Pierro
I was hoping last week. Not I am hoping next week. We have closed most of 
the tickets we think were important but there are a couple more to deal 
with. 



On Monday, 13 August 2012 09:00:48 UTC-5, Anthony wrote:

 p.s. hey, when is web2py v2.0 going to be stable and released full?


 I think very soon, not sure exactly when.
  

   doesn't it have angularjs built into it also?


 No, where did you hear that?

 Anthony 


--