Você está aqui: Página Inicial Documentação Utilizando o mecanismo de paginação embutido do Plone

Utilizando o mecanismo de paginação embutido do Plone

por Ramiro B. da Luz última modificação 13/11/2011 09:56
Este tutorial mostra como user o mecanismo de paginação embutido do Plone para criar seletores Anterior/Próximo com páginas quando você possui muitos items a exibir.

Utilizando o mecanismo de paginação embutido do Plone

Este tutorial mostra como user o mecanismo de paginação embutido do Plone para criar seletores Anterior/Próximo com páginas quando você possui muitos items a exibir.

 

Usando o PloneBatch

PloneBatch é uma extensão da classe Batch de ZTUtils. Também vem com uma útil macro para facilitar o desenvolvimento do menu de navegação. É perfeito para aqueles 2000 items da página de resultado de busca.

Os principais passos da inclusão do PloneBatch em seu template são importar o Batch, fazer um batch do seu resultset, usar a macro de navegação e iterar sobre os elementos batch. O código fonte neste exemplo vem do template search.pt do Plone. Primeiro passo, configure seu Batch no início de seu template e defina algumas variáveis usadas pelo Batch:

'results' é a lista na qual realiza-se a paginação.. Neste caso, são os resultados de uma pesquisa (uma consulta no catalog), mas pode ser qualquer lista. 'Batch' é importado de 'Products.CMFPlone' e feita disponível no template como 'Batch'. 'b_size' é o tamanho do batch, o número de elementos a seria exibidos em cada página. 'b_start' é o primeiro elemento do batch. É recuperado do request, ou 0 se não encontrado. Geralmente você verá 'b_start' setado a diferentes valores na URL quando você navega nas páginas no num resultado de busca. Segundo passo, faça um batch a partir dos resultados. Depois de configurar 'Batch' e as outras variáveis, estamos prontos para fazer a paginação de nosso resultado.

Se o próximo batch não possua elementos 'órfãos', ele será combinado com o batch corrente. Neste caso, se o próxumo batch possua apenas um elemente, ele será exibido na página corrente. Terceiro passo, fazer o menu de navegação. Para sua conveniência, nos fornecemos uma macro para fazer os menus de navegação. Esta macro tipicamente será chamada antes e depois de iterar-se sobre os items do batch. O resultado será alguma coisa similar a: «Anterior 1 2 3 4 [5] 6 7 8 ... Último Próxima».  Quarto passo, iterar sobre o batch. Isso é feito da mesma forma que você itera sobre um conjunto de resultados de uma consulta no portal_catalog, por exemplo. 

 

PloneBatch: Advanced Usage

The batch navigation is customizable, and here is an overview of the more advanced features available.

The Batch constructor takes these arguments: 

sequence -- The list to batch 

size -- The number of items in each batch 

start=0 -- The first item in the batch, 0-index 

end=0 -- The last item in the batch, 0-index and optional 

orphan=0 -- The next page will be combined with the current page if it does not contain more than orphan elements. Optional and default 0 

overlap=0 -- The number of overlapping elements in each batch. Optional and default 0 

pagerange=7 -- The number of pages to display in the navigation menu 

quantumleap=0 -- 0 or 1 to indicate wheter bigger increments should be used in the navigation list for big results. This would make navigation faster as you could make bigger jumps. 

b_start_str='b_start' -- The variable name to be used to set the start of the batch. Changing this enables multiple batches with different starting points on the same page. 


Making your own navigation menu 

You can make your own navigation menu if you are not satisfied with the regular one. To do this you have to know which attributes are available in the batch object. 

size -- Batchsize 

start -- First element, 1 based index into the sequence 

first -- First element, 0 based index into the sequence 

end -- Last element, 0 based index into the sequence 

orphan -- The next page will be combined with the current page if it does not contain more than orphan elements 

overlap -- The number of overlapping elements in each batch 

length -- Length of the batch 

b_start_str -- The name of the request variable storing batch starting point 

last -- First element on last page 

previous -- previous Batch, previous.first is the first element in the previous page 

next -- next Batch, next.first is the first element in the next page 

sequence_length -- The length of the result 

numpages -- Total number of pages 

pagenumber -- Current page number 

pagerange -- The computed number of pages to display in the navigation menu 

pagerangestart -- The first page to display in the navigation menu 

pagerangeend -- The last page to display in the navigation menu 

navlist -- A list containing the pagenumbers for the navigation list 

prevlist -- A list containing the pagenumbers for the navigation list with pagenumbers lower than the current page 

nextlist -- A list containing the pagenumbers for the navigation list with pagenumbers higher than the current page 

quantumleap -- 0 or 1 to indicate if there should be bigger gaps between the pagenumbers in on the edges of the navigation list 

leapback -- A list containing the pagenumbers for the quantum leap navigation list with pagehumbers lower than the current page 

leapforward -- A list containing the pagenumbers for the quantum leap navigation list with pagehumbers lower than the current page 

pageurl(self, formvariables, pagenumber=-1): -- """ Makes the url for a given page """ 

def navurls(self, formvariables, navlist=[]): -- """ Returns the page number and url for the navigation quick links """ 

def prevurls(self, formvariables): -- """ Helper method to get prev navigation list from templates """ 

def nexturls(self, formvariables): -- """ Helper method to get next navigation list from templates """