extend support to other search types
This commit is contained in:
parent
8ebb66ca12
commit
9129df08db
|
@ -25,12 +25,12 @@
|
|||
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/search_results;
|
||||
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, b_size,
|
||||
search_batch python:Batch(search_results or [], b_size,
|
||||
int(b_start), orphan=1);"
|
||||
tal:condition="search_results">
|
||||
tal:condition="python: search_results is not None">
|
||||
|
||||
<div id="resultsbox">
|
||||
<span>Nombre de résultats : <span tal:replace="python: len(search_results)"/></span>
|
||||
|
@ -50,22 +50,109 @@
|
|||
|
||||
<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="#">Précédent</a>
|
||||
<a tal:condition="n" id="results-nav-next" href="#">Suivant</a>
|
||||
<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>
|
||||
|
||||
</dd>
|
||||
<dt id="fieldset-legend-dossiers">Dossiers parlementaires</dt>
|
||||
<dt id="fieldsetlegend-dossiers">Dossiers parlementaires</dt>
|
||||
<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);"
|
||||
tal:condition="python: search_results is not None">
|
||||
|
||||
<input name="fieldset.current" type="hidden" value="#fieldset-dossiers"/>
|
||||
<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="python: object.reftitle">Véronique Salvi</a></h4>
|
||||
<p class="intitule" tal:content="item/Title"/>
|
||||
<p class="authors" tal:condition="python: object.authors">Auteur(s) : <span tal:replace="python: object.get_authors_as_string()" tal:condition="python: object.authors" /></p>
|
||||
</div></li>
|
||||
</tal:entry>
|
||||
</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>
|
||||
|
||||
</dd>
|
||||
<dt id="fielset-legend-questions">Questions & interpellations</dt>
|
||||
<dt id="fieldsetlegend-questions">Questions & interpellations</dt>
|
||||
<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);"
|
||||
tal:condition="python: search_results is not None">
|
||||
|
||||
<input name="fieldset.current" type="hidden" value="#fieldset-questions"/>
|
||||
<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="python: object.reftitle">Véronique Salvi</a></h4>
|
||||
<p class="intitule" tal:content="item/Title"/>
|
||||
<p class="authors" tal:condition="python: object.authors">Auteur(s) : <span tal:replace="python: object.get_authors_as_string()" tal:condition="python: object.authors" /></p>
|
||||
</div></li>
|
||||
</tal:entry>
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt id="fieldset-legend-decrets">Décrets</dt>
|
||||
<dt id="fieldsetlegend-decrets">Décrets</dt>
|
||||
<dd id="fieldset-decrets">
|
||||
</dd>
|
||||
</dl>
|
||||
|
|
|
@ -48,9 +48,20 @@ def possible_dossier_types(context):
|
|||
terms.append(SimpleVocabulary.createTerm(dostype_id, dostype_id, dostype))
|
||||
return SimpleVocabulary(terms)
|
||||
|
||||
@grok.provider(IContextSourceBinder)
|
||||
def possible_question_types(context):
|
||||
catalog = getToolByName(context, 'portal_catalog')
|
||||
possible_questypes = catalog.uniqueValuesFor('questype')
|
||||
terms = []
|
||||
for questype in possible_questypes:
|
||||
if not questype:
|
||||
continue
|
||||
questype_id = questype.encode('ascii', 'replace')
|
||||
terms.append(SimpleVocabulary.createTerm(questype_id, questype_id, questype))
|
||||
return SimpleVocabulary(terms)
|
||||
|
||||
class IDocumentSearch(interface.Interface):
|
||||
search_type = schema.TextLine(title=u'Search Type', default=u'document')
|
||||
search_type_is_document = schema.TextLine(title=u'Search Type', default=u'1', required=False)
|
||||
nodoc = schema.TextLine(title=_(u'Document Number'), required=False)
|
||||
nosuite = schema.TextLine(title=_(u'Suite Number'), required=False)
|
||||
doctype = schema.Choice(title=_(u'Type'), required=False,
|
||||
|
@ -76,7 +87,7 @@ class DocumentSearchForm(form.Form):
|
|||
|
||||
def updateWidgets(self):
|
||||
super(DocumentSearchForm, self).updateWidgets()
|
||||
self.widgets['search_type'].mode = z3c.form.interfaces.HIDDEN_MODE
|
||||
self.widgets['search_type_is_document'].mode = z3c.form.interfaces.HIDDEN_MODE
|
||||
|
||||
@button.buttonAndHandler(_(u'Search'))
|
||||
def handleApply(self, action):
|
||||
|
@ -89,6 +100,8 @@ class DocumentSearchForm(form.Form):
|
|||
|
||||
|
||||
class IDossierSearch(interface.Interface):
|
||||
search_type_is_dossier = schema.TextLine(title=u'Search Type', default=u'1', required=False)
|
||||
|
||||
nodos = schema.TextLine(title=_(u'Dossier Number'), required=False)
|
||||
dostype = schema.Choice(title=_(u'Type'), required=False,
|
||||
source=possible_dossier_types)
|
||||
|
@ -110,6 +123,10 @@ class DossierSearchForm(form.Form):
|
|||
ignoreContext = True
|
||||
template = ViewPageTemplateFile('form_templates/view_dossier_search.pt')
|
||||
|
||||
def updateWidgets(self):
|
||||
super(DossierSearchForm, self).updateWidgets()
|
||||
self.widgets['search_type_is_dossier'].mode = z3c.form.interfaces.HIDDEN_MODE
|
||||
|
||||
@button.buttonAndHandler(_(u'Search'))
|
||||
def handleApply(self, action):
|
||||
data, errors = self.extractData()
|
||||
|
@ -121,9 +138,10 @@ class DossierSearchForm(form.Form):
|
|||
|
||||
|
||||
class IQuestionSearch(interface.Interface):
|
||||
nodos = schema.TextLine(title=_(u'Question Number'), required=False)
|
||||
dostype = schema.Set(title=_(u'Type'), required=False,
|
||||
value_type=schema.Choice(values=[_(u'Lorem'), _(u'Ipsum')]))
|
||||
search_type_is_question = schema.TextLine(title=u'Search Type', default=u'1', required=False)
|
||||
|
||||
questype = schema.Choice(title=_(u'Type'), required=False,
|
||||
source=possible_question_types)
|
||||
#subjects =
|
||||
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
||||
authors = RelationList(title=_(u'Authors'), default=[], required=False,
|
||||
|
@ -141,6 +159,10 @@ class QuestionSearchForm(form.Form):
|
|||
ignoreContext = True
|
||||
template = ViewPageTemplateFile('form_templates/view_question_search.pt')
|
||||
|
||||
def updateWidgets(self):
|
||||
super(QuestionSearchForm, self).updateWidgets()
|
||||
self.widgets['search_type_is_question'].mode = z3c.form.interfaces.HIDDEN_MODE
|
||||
|
||||
@button.buttonAndHandler(_(u'Search'))
|
||||
def handleApply(self, action):
|
||||
data, errors = self.extractData()
|
||||
|
@ -152,6 +174,8 @@ class QuestionSearchForm(form.Form):
|
|||
|
||||
|
||||
class IDocumentPfbSearch(interface.Interface):
|
||||
search_type_is_document = schema.TextLine(title=u'Search Type', default=u'1')
|
||||
|
||||
nodoc = schema.TextLine(title=_(u'Document Number'), required=False)
|
||||
doctype = schema.Choice(title=_(u'Type'), required=False,
|
||||
source=possible_document_types)
|
||||
|
@ -177,6 +201,10 @@ class DocumentPfbSearchForm(form.Form):
|
|||
ignoreContext = True
|
||||
template = ViewPageTemplateFile('form_templates/view_pfbdocsearch.pt')
|
||||
|
||||
def updateWidgets(self):
|
||||
super(DocumentPfbSearchForm, self).updateWidgets()
|
||||
self.widgets['search_type_is_document'].mode = z3c.form.interfaces.HIDDEN_MODE
|
||||
|
||||
@button.buttonAndHandler(_(u'Search'))
|
||||
def handleApply(self, action):
|
||||
data, errors = self.extractData()
|
||||
|
@ -188,7 +216,9 @@ class DocumentPfbSearchForm(form.Form):
|
|||
|
||||
|
||||
class IGlobalSearchForm(interface.Interface):
|
||||
search_type = schema.TextLine(title=u'Search Type')
|
||||
search_type_is_document = schema.TextLine(title=u'Search Type', required=False)
|
||||
search_type_is_dossier = schema.TextLine(title=u'Search Type', required=False)
|
||||
search_type_is_question = schema.TextLine(title=u'Search Type', required=False)
|
||||
|
||||
nodoc = schema.TextLine(title=_(u'Document Number'), required=False)
|
||||
nosuite = schema.TextLine(title=_(u'Suite Number'), required=False)
|
||||
|
@ -199,8 +229,10 @@ class IGlobalSearchForm(interface.Interface):
|
|||
dostype = schema.Choice(title=_(u'Type'), required=False,
|
||||
source=possible_dossier_types)
|
||||
|
||||
#subjects =
|
||||
#subjects =
|
||||
questype = schema.Choice(title=_(u'Type'), required=False,
|
||||
source=possible_question_types)
|
||||
|
||||
#subjects =
|
||||
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
||||
text = schema.TextLine(title=_(u'Text'), required=False)
|
||||
authors = RelationList(title=_(u'Authors'), default=[], required=False,
|
||||
|
@ -218,17 +250,25 @@ class GlobalSearchForm(form.Form):
|
|||
ignoreContext = True
|
||||
|
||||
class SearchView(BrowserView):
|
||||
def search_results(self):
|
||||
def search_results(self, search_type):
|
||||
f = GlobalSearchForm(self.context, self.request)
|
||||
f.update()
|
||||
data, errors = f.extractData()
|
||||
|
||||
kw = {}
|
||||
|
||||
if data.get('search_type') == 'document':
|
||||
print data
|
||||
|
||||
if not data.get('search_type_is_%s' % search_type):
|
||||
print 'not the right pane'
|
||||
return None
|
||||
|
||||
if data.get('search_type_is_document'):
|
||||
kw['portal_type'] = 'tabellio.documents.document'
|
||||
elif data.get('search_type') == 'dossier':
|
||||
elif data.get('search_type_is_dossier'):
|
||||
kw['portal_type'] = 'tabellio.documents.dossier'
|
||||
elif data.get('search_type_is_question'):
|
||||
kw['portal_type'] = 'tabellio.documents.question'
|
||||
|
||||
if data.get('ttitle'):
|
||||
kw['Title'] = data.get('ttitle')
|
||||
|
@ -245,7 +285,7 @@ class SearchView(BrowserView):
|
|||
if data.get('doctype'):
|
||||
kw['doctype'] = possible_document_types(self.context).getTermByToken(data.get('doctype')).title
|
||||
if data.get('dostype'):
|
||||
kw['dostype'] = possible_dossier_types(self.context).getTermByToken(data.get('doctype')).title
|
||||
kw['dostype'] = possible_dossier_types(self.context).getTermByToken(data.get('dostype')).title
|
||||
if data.get('start') and data.get('end'):
|
||||
kw['dateDoc'] = {'query': [data.get('start'), data.get('end')], 'range': 'minmax'}
|
||||
elif data.get('start'):
|
||||
|
@ -263,10 +303,12 @@ class SearchView(BrowserView):
|
|||
if not kw:
|
||||
return []
|
||||
|
||||
if not kw.get('sort_on'):
|
||||
if not kw.get('sort_on') and data.get('search_type_is_document'):
|
||||
kw['sort_on'] = 'dateDoc'
|
||||
kw['sort_order'] = 'descending'
|
||||
|
||||
print 'kw:', kw
|
||||
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
return catalog(**kw)
|
||||
|
||||
|
@ -280,13 +322,22 @@ class SearchView(BrowserView):
|
|||
f.update()
|
||||
return f.render()
|
||||
|
||||
def document_search_results(self):
|
||||
return self.search_results(search_type='document')
|
||||
|
||||
def dossier_search_form(self):
|
||||
f = DossierSearchForm(self.context, self.request)
|
||||
f.update()
|
||||
return f.render()
|
||||
|
||||
def dossier_search_results(self):
|
||||
return self.search_results(search_type='dossier')
|
||||
|
||||
def question_search_form(self):
|
||||
f = QuestionSearchForm(self.context, self.request)
|
||||
f.update()
|
||||
return f.render()
|
||||
|
||||
def question_search_results(self):
|
||||
return self.search_results(search_type='question')
|
||||
|
||||
|
|
Reference in New Issue