add polgroups and topics earch
This commit is contained in:
parent
23f9f9e182
commit
f0535422bf
|
@ -26,6 +26,18 @@
|
|||
class=".form.ListAuthorsView"
|
||||
permission="zope2.View"/>
|
||||
|
||||
<browser:page
|
||||
for=".form.IFolderWithDocuments"
|
||||
name="listPolgroups"
|
||||
class=".form.ListPolgroupsView"
|
||||
permission="zope2.View"/>
|
||||
|
||||
<browser:page
|
||||
for=".form.IFolderWithDocuments"
|
||||
name="listTopics"
|
||||
class=".form.ListTopicsView"
|
||||
permission="zope2.View"/>
|
||||
|
||||
<browser:page
|
||||
for=".form.IFolderWithPfbDocuments"
|
||||
name="folder_listing"
|
||||
|
@ -59,4 +71,17 @@
|
|||
template="authors_input.pt"
|
||||
/>
|
||||
|
||||
<z3c:widgetTemplate
|
||||
mode="input"
|
||||
widget=".form.IPolgroupsWidget"
|
||||
layer="z3c.form.interfaces.IFormLayer"
|
||||
template="polgroups_input.pt"
|
||||
/>
|
||||
|
||||
<z3c:widgetTemplate
|
||||
mode="input"
|
||||
widget=".form.ITopicsWidget"
|
||||
layer="z3c.form.interfaces.IFormLayer"
|
||||
template="topics_input.pt"
|
||||
/>
|
||||
</configure>
|
||||
|
|
|
@ -126,7 +126,7 @@
|
|||
<div tal:replace="structure provider:plone.belowcontentbody" />
|
||||
|
||||
<script type="text/javascript">
|
||||
function update_authors_input(input) {
|
||||
function update_input(input) {
|
||||
var s = '';
|
||||
jq(input).nextAll('span.labelbox').each(function() {
|
||||
s = s + ' ' + jq(this).attr('class').split(' ')[1];
|
||||
|
@ -134,7 +134,7 @@ function update_authors_input(input) {
|
|||
jq(input).attr('value', s);
|
||||
}
|
||||
|
||||
function author_autocomplete_ready(event, data, formatted) {
|
||||
function autocomplete_ready(event, data, formatted) {
|
||||
(function($) {
|
||||
var input_box = $(event.target);
|
||||
// XXX: don't insert item if it's already present
|
||||
|
@ -142,9 +142,9 @@ function author_autocomplete_ready(event, data, formatted) {
|
|||
$(input_box).before(labelbox);
|
||||
$(labelbox).click(function() {
|
||||
$(this).remove();
|
||||
update_authors_input(jq(input_box).prevAll('input')[0]);
|
||||
update_input(jq(input_box).prevAll('input')[0]);
|
||||
});
|
||||
update_authors_input(jq(input_box).prevAll('input')[0]);
|
||||
update_input(jq(input_box).prevAll('input')[0]);
|
||||
$(input_box).attr('value', '');
|
||||
}(jQuery));
|
||||
}
|
||||
|
@ -152,7 +152,11 @@ function author_autocomplete_ready(event, data, formatted) {
|
|||
(function($) {
|
||||
$().ready(function() {
|
||||
$('.author-autocomplete').autocomplete('./listAuthors', {
|
||||
}).result(author_autocomplete_ready);
|
||||
}).result(autocomplete_ready);
|
||||
$('.polgroup-autocomplete').autocomplete('./listPolgroups', {
|
||||
}).result(autocomplete_ready);
|
||||
$('.topic-autocomplete').autocomplete('./listTopics', {
|
||||
}).result(autocomplete_ready);
|
||||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
|
|
|
@ -61,6 +61,57 @@ class ListAuthorsView(BrowserView):
|
|||
s.append(object)
|
||||
return '\n'.join(['%s|%s' % (x.Title(), x.id) for x in s])
|
||||
|
||||
class ListPolgroupsView(BrowserView):
|
||||
def get_folder_at_path(self, path):
|
||||
current = self.portal
|
||||
for part in path.split('/'):
|
||||
if not part:
|
||||
continue
|
||||
current = getattr(current, part)
|
||||
return current
|
||||
|
||||
_polgroups_folder = None
|
||||
def polgroups_folder(self):
|
||||
if self._polgroups_folder:
|
||||
return self._polgroups_folder
|
||||
path = self.settings.polgroupsPath
|
||||
self._polgroups_folder = self.get_folder_at_path(path)
|
||||
return self._polgroups_folder
|
||||
polgroups_folder = property(polgroups_folder)
|
||||
|
||||
def __call__(self):
|
||||
self.portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
||||
self.settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
||||
|
||||
self.request.response.setHeader('Content-type', 'text/plain')
|
||||
s = []
|
||||
q = self.request.form.get('q').lower()
|
||||
for object in self.polgroups_folder.objectValues():
|
||||
if object.portal_type != 'themis.datatypes.polgroup':
|
||||
continue
|
||||
if q in object.id or q in object.Title().lower():
|
||||
s.append(object)
|
||||
return '\n'.join(['%s|%s' % (x.Title(), x.id) for x in s])
|
||||
|
||||
|
||||
class ListTopicsView(BrowserView):
|
||||
def __call__(self):
|
||||
from plone.i18n.normalizer.fr import normalizer
|
||||
query_terms = [normalizer.normalize(x).lower() for x in self.request.form.get('q').split()]
|
||||
topics = tabellio.config.utils.get_topics_dict()
|
||||
self.request.response.setHeader('Content-type', 'text/plain')
|
||||
r = []
|
||||
for key, value in topics.items():
|
||||
for term in query_terms:
|
||||
if not term in value[1]:
|
||||
break
|
||||
else:
|
||||
r.append('%s|%s' % (value[0], key))
|
||||
if len(r) > 30:
|
||||
break
|
||||
return '\n'.join(sorted(r))
|
||||
|
||||
|
||||
class IAuthorsWidget(ITextWidget):
|
||||
pass
|
||||
|
||||
|
@ -68,10 +119,28 @@ class AuthorsWidget(text.TextWidget):
|
|||
implements(IAuthorsWidget)
|
||||
klass = u'authors'
|
||||
|
||||
|
||||
def FieldAuthorsWidget(field, request):
|
||||
return widget.FieldWidget(field, AuthorsWidget(request))
|
||||
|
||||
class IPolgroupsWidget(ITextWidget):
|
||||
pass
|
||||
|
||||
class PolgroupsWidget(text.TextWidget):
|
||||
implements(IPolgroupsWidget)
|
||||
klass = u'polgroups'
|
||||
|
||||
def FieldPolgroupsWidget(field, request):
|
||||
return widget.FieldWidget(field, PolgroupsWidget(request))
|
||||
|
||||
class ITopicsWidget(ITextWidget):
|
||||
pass
|
||||
|
||||
class TopicsWidget(text.TextWidget):
|
||||
implements(ITopicsWidget)
|
||||
klass = u'topics'
|
||||
|
||||
def FieldTopicsWidget(field, request):
|
||||
return widget.FieldWidget(field, TopicsWidget(request))
|
||||
|
||||
class IFolderWithDocuments(interface.Interface):
|
||||
pass
|
||||
|
@ -130,12 +199,11 @@ class IDocumentSearch(interface.Interface):
|
|||
nosuite = schema.TextLine(title=_(u'Suite Number'), required=False)
|
||||
doctype = schema.Choice(title=_(u'Type'), required=False,
|
||||
source=possible_document_types)
|
||||
#subjects =
|
||||
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
||||
text = schema.TextLine(title=_(u'Text'), required=False)
|
||||
authors = schema.TextLine(title=_(u'Authors'), required=False)
|
||||
|
||||
# polgroups
|
||||
polgroups = schema.TextLine(title=_(u'Political Groups'), required=False)
|
||||
topics = schema.TextLine(title=_(u'Topics'), required=False)
|
||||
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
||||
source=possible_sessions)
|
||||
start = schema.Date(title=_(u'Start'), required=False)
|
||||
|
@ -147,6 +215,8 @@ class DocumentSearchForm(form.Form):
|
|||
prefix = 'document'
|
||||
fields = field.Fields(IDocumentSearch)
|
||||
fields['authors'].widgetFactory = FieldAuthorsWidget
|
||||
fields['polgroups'].widgetFactory = FieldPolgroupsWidget
|
||||
fields['topics'].widgetFactory = FieldTopicsWidget
|
||||
ignoreContext = True
|
||||
template = ViewPageTemplateFile('form_templates/view_effectivesearch.pt')
|
||||
|
||||
|
@ -170,10 +240,10 @@ class IDossierSearch(interface.Interface):
|
|||
nodos = schema.TextLine(title=_(u'Dossier Number'), required=False)
|
||||
dostype = schema.Choice(title=_(u'Type'), required=False,
|
||||
source=possible_dossier_types)
|
||||
#subjects =
|
||||
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
||||
authors = schema.TextLine(title=_(u'Authors'), required=False)
|
||||
# polgroups
|
||||
polgroups = schema.TextLine(title=_(u'Political Groups'), required=False)
|
||||
topics = schema.TextLine(title=_(u'Topics'), required=False)
|
||||
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
||||
source=possible_sessions)
|
||||
start = schema.Date(title=_(u'Start'), required=False)
|
||||
|
@ -185,6 +255,8 @@ class DossierSearchForm(form.Form):
|
|||
method = 'get'
|
||||
fields = field.Fields(IDossierSearch)
|
||||
fields['authors'].widgetFactory = FieldAuthorsWidget
|
||||
fields['polgroups'].widgetFactory = FieldPolgroupsWidget
|
||||
fields['topics'].widgetFactory = FieldTopicsWidget
|
||||
ignoreContext = True
|
||||
template = ViewPageTemplateFile('form_templates/view_dossier_search.pt')
|
||||
|
||||
|
@ -207,10 +279,10 @@ class IQuestionSearch(interface.Interface):
|
|||
|
||||
questype = schema.Choice(title=_(u'Type'), required=False,
|
||||
source=possible_question_types)
|
||||
#subjects =
|
||||
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
||||
authors = schema.TextLine(title=_(u'Authors'), required=False)
|
||||
# polgroups
|
||||
polgroups = schema.TextLine(title=_(u'Political Groups'), required=False)
|
||||
topics = schema.TextLine(title=_(u'Topics'), required=False)
|
||||
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
||||
source=possible_sessions)
|
||||
start = schema.Date(title=_(u'Start'), required=False)
|
||||
|
@ -221,6 +293,8 @@ class QuestionSearchForm(form.Form):
|
|||
prefix = 'question'
|
||||
fields = field.Fields(IQuestionSearch)
|
||||
fields['authors'].widgetFactory = FieldAuthorsWidget
|
||||
fields['polgroups'].widgetFactory = FieldPolgroupsWidget
|
||||
fields['topics'].widgetFactory = FieldTopicsWidget
|
||||
ignoreContext = True
|
||||
template = ViewPageTemplateFile('form_templates/view_question_search.pt')
|
||||
|
||||
|
@ -244,11 +318,11 @@ class IDocumentPfbSearch(interface.Interface):
|
|||
nodoc = schema.TextLine(title=_(u'Document Number'), required=False)
|
||||
doctype = schema.Choice(title=_(u'Type'), required=False,
|
||||
source=possible_document_types)
|
||||
#subjects =
|
||||
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
||||
text = schema.TextLine(title=_(u'Text'), required=False)
|
||||
authors = schema.TextLine(title=_(u'Authors'), required=False)
|
||||
# polgroups
|
||||
polgroups = schema.TextLine(title=_(u'Political Groups'), required=False)
|
||||
topics = schema.TextLine(title=_(u'Topics'), required=False)
|
||||
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
||||
source=possible_sessions)
|
||||
start = schema.Date(title=_(u'Start'), required=False)
|
||||
|
@ -260,8 +334,11 @@ class IDocumentPfbSearch(interface.Interface):
|
|||
|
||||
class DocumentPfbSearchForm(form.Form):
|
||||
method = 'get'
|
||||
prefix = 'document'
|
||||
fields = field.Fields(IDocumentPfbSearch)
|
||||
fields['authors'].widgetFactory = FieldAuthorsWidget
|
||||
fields['polgroups'].widgetFactory = FieldPolgroupsWidget
|
||||
fields['topics'].widgetFactory = FieldTopicsWidget
|
||||
ignoreContext = True
|
||||
template = ViewPageTemplateFile('form_templates/view_pfbdocsearch.pt')
|
||||
|
||||
|
@ -296,11 +373,11 @@ class IGlobalSearchForm(interface.Interface):
|
|||
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 = schema.TextLine(title=_(u'Authors'), required=False)
|
||||
# polgroups
|
||||
polgroups = schema.TextLine(title=_(u'Poltical Groups'), required=False)
|
||||
topics = schema.TextLine(title=_(u'Topics'), required=False)
|
||||
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
||||
source=possible_sessions)
|
||||
start = schema.Date(title=_(u'Start'), required=False)
|
||||
|
@ -315,7 +392,7 @@ class SearchView(BrowserView):
|
|||
batch_macros = ViewPageTemplateFile('batch_macros.pt')
|
||||
|
||||
def search_results(self, search_type):
|
||||
|
||||
print 'search type:', search_type
|
||||
if self.request.form.get('document.widgets.search_type_is_document'):
|
||||
GlobalSearchForm.prefix = 'document'
|
||||
elif self.request.form.get('dossier.widgets.search_type_is_dossier'):
|
||||
|
@ -327,12 +404,14 @@ class SearchView(BrowserView):
|
|||
f.update()
|
||||
|
||||
data, errors = f.extractData()
|
||||
print 'got data:', data
|
||||
|
||||
kw = {}
|
||||
|
||||
print 'data:', data
|
||||
|
||||
if not data.get('search_type_is_%s' % search_type):
|
||||
print ' stopping here'
|
||||
return None
|
||||
|
||||
if data.get('ttitle'):
|
||||
|
@ -367,7 +446,12 @@ class SearchView(BrowserView):
|
|||
'operator': 'and'}
|
||||
|
||||
if data.get('polgroups'):
|
||||
pass # XXX : kw['polgroupsDoc'] = {'query': ['ps', 'ecolo'], 'operator': 'and'}
|
||||
kw['polgroupsDoc'] = {'query': data.get('polgroups').strip().split(),
|
||||
'operator': 'and'}
|
||||
|
||||
if data.get('topics'):
|
||||
kw['topics'] = {'query': data.get('topics').strip().split(),
|
||||
'operator': 'and'}
|
||||
|
||||
if data.get('sort_on') == 'Type':
|
||||
kw['sort_on'] = 'doctype'
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
tal:omit-tag="">
|
||||
<input type="hidden" tal:attributes="id view/id; name view/name;"/>
|
||||
<input class="polgroup-autocomplete" type="text" tal:attributes="name string:${view/name}-query"/>
|
||||
</html>
|
|
@ -0,0 +1,6 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
tal:omit-tag="">
|
||||
<input type="hidden" tal:attributes="id view/id; name view/name;"/>
|
||||
<input class="topic-autocomplete" type="text" tal:attributes="name string:${view/name}-query"/>
|
||||
</html>
|
Reference in New Issue