add simple search

This commit is contained in:
Frédéric Péters 2011-10-03 13:00:48 +02:00
parent 1b94a77533
commit 348075b8bb
4 changed files with 200 additions and 0 deletions

View File

@ -17,4 +17,10 @@
template="docsearch.pt"
permission="zope2.View"/>
<browser:page
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
name="search2"
class=".simple.SimpleSearchView"
permission="zope2.View"/>
</configure>

View File

@ -0,0 +1,62 @@
from zope import interface, schema
from z3c.form import form, field, button
from plone.z3cform.layout import wrap_form
from Products.CMFCore.utils import getToolByName
from z3c.form.ptcompat import ViewPageTemplateFile
from z3c.relationfield.schema import RelationChoice, RelationList
from plone.formwidget.contenttree import ObjPathSourceBinder
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 SearchForm(form.Form):
fields = field.Fields(ISearch)
ignoreContext = True
template = ViewPageTemplateFile('simple_templates/view_effectivesearch.pt')
def deputy_results(self):
catalog = getToolByName(self.context, 'portal_catalog')
data, errors = self.extractData()
return catalog(
portal_type=['themis.datatypes.deputy'],
SearchableText=data.get('SearchableText'))
def page_results(self):
catalog = getToolByName(self.context, 'portal_catalog')
data, errors = self.extractData()
return catalog(
portal_type=['Document', 'File', 'Folder', 'Link'],
SearchableText=data.get('SearchableText'))
def doc_results(self):
catalog = getToolByName(self.context, 'portal_catalog')
data, errors = self.extractData()
return catalog(
portal_type=['tabellio.documents.dossier', 'tabellio.documents.document'],
SearchableText=data.get('SearchableText'))
def event_results(self):
catalog = getToolByName(self.context, 'portal_catalog')
data, errors = self.extractData()
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)

View File

@ -0,0 +1,25 @@
<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>

View File

@ -0,0 +1,107 @@
<!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;
mq python:modules['ZTUtils'].make_query;
url batch_base_url | request/ACTUAL_URL;
batchformkeys batchformkeys|nothing;
batchlinkparams python:batchformkeys and dict([(key, request.form[key]) for key in batchformkeys
if key in request]) or 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_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);
doc_batch python:Batch(doc_results, b_size, int(b_start), orphan=1);
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" />
</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>
<div class="results">
<ul>
<li class="odd" tal:repeat="deputy deputy_batch"><div>
<h4><a href="#" tal:attributes="href deputy/getURL" tal:content="deputy/Title">Véronique Salvi</a></h4>
</div></li>
</ul>
</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>
<div class="results">
<ul>
<li class="odd" tal:repeat="doc doc_batch"><div>
<h4><a href="#" tal:attributes="href doc/getURL" tal:content="doc/Title">Véronique Salvi</a></h4>
</div></li>
</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} ))">
&laquo;
<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>
&raquo;
</a>
</span>
</div>
<div id="events-results" tal:condition="python:len(event_results)">
<h2>Événements <span>(<span tal:content="python:len(event_results)"/>)</span></h2>
<div class="results">
<ul>
<li class="odd" tal:repeat="event event_batch"><div>
<h4><a href="#" tal:attributes="href event/getURL" tal:content="event/Title">Véronique Salvi</a></h4>
</div></li>
</ul>
</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>
<div class="results">
<ul>
<li class="odd" tal:repeat="page page_batch"><div>
<h4><a href="#" tal:attributes="href page/getURL" tal:content="page/Title">Communiqué de presse</a></h4>
<p tal:content="page/Description">bla</p>
</div></li>
</ul>
</div>
</div>
</body>
</html>