rewrite simple search to address comments in #786
This commit is contained in:
parent
90554395ac
commit
b2886dc448
|
@ -62,7 +62,8 @@
|
|||
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
|
||||
name="search2"
|
||||
class=".simple.SimpleSearchView"
|
||||
permission="zope2.View"/>
|
||||
permission="zope2.View"
|
||||
template="simple.pt"/>
|
||||
|
||||
<browser:page
|
||||
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
xmlns:metal="http://xml.zope.org/namespaces/metal">
|
||||
<body
|
||||
tal:define="Batch python:modules['Products.CMFPlone'].Batch;
|
||||
xmlns:metal="http://xml.zope.org/namespaces/metal"
|
||||
metal:use-macro="context/main_template/macros/master">
|
||||
<body>
|
||||
|
||||
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
|
||||
<div id="simplesearch"
|
||||
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]);
|
||||
deputy_results view/deputy_results;
|
||||
page_results view/page_results;
|
||||
doc_results view/doc_results;
|
||||
event_results view/event_results;
|
||||
b_size python:10; b_size request/b_size | b_size;
|
||||
b_size python:5; b_size request/b_size | b_size;
|
||||
b_start python:0;b_start request/b_start | b_start;
|
||||
deputy_batch python:Batch(deputy_results, b_size, int(b_start), orphan=1);
|
||||
page_batch python:Batch(page_results, b_size, int(b_start), orphan=1);
|
||||
|
@ -20,69 +26,75 @@
|
|||
event_batch python:Batch(event_results, b_size, int(b_start), orphan=1);
|
||||
">
|
||||
<form method="get" action="search2">
|
||||
<metal:use use-macro="context/@@ploneform-macros/fields" />
|
||||
<metal:use use-macro="context/@@ploneform-macros/actions" />
|
||||
<input name="SearchableText" type="text"
|
||||
tal:attributes="value python: request.form.get('SearchableText')"/>
|
||||
<input type="submit" value="Recherche"/>
|
||||
</form>
|
||||
|
||||
<div id="deputies-results" tal:condition="python:len(deputy_results)">
|
||||
<h2>Députés <span>(<span tal:content="python:len(deputy_results)"/>)</span></h2>
|
||||
<h2>Députés</h2>
|
||||
<div class="resultsinfobox">
|
||||
<span>Nombre de résultats : <span tal:replace="python:len(deputy_results)"/></span>
|
||||
<a tal:attributes="href view/deputy_form_url">Filtre avancé</a>
|
||||
</div>
|
||||
|
||||
<div class="results">
|
||||
<ul>
|
||||
<tal:entry tal:repeat="deputy deputy_batch">
|
||||
<tal:entry tal:repeat="deputy python: deputy_batch">
|
||||
<li tal:define="oddrow repeat/deputy/odd;" tal:attributes="class python: oddrow and 'odd' or 'even'"><div>
|
||||
<h4><a href="#" tal:attributes="href deputy/getURL" tal:content="deputy/Title">Véronique Salvi</a></h4>
|
||||
<p class="intitule" tal:define="deputy_object python: deputy.getObject()">
|
||||
Groupe politique : <span tal:content="deputy_object/polgroup/to_object/title"/>
|
||||
<tal:block tal:condition="deputy_object/district">
|
||||
-
|
||||
Arrondissement : <span tal:content="deputy_object/district"/>
|
||||
</tal:block>
|
||||
<tal:block tal:condition="not: deputy_object/active">
|
||||
-
|
||||
<i>Ce député ne siège plus.</i>
|
||||
</tal:block>
|
||||
</p>
|
||||
</div></li>
|
||||
</tal:entry>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div tal:define="batch deputy_batch">
|
||||
<div metal:use-macro="view/batch_macros/macros/navigation" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="docs-results" tal:condition="python:len(doc_results)">
|
||||
<h2>Documents et dossiers <span>(<span tal:content="python:len(doc_results)"/>)</span></h2>
|
||||
<h2>Documents et dossiers</h2>
|
||||
<div class="resultsinfobox">
|
||||
<span>Nombre de résultats : <span tal:replace="python:len(doc_results)"/></span>
|
||||
<a tal:attributes="href view/docdos_form_url">Filtre avancé</a>
|
||||
</div>
|
||||
|
||||
<div class="results">
|
||||
<ul>
|
||||
<tal:entry tal:repeat="doc doc_batch">
|
||||
<li tal:define="oddrow repeat/doc/odd;" tal:attributes="class python: oddrow and 'odd' or 'even'"><div>
|
||||
<h4><a href="#" tal:attributes="href doc/getURL" tal:content="doc/Title">Véronique Salvi</a></h4>
|
||||
<h4><a href="#" tal:attributes="href doc/getURL" tal:content="python: doc.getObject().reftitle">Véronique Salvi</a></h4>
|
||||
<p class="intitule" tal:content="doc/Title"/>
|
||||
</div></li>
|
||||
</tal:entry>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<span class="previous"
|
||||
tal:define="p doc_batch/previous | nothing"
|
||||
tal:condition="p">
|
||||
<a href=""
|
||||
tal:attributes="href python: '%s?%s' % (url , mq( batchlinkparams, {doc_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>
|
||||
|
||||
<span class="next"
|
||||
tal:define="n doc_batch/next | nothing"
|
||||
tal:condition="n">
|
||||
<a href=""
|
||||
tal:attributes="href python: '%s?%s' % (url , mq( batchlinkparams, {doc_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>
|
||||
<div tal:define="batch doc_batch">
|
||||
<div metal:use-macro="view/batch_macros/macros/navigation" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="events-results" tal:condition="python:len(event_results)">
|
||||
<h2>Événements <span>(<span tal:content="python:len(event_results)"/>)</span></h2>
|
||||
<h2>Événements</h2>
|
||||
<div class="resultsinfobox">
|
||||
<span>Nombre de résultats : <span tal:replace="python:len(event_results)"/></span>
|
||||
<a tal:attributes="href view/event_form_url">Filtre avancé</a>
|
||||
</div>
|
||||
|
||||
<div class="results">
|
||||
<ul>
|
||||
|
@ -93,10 +105,18 @@
|
|||
</tal:entry>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div tal:define="batch event_batch">
|
||||
<div metal:use-macro="view/batch_macros/macros/navigation" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="pages-results" tal:condition="python:len(page_results)">
|
||||
<h2>Ailleurs sur le site <span>(<span tal:content="python:len(page_results)"/>)</span></h2>
|
||||
<h2>Ailleurs sur le site</h2>
|
||||
<div class="resultsinfobox">
|
||||
<span>Nombre de résultats : <span tal:replace="python:len(page_results)"/></span>
|
||||
</div>
|
||||
|
||||
<div class="results">
|
||||
<ul>
|
||||
|
@ -108,7 +128,16 @@
|
|||
</tal:entry>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div tal:define="batch page_batch">
|
||||
<div metal:use-macro="view/batch_macros/macros/navigation" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</tal:main-macro>
|
||||
</metal:main>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -13,62 +13,51 @@ from tabellio.searchform.interfaces import MessageFactory as _
|
|||
from Products.Five import BrowserView
|
||||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
||||
|
||||
class ISearch(interface.Interface):
|
||||
SearchableText = schema.TextLine(title=_(u'Text'), required=False)
|
||||
class SimpleSearchView(BrowserView):
|
||||
batch_macros = ViewPageTemplateFile('batch_macros.pt')
|
||||
|
||||
def deputy_form_url(self):
|
||||
return '#'
|
||||
|
||||
class SearchForm(form.Form):
|
||||
fields = field.Fields(ISearch)
|
||||
ignoreContext = True
|
||||
template = ViewPageTemplateFile('simple_templates/view_effectivesearch.pt')
|
||||
def docdos_form_url(self):
|
||||
return '#'
|
||||
|
||||
def event_form_url(self):
|
||||
return '#'
|
||||
|
||||
def deputy_results(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
data, errors = self.extractData()
|
||||
if data.get('SearchableText') is None:
|
||||
if not self.request.form.get('SearchableText'):
|
||||
return []
|
||||
return catalog(
|
||||
portal_type=['themis.datatypes.deputy'],
|
||||
SearchableText=data.get('SearchableText'),
|
||||
sort_on="sortable_title", sort_order='ascending', sort_limit=20)
|
||||
SearchableText=self.request.form.get('SearchableText'),
|
||||
sort_on="sortable_title", sort_order='ascending')
|
||||
|
||||
def page_results(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
data, errors = self.extractData()
|
||||
if data.get('SearchableText') is None:
|
||||
if not self.request.form.get('SearchableText'):
|
||||
return []
|
||||
return catalog(
|
||||
portal_type=['Document', 'File', 'Folder', 'Link'],
|
||||
SearchableText=data.get('SearchableText'),
|
||||
sort_on='created', sort_order='descending', sort_limit=20)
|
||||
SearchableText=self.request.form.get('SearchableText'),
|
||||
sort_on='created', sort_order='descending')
|
||||
|
||||
def doc_results(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
data, errors = self.extractData()
|
||||
if data.get('SearchableText') is None:
|
||||
if not self.request.form.get('SearchableText'):
|
||||
return []
|
||||
return catalog(
|
||||
portal_type=['tabellio.documents.dossier',
|
||||
'tabellio.documents.document',
|
||||
'tabellio.documents.question'],
|
||||
SearchableText=data.get('SearchableText'))
|
||||
SearchableText=self.request.form.get('SearchableText'))
|
||||
|
||||
def event_results(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
data, errors = self.extractData()
|
||||
if data.get('SearchableText') is None:
|
||||
if not self.request.form.get('SearchableText'):
|
||||
return []
|
||||
return catalog(
|
||||
portal_type=['tabellio.agenda.parlevent', 'tabellio.agenda.event'],
|
||||
SearchableText=data.get('SearchableText'))
|
||||
|
||||
@button.buttonAndHandler(u'Search')
|
||||
def handleApply(self, action):
|
||||
data, errors = self.extractData()
|
||||
if not errors:
|
||||
plone_utils = getToolByName(self.context, 'plone_utils')
|
||||
plone_utils.addPortalMessage(_('Your search has been completed!'))
|
||||
return
|
||||
|
||||
SimpleSearchView = wrap_form(SearchForm)
|
||||
SearchableText=self.request.form.get('SearchableText'))
|
||||
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
xmlns:metal="http://xml.zope.org/namespaces/metal"
|
||||
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
|
||||
lang="en"
|
||||
metal:use-macro="context/main_template/macros/master"
|
||||
i18n:domain="tabellio.searchform">
|
||||
<body>
|
||||
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
<h1 class="documentFirstHeading" tal:content="context/title" />
|
||||
<div tal:replace="structure provider:plone.belowcontenttitle" />
|
||||
|
||||
<div tal:replace="structure view/search_form"/>
|
||||
|
||||
<div tal:replace="structure provider:plone.belowcontentbody" />
|
||||
|
||||
</tal:main-macro>
|
||||
</metal:main>
|
||||
|
||||
</body>
|
||||
</html>
|
Reference in New Issue