add event search

This commit is contained in:
Frédéric Péters 2011-11-20 20:18:21 +01:00
parent 4498a81e96
commit 228e39661b
6 changed files with 219 additions and 10 deletions

View File

@ -86,6 +86,13 @@
template="guided-search.pt"
permission="zope2.View"/>
<browser:page
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
name="eventsearch"
class=".form.SearchView"
permission="zope2.View"
template="eventsearch.pt"/>
<z3c:widgetTemplate
mode="input"
widget=".form.IAuthorsWidget"

View File

@ -23,7 +23,9 @@
<dl class="enableFormTabbing" id="search-tabs">
<dt id="fieldsetlegend-documents">Documents parlementaires</dt>
<dd id="fieldset-documents">
<form method="post" action="./#resultsbox">
<div tal:replace="structure view/document_search_form"/>
</form>
<div tal:define="search_results view/document_search_results;
@ -47,10 +49,8 @@
</div>
<div tal:define="batch search_batch">
<form method="get" action="./#resultsbox">
<div metal:use-macro="view/batch_macros/macros/navigation" />
<div metal:use-macro="view/batch_macros/macros/feed" />
</form>
</div>
</div>
@ -58,7 +58,9 @@
</dd>
<dt id="fieldsetlegend-dossiers">Dossiers parlementaires</dt>
<dd id="fieldset-dossiers">
<form method="post" action="./#resultsbox">
<div tal:replace="structure view/dossier_search_form"/>
</form>
<div tal:define="search_results view/dossier_search_results;
search_batch python:Batch(list(search_results or []), b_size, int(b_start), orphan=1);"
@ -82,10 +84,8 @@
</div>
<div tal:define="batch search_batch">
<form method="get" action="./#resultsbox">
<div metal:use-macro="view/batch_macros/macros/navigation" />
<div metal:use-macro="view/batch_macros/macros/feed" />
</form>
</div>
</div>
@ -93,7 +93,9 @@
</dd>
<dt id="fieldsetlegend-questions">Questions &amp; interpellations</dt>
<dd id="fieldset-questions">
<form method="post" action="./#resultsbox">
<div tal:replace="structure view/question_search_form"/>
</form>
<div tal:define="search_results view/question_search_results;
search_batch python:Batch(list(search_results or []), b_size, int(b_start), orphan=1);"
@ -117,10 +119,8 @@
</div>
<div tal:define="batch search_batch">
<form method="get" action="./#resultsbox">
<div metal:use-macro="view/batch_macros/macros/navigation" />
<div metal:use-macro="view/batch_macros/macros/feed" />
</form>
</div>
</div>

View File

@ -51,10 +51,8 @@
</div>
<div tal:define="batch search_batch">
<form method="get" action="./#resultsbox">
<div metal:use-macro="view/batch_macros/macros/navigation" />
<div metal:use-macro="view/batch_macros/macros/feed" />
</form>
</div>
</div>
@ -89,10 +87,8 @@
</div>
<div tal:define="batch search_batch">
<form method="get" action="./#resultsbox">
<div metal:use-macro="view/batch_macros/macros/navigation" />
<div metal:use-macro="view/batch_macros/macros/feed" />
</form>
</div>
</div>

View File

