pass current page id to load function in sidebar

85 views
Skip to first unread message

Greg Vaughan

unread,
Apr 24, 2014, 9:05:20 AM4/24/14
to web...@googlegroups.com
Hi everyone...

I am using a LOAD function for a notes field in the sidebar of my app. I am able to load the notes for a specific business by hardcoding the id of the business in the controller like so...

@auth.requires_login()
def note():
    current==1
    notes=db(db.notes.business==current).select()
    return dict(notes=notes)

What I would like to do is have the value of current set to the id var of the current page eg... welcome/default/leads?id=17 <<< THIS

No request.vars are available to the LOAD function however...

How do I achieve this?

Niphlod

unread,
Apr 24, 2014, 11:00:04 AM4/24/14
to web...@googlegroups.com
why are you saying that vars are unavailable for LOAD ?

Greg Vaughan

unread,
Apr 24, 2014, 11:23:21 AM4/24/14
to web...@googlegroups.com
Hi Niphlod...

{{=response.vars}} shows nothing... nor does {{response.toolbar()}}...
db stats shows notes.business = 1 when I hardcode it as above...

I took a screenshot here

I assume that the filter will have to be sorted in the controller as the LOAD function would be serialised before the page is loaded? I could be completeley wrong of course.

Niphlod

unread,
Apr 24, 2014, 12:03:22 PM4/24/14
to web...@googlegroups.com
how are you using LOAD to load the component ?

Greg Vaughan

unread,
Apr 24, 2014, 12:49:28 PM4/24/14
to web...@googlegroups.com
Sorry I should have given you all the data...

The db table is a simple one

# HISTORY

db
.define_table('notes',
   
Field('business', 'reference calls',
          writable
=False
         
),
   
Field('note', 'text',
          label
='Add Note'
         
),
    auth
.signature,
    format
='%(business)s'
   
)


The controller is as above...
 
note.load is simply

{{=response.toolbar()}}
<h4>Notes:</h4>
{{for note in notes:}}
<div class="note">
   
On {{=note.created_on}} {{=note.created_by.first_name}}
      says
<blockquote class="note_body">{{=note.note}}</blockquote>
</div>
{{pass}}

load is only called in a couple of views at the moment until I get this sorted out...

for example in leads.html (the one in the screenshot)

{{extend 'layout.html'}}
{{=form}}
{{pass}}
{{block right_sidebar}}
{{=LOAD('default','note.load',ajax=True)}}
{{end}}

Derek

unread,
Apr 24, 2014, 1:11:29 PM4/24/14
to web...@googlegroups.com
put it in the session...

Anthony

unread,
Apr 24, 2014, 1:12:00 PM4/24/14
to web...@googlegroups.com
{{extend 'layout.html'}}
{{=form}}
{{pass}}
{{block right_sidebar}}
{{=LOAD('default','note.load',ajax=True)}}
{{end}}


Just do:

{{=LOAD('default', 'note.load', vars=dict(id=request.vars.id), ajax=True)}}

And in the note() function:

def note():
    notes
= db(db.notes.business == request.vars.id).select()

Also, avoid using "current" as a variable name, as there is a web2py global object called "current".

Anthony

Derek

unread,
Apr 24, 2014, 1:14:53 PM4/24/14
to web...@googlegroups.com
session.lead_id=request.vars.id
in the 'leads' function. Then the note...
current = session.lead_id

= is assignment
== is comparison

Greg Vaughan

unread,
Apr 24, 2014, 1:49:02 PM4/24/14
to web...@googlegroups.com
Cheers Anthony

Worked a treat...

Thanks everyone for the help...
Reply all
Reply to author
Forward
0 new messages