Forum OpenACS Q&A: Re: Using list-builder and pagination

Collapse
Posted by Lars Pind on
Nope. You don't need to talk to the paginator yourself at all.

Create the list the way you do, then include the following in your query:

select ...
from  ...
where  ...
and    activity_id in ([template::list::page_get_ids -name $list_name])

That should do it.

Pagination is still kindof sketchy. The "old" paginator which I'm using is complicated and does this pagination in Tcl instead of in the database, etc.

Whenever I get a chance, I want to try and integrate with Jon Griffin's new paginator, which should be simpler.

/Lars

Collapse
Posted by Robert Locke on
Andrei: I'm not seeing the behavior you're describing, but I will look out for it.

Lars: your method is much cleaner, thanks!  Is there any documentation on filters?

Thanks again...

Collapse
Posted by Lear Zumaeta on
Hi, I want to know if is possible change te format of the elemnt that shown on the array, sorry for my english, I have this as shown on the tradicional pagination list

<< < 1 2 3 4 5 6 7 8 9 10 > >>

Gaceta norma numero año autoridad
---------------------------------------------------------
375 49 25 1906 8
753 49 12 1909 8

the tipe for 49=Ley and 8=asamblea

but I want list like this

Ley 25 1906
375
asamblea

ley 12 1909
753
asamblea

and go on

is this possible or I have to limited for the tradicional pagination list

Collapse
Posted by Brian Fenton on
Hi Lear,

I'm not sure if this will do what you want, but you could take a look at using "group by" with list builder. See here for an example: https://openacs.org/blog/one-entry?entry_id=907364

hope this helps
Brian Fenton

Collapse
Posted by Lear Zumaeta on
Hello Brian I have this in my .tcl

###########################################################
request create -params {
sql1 -datatype text -optional
}

ad_page_contract {
} {
    {page:naturalnum 1}
}

list::create -name users \
        -multirow users \
        -key num_sec \
        -page_size 10 \
        -page_query { select num_sec from procadm.t_normas where $sql1} \
        -elements {
                  num_sec {
                        display_template {<table width="800" border="0"><tr><td width="2%" valign="top" align="center"><font face="Arial, Helvetica, sans-serif" color="#FF0000" size="3"><b><img src="puntero.gif" width="17" height="17"></b></font></td><td width="96%" valign="top" bgcolor="#E8E8E8" align="justify">@users.desc_norma@&nbsp;@users.num_norma@&nbsp;de&nbsp;@users.anio_gac@<br>Número de Gaceta:&nbsp;@users.num_gaeta@<br>Autoridad:&nbsp;@users.desc_autoridad@<br>Título:&nbsp;@users.titulo@</td></tr></table> }
            }
        }

  set query  "select a.num_sec num_sec, num_gaceta,to_char(fecha_gaceta,'yyyy') anio_gac, a.norma, desc_norma, num_norma, titulo, cod_autoridad,desc_autoridad \
from procadm.t_normas a, procadm.t_tipo_norma b,procadm.t_autoridad c where $sql1 and \
a.norma=b.num_sec and \
a.cod_autoridad=c.num_sec and \
a.num_sec in ([template::list::page_get_ids -name users])"

    db_multirow users users_query $query

#########################################################

I past the value sql1 from another script and list the first  10 rows fine when I put the value from keyboard but when I clik the next 10 rows I feel like sql1 lost the value in the array and list me an error.

What I am doing wrong.  Please sorry about my english

Collapse
Posted by Brian Fenton on
Hi Lear,

I don't think it's a good idea to be passing in your SQL query as a parameter to the page - you're leaving yourself open to potential SQL Injection attacks.

Also I don't think you need the "request create" - just use ad_page_contract to handle any form variables.

Brian

How I do that? Do you have any documentation or example script on this matter. I have this script with elements form that a I enter by keyboard but when I excecute the submit instruccion, runs the select query on the list array for the first page but when I past to the next page=2 I lost the information...
Sure, there are loads of examples in the OpenACS codebase. Try this one for starters: http://cvs.openacs.org/cvs/*checkout*/openacs-4/packages/dotlrn-ecommerce/lib/tree-chunk.tcl?rev=1.2
I don't think it's a good idea to be passing in your SQL query as a parameter to the page - you're leaving yourself open to potential SQL Injection attacks.

Also I don't think you need the "request create" - just use ad_page_contract to handle any form variables.

How I use ad_page_contract to do this, handle any form variables from another script passed

How I use ad_page_contract to do this, handle any form variables from another script passed
Hi Brian, forgiveness for asking to much I´m trying to understand those templating demos but I barracks,

this is a portion of the script that pass parameters
index_lista.tcl

if {  [string equal $keyword {}] } {

  if {  ! [ string compare $sql1 "no"] } {

        set display "doc_list"
        set band4 "12"
        element set_error func_search error2_search " Por favor introduzca su busqueda"
        return
        } else {
# past of parameter to prueba_list_builder?
template::forward prueba_list_builder?sql1=$sql1
}

This is the code for the prueba_list_builder

ad_page_contract {
} {
            {page:optional}
}

request create -params {
  sql1 -datatype text -optional
}

if { ! [request is_valid] } { return }

set sql1 $sql1

list::create -name users \
        -multirow users \
        -key num_sec \
        -pass_properties { sql1 } \
        -page_size 10 \
        -page_query { select num_sec from procadm.t_normas where $sql1} \
        -elements {
                  num_sec {
                        display_template {<table width="800" border="0" cellspacing="6" cellpadding="6"><tr><td width="2%" valign="top" align="center"><font face="Arial, Helvetica, sans-serif" color="#FF0000" size="3"><b><img src="puntero.gif" width="17" height="17"></b></font></td><td width="96%" valign="top" align="justify">@sql1@<br>@users.desc_norma@&nbsp;@users.num_norma@&nbsp;de&nbsp;@users.anio_gac@<br>Número de Gaeta:&nbsp;@users.num_gaceta@<br>Autoridad:&nbsp;@users.desc_autoridad@<br>Título:&nbsp;@users.titulo@</td></tr></table> }
            }
        }

  set query  "select a.num_sec num_sec, num_gaceta,to_char(fecha_gaceta,'yyyy') anio_gac, a.norma, desc_norma, num_norma, titulo, cod_autoridad,
desc_autoridad \
from procadm.t_normas a, procadm.t_tipo_norma b,procadm.t_autoridad c where $sql1 and \
a.norma=b.num_sec and
a.cod_autoridad=c.num_sec and
a.num_sec in ([template::list::page_get_ids -name users])"

db_multirow users users_query $query

the view showme the value of variable for the first page but when I past to the second the variable lost the value