@ -0,0 +1,126 @@
<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">
<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;
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">Événements</h1>
<div tal:replace="structure provider:plone.belowcontenttitle" />
<form method="post" action="./eventsearch#resultsbox">
<div tal:replace="structure view/event_search_form"/>
</form>
<div tal:define="search_results view/event_search_results;
search_batch python:Batch(list(search_results or []), b_size, int(b_start), orphan=1);"
tal:condition="python: search_results is not None">
<div id="resultsbox">
<span>Nombre de résultats : <span tal:replace="python: len(search_results)"/></span>
</div>
<div id="results">
<ul>
<tal:entry tal:repeat="item search_batch">
<li tal:define="oddrow repeat/item/odd; object python: item.getObject()" tal:attributes="class python: oddrow and 'odd' or 'even'"><div>
<h4><a href="#" tal:attributes="href item/getURL" tal:content="item/Title">Véronique Salvi</a></h4>
<p><span tal:replace="item/start/day"/> <span tal:replace="python: item.getObject().start_month()">mars</span></p>
</div></li>
</tal:entry>
</ul>
</div>
<div tal:define="batch search_batch">
<div metal:use-macro="view/batch_macros/macros/navigation" />
</div>
</div>
<div tal:replace="structure provider:plone.belowcontentbody" />
<script type="text/javascript" tal:content="string: var PORTAL_URL='${view/portal_url}';"/>
<script type="text/javascript">
function update_input(input) {
var s = '';
jq(input).nextAll('span.labelbox').each(function() {
s = s + ' ' + jq(this).attr('class').split(' ')[1];
});
jq(input).attr('value', s);
}
function create_labelbox(input_box, id, value)
{
labelbox = $('<span class="labelbox ' + id + '">' + value + '<' + '/span>');
$(labelbox).click(function() {
$(this).remove();
update_input(jq(input_box).prevAll('input')[0]);
});
return labelbox;
}
function autocomplete_ready(event, data, formatted) {
(function($) {
var input_box = $(event.target);
// XXX: don't insert item if it's already present
labelbox = create_labelbox(input_box, data[1], data[0]);
$(input_box).before(labelbox);
update_input(jq(input_box).prevAll('input')[0]);
$(input_box).attr('value', '');
}(jQuery));
}
function sync_elements(index, elem, url)
{
hidden = $(elem).prev();
values = $(hidden).attr('value').trim().split(' ');
for (i=0; i < values.length; i++) {
if (values[i]) {
labelbox = create_labelbox(elem, values[i], '...');
$(hidden).after(labelbox);
$(labelbox).load(url + '?id=' + values[i]);
}
}
}
function sync_authors(index, elem) { sync_elements(index, elem, PORTAL_URL+'/listAuthors'); }
function sync_polgroups(index, elem) { sync_elements(index, elem, PORTAL_URL+'/listPolgroups'); }
function sync_topics(index, elem) { sync_elements(index, elem, PORTAL_URL+'/listTopics'); }
if(typeof(String.prototype.trim) === "undefined") {
String.prototype.trim = function()
{
return String(this).replace(/^\s+|\s+$/g, '');
};
}
(function($) {
$().ready(function() {
$('.author-autocomplete').each(sync_authors).autocomplete(PORTAL_URL+'/listAuthors', {
}).result(autocomplete_ready);
$('.polgroup-autocomplete').each(sync_polgroups).autocomplete(PORTAL_URL+'/listPolgroups', {
}).result(autocomplete_ready);
$('.topic-autocomplete').each(sync_topics).autocomplete(PORTAL_URL+'/listTopics', {
}).result(autocomplete_ready);
});
})(jQuery);
</script>
</tal:block>
</tal:main-macro>
</metal:main>
</body>
</html>

View File

@ -462,6 +462,44 @@ class DeputySearchForm(form.Form):
def handleApply(self, action):
pass
class IEventSearch(interface.Interface):
search_type_is_event = schema.TextLine(title=u'Search Type', default=u'1', required=False)
start = schema.Date(title=_(u'Start'), required=False)
end = schema.Date(title=_(u'End'), required=False)
class EventSearchForm(form.Form):
prefix = 'event'
fields = field.Fields(IEventSearch)
ignoreContext = True
template = ViewPageTemplateFile('form_templates/view_form.pt')
def updateWidgets(self):
super(EventSearchForm, self).updateWidgets()
self.widgets['search_type_is_event'].mode = z3c.form.interfaces.HIDDEN_MODE
@button.buttonAndHandler(_(u'Submit'))
def handleApply(self, action):
pass
class DeputySearchForm(form.Form):
prefix = 'deputy'
fields = field.Fields(IDeputySearch)
ignoreContext = True
template = ViewPageTemplateFile('form_templates/view_deputy_search.pt')
def updateWidgets(self):
super(DeputySearchForm, self).updateWidgets()
self.widgets['search_type_is_deputy'].mode = z3c.form.interfaces.HIDDEN_MODE
@button.buttonAndHandler(_(u'Submit'))
def handleApply(self, action):
pass
class IGlobalSearchForm(interface.Interface):
search_type_is_document = schema.TextLine(title=u'Search Type', required=False)
search_type_is_dossier = schema.TextLine(title=u'Search Type', required=False)
@ -694,6 +732,40 @@ class SearchView(BrowserView):
def question_search_results(self):
return self.search_results(search_type='question')
def event_search_form(self):
f = EventSearchForm(self.context, self.request)
f.update()
return f.render()
def event_search_results(self):
f = EventSearchForm(self.context, self.request)
f.update()
data, errors = f.extractData()
kw = {}
print data
if not data.get('search_type_is_event'):
return None
if data.get('start') and data.get('end'):
kw['start'] = {'query': [data.get('start'), data.get('end')], 'range': 'minmax'}
elif data.get('start'):
kw['start'] = {'query': data.get('start'), 'range': 'min'}
elif data.get('end'):
kw['start'] = {'query': data.get('end'), 'range': 'max'}
kw['sort_on'] = 'start'
kw['sort_order'] = 'descending'
kw['portal_type'] = ('tabellio.agenda.event',
'tabellio.agenda.comevent',
'tabellio.agenda.parlevent')
catalog = getToolByName(self.context, 'portal_catalog')
return catalog(**kw)
def pfbdocform_url(self):
catalog = getToolByName(self.context, 'portal_catalog')
try:

View File

@ -0,0 +1,8 @@
<!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">
<body>
<metal:use use-macro="context/@@ploneform-macros/fields" />
<metal:use use-macro="context/@@ploneform-macros/actions" />
</body>
</html>