my own records on SQLFORM select

35 views
Skip to first unread message

Murat KAŞIKÇIOĞLU

unread,
Jul 10, 2019, 2:23:07 AM7/10/19
to web...@googlegroups.com
I want to select only authenticated teachers' students on the form. But I could not find how to filter. Can you help?
Best,
Murat.

###
db.define_table(
    'session_header',
    Field('session_date', type="date", label='Session Date'),
    Field('teacher', 'reference auth_user', notnull=True, readonly=True, default=auth.user_id),
    Field('student', 'reference student', notnull=True),
    auth.signature)

def create():
    form = SQLFORM(session_header)
    if form.process().accepted:
        response.flash = "Record inserted successfully."
    elif form.errors:
        response.flash = "Please correct the form errors."
    response.view = 'sessions/create.html'
    return dict(form=form)


Dave S

unread,
Jul 10, 2019, 7:32:26 PM7/10/19
to web2py-users


On Tuesday, July 9, 2019 at 11:23:07 PM UTC-7, Murat KAŞIKÇIOĞLU wrote:
I want to select only authenticated teachers' students on the form. But I could not find how to filter. Can you help?

I don't find it easy to picture what you want. 

My best guess is that when a teacher is logged in, you want to show a list of students who are in a session where the session teacher field is the logged-in teacher.  Wouldn't that be just a query like

rows = db(db.session_header.teacher == auth.user_id).select()

You would put this in another controller function

def showmystudents():
    rows
= ...
   
return dict(vrows = rows)

and in the matching view you would populate a table or use SQLTABLE().

Or you combine some of the steps (and provide for editing) by using SQLFORM.grid()
<URL:http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM-grid>




Best,
Murat.


/dps
 

Murat KAŞIKÇIOĞLU

unread,
Jul 11, 2019, 1:47:08 AM7/11/19
to web...@googlegroups.com
I wanted to use SQLFORM. Whenever teacher logged in, he has to select from combobox only their responsible students. 
I could not find the way how to implement it while creating SQLFORM. 
My solution: I've added one hidden text into form and parse on the client side like this:
form = SQLFORM(
        table_sessions,
        fields=field_list,
        hidden=dict(student_list=get_students()))
    if form.process().accepted:
        ...

And on client side I used jQuery to parse.

Thanks for reply.
-------------------------------
Murat KAŞIKÇIOĞLU




Dave S <snide...@gmail.com>, 11 Tem 2019 Per, 02:32 tarihinde şunu yazdı:
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/391ac387-13b0-42bb-a5d6-abd0d4fa08ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages