Utilizando o mecanismo de paginação embutido do Plone
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.
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 """
