Forum OpenACS Development: Passing custom variables through pages

Request notifications

Hi there,

Using ad_proc list::create, to show a couple of items, returns paginated results.

[listemplate] seems to be working fine, but when I click in the pagination links, next pages return errors, it complains about a custom variable, which is mandatory to run the SQL query, in the db_multirow, related to [list::create]

The custom TCL var is present in the page, and properly assinged, as the very first page of the list displays just fine. But, I'm pretty sure, I'm missing something very basic!

I've tried to find a switch to pass the custom variable in the ad_proc [list::create], but I found no documentation for [list::create], at /api-doc.

There was documentation only for ad_proc [list::template::create], which perhaps I could get a clue about what arguments that ad_proc [list::create] would have.

api-doc/proc-view?proc=template::list::create&source_p=1

However, even after reading it, I'm still not able to tell which switch would be the one to add a variable in the link of the pages.

I've tried to use the switch pass_properties, but it doesn`t have the expected behavior.

Ideas on how to edit pagination links in [list::create] are welcome!

Best wishes,

Collapse
Posted by Brian Fenton on
Hi Iuri

It might be good to show us your code, but here are a few things you should try. There is also more documentation here https://openacs.org/api-doc/proc-view?proc=template::paginator::create&source_p=1

You should have something like these in the ad_page_contract:
{items_per_page 20}
{page_size "" }
{page:naturalnum 1}

These need to be included in your filters declaration:

items_per_page {}
page_size {}

Your list::create needs at least these:

-page_size $items_per_page \
-page_query_name page_sql_query_name \
-page_flush_p 1

page_sql_query_name will need to be defined in the .XQL file

Finally, your main list multirow query should have something like these:

[template::list::page_where_clause -and -name $list_name -key claim_detail_id]
[template::list::filter_where_clauses -name $list_name]
[template::list::orderby_clause -name $list_name -orderby]

hope this helps
Brian

Collapse
Posted by Antonio Pisano on
Dear Iuri, without looking at your code, something coming to my mind is: did you define such custom variable as a filter in your template::list? Something like:
-filters {
	a_custom_variable {
	    hide_p 1
        }
        ....
}
This will make the variable be exported by the paginator links. You will need to add the variable to the ad_page_contract definition as well, or it will be ignored even when the URL specifies it. Hope this helps
Collapse
Posted by Iuri Sampaio on
Here it is listtemplate source


list::create \
    -name items \
    -multirow items \
    -key item_id \
    -page_flush_p 1 \
    -page_size 250 \
    -page_query_name select_items \
    -actions {
        "#evex-event.Send_request#" request-proposal "#evex-event.Send_a_request_to_partner#"
    } \
    -bulk_action_method post \
    -bulk_action_export_vars { event_id } \
    -bulk_actions {
        "#evex-event.Send_request#" request-proposal "#evex-event.Send_request_to_all_partners#"
    } \
    -elements {
        title {
            label "#evex-event.Title#"
        }
        distance {
            label "#evex-event.Distance#"
        }
        score {
            label "#evex-event.Category_Score#"
        }
        total {
            label "#evex-event.Total_Score#"
        }
        location {
            label "#evex-event.Location#"
        }
    }

db_multirow -extend { location thumbnail_url} items select_items_page "
    SELECT qa1.item_id, qa1.score AS total, qa2.score, cr.title,
    pa.latitude, pa.longitude, pa.delivery_address AS location,
    to_char((( 3959 * acos ( cos ( radians(:latitude) ) * cos( radians( CAST(pa.latitude AS NUMERIC)) ) * cos( radians( CAST(pa.longitude AS NUMERIC) ) - radians(:longitude) )+ sin ( radians(:latitude) )* sin( radians( CAST(pa.latitude AS NUMERIC) ) ) )) * 1.6)::float, 'FM999999990.00') AS distance
    FROM
    cr_items ci, cr_revisions cr,
    ee_qa_item_info qa1, ee_qa_item_category_score qa2,
    postal_addresses pa,
    acs_data_links adl
    WHERE ci.item_id = cr.item_id
    AND ci.live_revision = cr.revision_id
    AND (ci.content_type = 'ee_venue' OR ci.content_type = 'ee_service')
    AND qa1.item_id = ci.item_id
    AND qa1.item_id = qa2.item_id
    AND adl.object_id_one = qa1.item_id
    AND adl.object_id_two = pa.party_id
    AND adl.relation_tag = 'item_group_rel'

    AND (( 3959 * acos ( cos ( radians(:latitude) ) * cos( radians( CAST(pa.latitude AS NUMERIC)) ) * cos( radians( CAST(pa.longitude AS NUMERIC) ) - radians(:longitude) )+ sin ( radians(:latitude) )* sin( radians( CAST(pa.latitude AS NUMERIC) ) ) )) * 1.6) < :max_distance

    AND ci.item_id IN ($item_ids)
    AND qa2.category_id IN ($categories)
    AND [template::list::page_where_clause -name items -key qa1.item_id ]
    [template::list::filter_where_clauses -and -name items]
    GROUP BY qa1.item_id, qa2.score, cr.title, pa.latitude, pa.longitude, pa.delivery_address
    ORDER BY qa2.score DESC, qa1.score DESC

" {

    set thumbnail_url ""
...
}

Collapse
Posted by Iuri Sampaio on
I thought full TCL script would be better, self-explanatory.

https://pastebin.com/wzJvJrnY

Collapse
Posted by Antonio Pisano on
Your code is compatible with my explanation. Please try:
- adding the filters so variables are exported in the paginator's URLs
- add the custom variable to the ad_page_contract

I am pretty confident this will work. Let us know!

Ciao

Collapse
Posted by Iuri Sampaio on
It does work. custom variables passed through.
Pagination seems a bit weird though. It's unbalanced, neither shows the correct total. I'll make sure my SQL is properly written. Then... Perhaps I'll create a new thread soon! (-: