add columns to doc search results

This commit is contained in:
Frédéric Péters 2011-12-19 12:20:51 +01:00
parent 109e3fa018
commit c8bf1224fb
4 changed files with 58 additions and 9 deletions

View File

@ -17,6 +17,7 @@
b_start python:0;b_start request/b_start | b_start;
results view/search_results;
batch python:Batch(list(results), b_size, int(b_start), orphan=1);
states view/review_states;
">
<h1 class="documentFirstHeading">Recherche de documents</h1>
@ -33,10 +34,22 @@
<div class="results-var">
<div class="results">
<table>
<thead>
<tr>
<th>Session</th>
<th>Titre</th>
<th>Catégorie</th>
<th>Auteurs / rapporteurs / orateurs</th>
<th>État</th>
</tr>
</thead>
<tal:entry tal:repeat="item batch">
<tr tal:define="oddrow repeat/item/odd;" tal:attributes="class python: oddrow and 'odd' or 'even'">
<td class="date"><span tal:condition="item/docDate" tal:replace="string: ${item/docDate/day}/${item/docDate/month}/${item/docDate/year}"></span></td>
<td class="session" tal:content="item/docSession"></td>
<td><a tal:attributes="href item/getURL" tal:content="item/Title"></a></td>
<td class="type" tal:content="item/Type"></td>
<td class="persons" tal:content="item/docPersonsStr"></td>
<td class="state" tal:content="python: states.get(item.review_state, item.review_state)"></td>
</tr>
</tal:entry>
</table>
@ -50,9 +63,8 @@
background: #eee;
}
td.date {
text-align: right;
width: 7em;
.results table tr th,
.results table tr td {
padding-right: 1em;
}
</style>

View File

@ -182,3 +182,9 @@ class SearchView(BrowserView):
elif type(d[key]) is unicode:
d[key] = d[key].encode('utf-8')
return d
def review_states(self):
d = {}
for label, id in self.context.portal_workflow.listWFStatesByTitle():
d[id] = label
return d

View File

@ -60,6 +60,19 @@ def mailCategoryTxtIndexer(obj):
grok.global_adapter(mailCategoryTxtIndexer, name="mailCategoryTxt")
@indexer(plone.dexterity.interfaces.IDexterityItem)
def docSessionIndexer(obj):
if not '(D)' in obj.Type():
return None
for attr in ('session',):
if not hasattr(obj, attr):
continue
if getattr(obj, attr):
return getattr(obj, attr)
return None
grok.global_adapter(docSessionIndexer, name='docSession')
def get_data_to_index(obj, data):
@ -228,10 +241,8 @@ def docCategoryIndexer(obj):
return category
grok.global_adapter(docCategoryIndexer, name="docCategory")
@indexer(plone.dexterity.interfaces.IDexterityItem)
def personsFuzzyIndexer(obj):
if not '(D)' in obj.Type():
return None
def get_doc_persons(obj):
persons = []
src = ContactsSource()
for attr in ('auteur', 'auteurs', 'rapporteurs', 'orateurs_seance',
@ -256,6 +267,21 @@ def personsFuzzyIndexer(obj):
persons.append(r)
else:
persons.append(item)
return ' '.join(persons)
return persons
@indexer(plone.dexterity.interfaces.IDexterityItem)
def personsFuzzyIndexer(obj):
if not '(D)' in obj.Type():
return None
return ' '.join(get_doc_persons(obj))
grok.global_adapter(personsFuzzyIndexer, name='docPersonsFuzzy')
@indexer(plone.dexterity.interfaces.IDexterityItem)
def personsStrIndexer(obj):
if not '(D)' in obj.Type():
return None
return ', '.join(get_doc_persons(obj))
grok.global_adapter(personsStrIndexer, name='docPersonsStr')

View File

@ -44,6 +44,9 @@
<index name="docNumber" meta_type="FieldIndex">
<indexed_attr value="docNumber"/>
</index>
<index name="docSession" meta_type="FieldIndex">
<indexed_attr value="docSession"/>
</index>
<index name="docCategory" meta_type="KeywordIndex">
<indexed_attr value="docCategory"/>
</index>
@ -67,4 +70,6 @@
<column value="docDate"/>
<column value="docMeetingDate"/>
<column value="docNumber"/>
<column value="docSession"/>
<column value="docPersonsStr"/>
</object>