refactored batching code and added pagination to search results
This commit is contained in:
parent
219a0b88e0
commit
3cf27379a3
|
@ -0,0 +1,157 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
xmlns:metal="http://xml.zope.org/namespaces/metal"
|
||||
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
|
||||
i18n:domain="plone">
|
||||
<body>
|
||||
|
||||
<tal:comment condition="nothing">You can feed in batch_base_url by enclosing
|
||||
the metal:use-macro="context/batch_macros/macros/navigation" statement in your
|
||||
template with a tal:define="batch_base_url YOUR_BASE_URL" tales expression.
|
||||
</tal:comment>
|
||||
<div id="results-nav" class="listingBar"
|
||||
metal:define-macro="navigation"
|
||||
tal:define="request request|context/request|container/request|nothing;
|
||||
batch batch|nothing;
|
||||
batchformkeys batchformkeys|nothing;
|
||||
batchlinkparams python:batchformkeys and dict([(key, request.form[key]) for key in batchformkeys if key in request]) or request.form;
|
||||
mq python:modules['ZTUtils'].make_query;
|
||||
url batch_base_url | request/ACTUAL_URL;
|
||||
currentpage batch/pagenumber;"
|
||||
tal:condition="python: batch.next or batch.previous">
|
||||
|
||||
<tal:block tal:define="p batch/previous | nothing">
|
||||
<a href="" id="results-nav-prev" tal:condition="p"
|
||||
tal:attributes="href python: '%s?%s' % (url , mq( batchlinkparams, {batch.b_start_str:p.first} ))">
|
||||
«
|
||||
<span i18n:translate="batch_previous_x_items" tal:omit-tag="">
|
||||
Previous
|
||||
<span i18n:name="number" tal:omit-tag="" tal:content="p/length">n</span>
|
||||
items
|
||||
</span>
|
||||
</a>
|
||||
<span id="results-nav-prev" tal:condition="not: p">
|
||||
«
|
||||
<span i18n:translate="batch_previous_x_items" tal:omit-tag="">
|
||||
Previous
|
||||
<span i18n:name="number" tal:omit-tag="" tal:content="b_size">n</span>
|
||||
items
|
||||
</span>
|
||||
</span>
|
||||
</tal:block>
|
||||
|
||||
<tal:block tal:define="n batch/next | nothing">
|
||||
<a href="" id="results-nav-next" tal:condition="n"
|
||||
tal:attributes="href python: '%s?%s' % (url , mq( batchlinkparams, {batch.b_start_str:n.first} ))">
|
||||
<span i18n:translate="batch_next_x_items" tal:omit-tag="">
|
||||
Next
|
||||
<span i18n:name="number" tal:omit-tag="" tal:content="n/length">n</span>
|
||||
items
|
||||
</span>
|
||||
»
|
||||
</a>
|
||||
<span id="results-nav-next" tal:condition="not: n">
|
||||
<span i18n:translate="batch_next_x_items" tal:omit-tag="">
|
||||
Next
|
||||
<span i18n:name="number" tal:omit-tag="" tal:content="b_size">n</span>
|
||||
items
|
||||
</span>
|
||||
»
|
||||
</span>
|
||||
</tal:block>
|
||||
|
||||
<tal:comment tal:condition="nothing">
|
||||
Link to first
|
||||
</tal:comment>
|
||||
<span tal:condition="python: 1 not in batch.navlist">
|
||||
<a href=""
|
||||
tal:attributes="href python: '%s?%s' % (url, batch.pageurl(batchlinkparams,1));">1</a>
|
||||
<span tal:condition="python: 2 not in (batch.prevlist or batch.leapback)"
|
||||
tal:omit-tag="">
|
||||
…
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<span class="pager">Page : </span>
|
||||
|
||||
<tal:comment tal:condition="nothing">
|
||||
Pagelist with quantum leap links to previous pages for quick navigation
|
||||
</tal:comment>
|
||||
<span tal:repeat="linklist python:batch.navurls(batchlinkparams, batch.leapback)"
|
||||
tal:condition="batch/leapback"
|
||||
tal:omit-tag="" >
|
||||
<a href=""
|
||||
tal:define="page python:linklist[0];
|
||||
query python:linklist[1];"
|
||||
tal:content="page"
|
||||
tal:attributes="href python: '%s?%s' % (url,query)" >
|
||||
</a>
|
||||
…
|
||||
</span>
|
||||
|
||||
<tal:comment tal:condition="nothing">
|
||||
Pagelist with links to previous pages for quick navigation
|
||||
</tal:comment>
|
||||
<span tal:repeat="linklist python:batch.prevurls(batchlinkparams)"
|
||||
tal:condition="batch/prevlist"
|
||||
tal:omit-tag="" >
|
||||
<a href=""
|
||||
tal:define="page python:linklist[0];
|
||||
query python:linklist[1];"
|
||||
tal:content="page"
|
||||
tal:attributes="href python: '%s?%s' % (url,query)" >
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<tal:comment tal:replace="nothing">
|
||||
Current page
|
||||
</tal:comment>
|
||||
<span tal:condition="batch/navlist" class="current"
|
||||
tal:content="batch/pagenumber">Current page number</span>
|
||||
|
||||
<tal:comment tal:replace="nothing">
|
||||
Pagelist with links to next pages for quick navigation
|
||||
</tal:comment>
|
||||
<span tal:repeat="linklist python:batch.nexturls(batchlinkparams)"
|
||||
tal:condition="batch/nextlist"
|
||||
tal:omit-tag="" >
|
||||
<a href=""
|
||||
tal:define="page python:linklist[0];
|
||||
query python:linklist[1];"
|
||||
tal:content="page"
|
||||
tal:attributes="href python: '%s?%s' % (url,query)" >
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<tal:comment tal:replace="nothing">
|
||||
Pagelist with quantum leap links to next pages for quick navigation
|
||||
</tal:comment>
|
||||
<span tal:repeat="linklist python:batch.navurls(batchlinkparams, batch.leapforward)"
|
||||
tal:condition="batch/leapforward"
|
||||
tal:omit-tag="" >
|
||||
…
|
||||
<a href=""
|
||||
tal:define="page python:linklist[0];
|
||||
query python:linklist[1];"
|
||||
tal:content="page"
|
||||
tal:attributes="href python: '%s?%s' % (url,query)" >
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<tal:comment tal:replace="nothing">
|
||||
Link to last
|
||||
</tal:comment>
|
||||
<span tal:condition="python:batch.numpages not in batch.navlist">
|
||||
<span tal:condition="python: batch.numpages - 1 not in (batch.nextlist or batch.leapforward)"
|
||||
tal:omit-tag="">
|
||||
…
|
||||
</span>
|
||||
<a href=""
|
||||
tal:attributes="href python: '%s?%s' % (url,batch.pageurl(batchlinkparams,batch.numpages));"
|
||||
tal:content="batch/numpages">3457</a>
|
||||
</span>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -9,6 +9,13 @@
|
|||
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
<tal:block tal:define="Batch python:modules['Products.CMFPlone'].Batch;
|
||||
mq python:modules['ZTUtils'].make_query;
|
||||
url batch_base_url | request/ACTUAL_URL;
|
||||
batchformkeys batchformkeys|nothing;
|
||||
batchlinkparams python:batchformkeys and dict([(key, unicode(request.form[key]).encode('utf-8')) for key in batchformkeys if key in request]) or dict([(key, unicode(request.form[key]).encode('utf-8')) for key in request.form]);
|
||||
b_size python:10; b_size request/b_size | b_size;
|
||||
b_start python:0;b_start request/b_start | b_start;">
|
||||
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
<h1 class="documentFirstHeading" tal:content="context/title" />
|
||||
|
@ -20,16 +27,8 @@
|
|||
<div tal:replace="structure view/document_search_form"/>
|
||||
|
||||
|
||||
<div tal:define="Batch python:modules['Products.CMFPlone'].Batch;
|
||||
mq python:modules['ZTUtils'].make_query;
|
||||
url batch_base_url | request/ACTUAL_URL;
|
||||
batchformkeys batchformkeys|nothing;
|
||||
batchlinkparams python:batchformkeys and dict([(key, unicode(request.form[key]).encode('utf-8')) for key in batchformkeys if key in request]) or dict([(key, unicode(request.form[key]).encode('utf-8')) for key in request.form]);
|
||||
search_results view/document_search_results;
|
||||
b_size python:10; b_size request/b_size | b_size;
|
||||
b_start python:0;b_start request/b_start | b_start;
|
||||
search_batch python:Batch(search_results or [], b_size,
|
||||
int(b_start), orphan=1);"
|
||||
<div tal:define="search_results view/document_search_results;
|
||||
search_batch python:Batch(search_results or [], b_size, int(b_start), orphan=1);"
|
||||
tal:condition="python: search_results is not None">
|
||||
|
||||
<div id="resultsbox">
|
||||
|
@ -48,14 +47,9 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="results-nav" tal:define="p search_batch/previous | nothing;
|
||||
n search_batch/next | nothing">
|
||||
<a tal:condition="p" id="results-nav-prev" href="#"
|
||||
tal:attributes="href python: '%s?%s' % (url , mq( batchlinkparams, {search_batch.b_start_str:p.first} ))"
|
||||
>Précédent</a>
|
||||
<a tal:condition="n" id="results-nav-next" href="#"
|
||||
tal:attributes="href python: '%s?%s' % (url , mq( batchlinkparams, {search_batch.b_start_str:n.first} ))">Suivant</a>
|
||||
</div>
|
||||
<div tal:define="batch search_batch">
|
||||
<div metal:use-macro="view/batch_macros/macros/navigation" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -64,16 +58,8 @@
|
|||
<dd id="fieldset-dossiers">
|
||||
<div tal:replace="structure view/dossier_search_form"/>
|
||||
|
||||
<div tal:define="Batch python:modules['Products.CMFPlone'].Batch;
|
||||
mq python:modules['ZTUtils'].make_query;
|
||||
url batch_base_url | request/ACTUAL_URL;
|
||||
batchformkeys batchformkeys|nothing;
|
||||
batchlinkparams python:batchformkeys and dict([(key, unicode(request.form[key]).encode('utf-8')) for key in batchformkeys if key in request]) or dict([(key, unicode(request.form[key]).encode('utf-8')) for key in request.form]);
|
||||
search_results view/dossier_search_results;
|
||||
b_size python:10; b_size request/b_size | b_size;
|
||||
b_start python:0;b_start request/b_start | b_start;
|
||||
search_batch python:Batch(search_results or [], b_size,
|
||||
int(b_start), orphan=1);"
|
||||
<div tal:define="search_results view/dossier_search_results;
|
||||
search_batch python:Batch(search_results or [], b_size, int(b_start), orphan=1);"
|
||||
tal:condition="python: search_results is not None">
|
||||
|
||||
<input name="fieldset.current" type="hidden" value="#fieldset-dossiers"/>
|
||||
|
@ -93,14 +79,9 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="results-nav" tal:define="p search_batch/previous | nothing;
|
||||
n search_batch/next | nothing">
|
||||
<a tal:condition="p" id="results-nav-prev" href="#"
|
||||
tal:attributes="href python: '%s?%s' % (url , mq( batchlinkparams, {search_batch.b_start_str:p.first} ))"
|
||||
>Précédent</a>
|
||||
<a tal:condition="n" id="results-nav-next" href="#"
|
||||
tal:attributes="href python: '%s?%s' % (url , mq( batchlinkparams, {search_batch.b_start_str:n.first} ))">Suivant</a>
|
||||
</div>
|
||||
<div tal:define="batch search_batch">
|
||||
<div metal:use-macro="view/batch_macros/macros/navigation" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -109,16 +90,8 @@
|
|||
<dd id="fieldset-questions">
|
||||
<div tal:replace="structure view/question_search_form"/>
|
||||
|
||||
<div tal:define="Batch python:modules['Products.CMFPlone'].Batch;
|
||||
mq python:modules['ZTUtils'].make_query;
|
||||
url batch_base_url | request/ACTUAL_URL;
|
||||
batchformkeys batchformkeys|nothing;
|
||||
batchlinkparams python:batchformkeys and dict([(key, unicode(request.form[key]).encode('utf-8')) for key in batchformkeys if key in request]) or dict([(key, unicode(request.form[key]).encode('utf-8')) for key in request.form]);
|
||||
search_results view/question_search_results;
|
||||
b_size python:10; b_size request/b_size | b_size;
|
||||
b_start python:0;b_start request/b_start | b_start;
|
||||
search_batch python:Batch(search_results or [], b_size,
|
||||
int(b_start), orphan=1);"
|
||||
<div tal:define="search_results view/question_search_results;
|
||||
search_batch python:Batch(search_results or [], b_size, int(b_start), orphan=1);"
|
||||
tal:condition="python: search_results is not None">
|
||||
|
||||
<input name="fieldset.current" type="hidden" value="#fieldset-questions"/>
|
||||
|
@ -138,19 +111,12 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="results-nav" tal:define="p search_batch/previous | nothing;
|
||||
n search_batch/next | nothing">
|
||||
<a tal:condition="p" id="results-nav-prev" href="#"
|
||||
tal:attributes="href python: '%s?%s' % (url , mq( batchlinkparams, {search_batch.b_start_str:p.first} ))"
|
||||
>Précédent</a>
|
||||
<a tal:condition="n" id="results-nav-next" href="#"
|
||||
tal:attributes="href python: '%s?%s' % (url , mq( batchlinkparams, {search_batch.b_start_str:n.first} ))">Suivant</a>
|
||||
</div>
|
||||
<div tal:define="batch search_batch">
|
||||
<div metal:use-macro="view/batch_macros/macros/navigation" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt id="fieldsetlegend-decrets">Décrets</dt>
|
||||
<dd id="fieldset-decrets">
|
||||
|
@ -191,6 +157,7 @@ function author_autocomplete_ready(event, data, formatted) {
|
|||
})(jQuery);
|
||||
</script>
|
||||
|
||||
</tal:block>
|
||||
</tal:main-macro>
|
||||
</metal:main>
|
||||
|
||||
|
|
|
@ -312,6 +312,8 @@ class GlobalSearchForm(form.Form):
|
|||
ignoreContext = True
|
||||
|
||||
class SearchView(BrowserView):
|
||||
batch_macros = ViewPageTemplateFile('batch_macros.pt')
|
||||
|
||||
def search_results(self, search_type):
|
||||
|
||||
if self.request.form.get('document.widgets.search_type_is_document'):
|
||||
|
|
Reference in New Issue