2011-11-06 21:22:52 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2011-11-16 13:14:03 +01:00
|
|
|
import re
|
|
|
|
import time
|
2011-11-21 13:57:09 +01:00
|
|
|
import datetime
|
2011-11-16 13:14:03 +01:00
|
|
|
|
2011-10-21 19:33:36 +02:00
|
|
|
from five import grok
|
2011-11-16 13:14:03 +01:00
|
|
|
from plone.memoize import instance, ram
|
2011-11-06 21:22:52 +01:00
|
|
|
from zope import interface, schema, component
|
2011-09-08 08:56:35 +02:00
|
|
|
from z3c.form import form, field, button
|
|
|
|
from plone.z3cform.layout import wrap_form
|
2011-10-21 17:54:21 +02:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
2011-11-06 21:22:52 +01:00
|
|
|
from zope.interface import implements
|
2011-09-08 08:56:35 +02:00
|
|
|
|
|
|
|
from z3c.form.ptcompat import ViewPageTemplateFile
|
2011-11-05 12:16:21 +01:00
|
|
|
import z3c.form.interfaces
|
2011-11-06 21:22:52 +01:00
|
|
|
from z3c.form.browser import text
|
|
|
|
from z3c.form import widget
|
|
|
|
from z3c.form.interfaces import ITextWidget
|
2011-11-20 12:10:45 +01:00
|
|
|
from z3c.form.browser.checkbox import CheckBoxWidget
|
2011-11-20 15:28:21 +01:00
|
|
|
from z3c.form.browser.radio import RadioWidget
|
2011-09-08 08:56:35 +02:00
|
|
|
|
|
|
|
from z3c.relationfield.schema import RelationChoice, RelationList
|
|
|
|
from plone.formwidget.contenttree import ObjPathSourceBinder
|
2011-11-23 10:51:13 +01:00
|
|
|
import plone.directives.form
|
2011-09-08 08:56:35 +02:00
|
|
|
|
|
|
|
from tabellio.searchform.interfaces import MessageFactory as _
|
|
|
|
|
2011-11-22 12:34:50 +01:00
|
|
|
import Missing
|
|
|
|
|
2011-10-02 13:42:25 +02:00
|
|
|
from Products.Five import BrowserView
|
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
2011-10-21 19:33:36 +02:00
|
|
|
from zope.schema.interfaces import IContextSourceBinder
|
|
|
|
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
|
|
|
|
|
2011-11-06 21:22:52 +01:00
|
|
|
from plone.registry.interfaces import IRegistry
|
|
|
|
|
|
|
|
from tabellio.config.interfaces import ITabellioSettings
|
2011-11-06 16:13:56 +01:00
|
|
|
import tabellio.config.utils
|
2011-11-13 16:40:37 +01:00
|
|
|
from tabellio.documents.typenames import MAPPING
|
2011-11-06 16:13:56 +01:00
|
|
|
|
2011-10-02 13:42:25 +02:00
|
|
|
|
2011-11-06 21:22:52 +01:00
|
|
|
class ListAuthorsView(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
|
|
|
|
|
|
|
|
_deputies_folder = None
|
|
|
|
def deputies_folder(self):
|
|
|
|
if self._deputies_folder:
|
|
|
|
return self._deputies_folder
|
|
|
|
path = self.settings.deputiesPath
|
|
|
|
self._deputies_folder = self.get_folder_at_path(path)
|
|
|
|
return self._deputies_folder
|
|
|
|
deputies_folder = property(deputies_folder)
|
|
|
|
|
|
|
|
def __call__(self):
|
2011-11-23 18:37:01 +01:00
|
|
|
from plone.i18n.normalizer.fr import normalizer
|
|
|
|
|
2011-11-06 21:22:52 +01:00
|
|
|
self.portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
|
|
|
self.settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
|
|
|
self.request.response.setHeader('Content-type', 'text/plain')
|
2011-11-14 15:55:55 +01:00
|
|
|
|
|
|
|
id = self.request.form.get('id')
|
|
|
|
if id:
|
|
|
|
try:
|
|
|
|
t = getattr(self.deputies_folder, id)
|
|
|
|
except AttributeError:
|
|
|
|
return 'XXX'
|
|
|
|
return t.Title()
|
|
|
|
|
2011-11-06 21:22:52 +01:00
|
|
|
s = []
|
2011-11-23 18:37:01 +01:00
|
|
|
q = normalizer.normalize(unicode(self.request.form.get('q'), 'utf-8')).lower()
|
2011-11-06 21:22:52 +01:00
|
|
|
for object in self.deputies_folder.objectValues():
|
|
|
|
if object.portal_type != 'themis.datatypes.deputy':
|
|
|
|
continue
|
2011-11-23 18:37:01 +01:00
|
|
|
if q in normalizer.normalize(object.Title()).lower():
|
2011-11-06 21:22:52 +01:00
|
|
|
s.append(object)
|
2011-11-20 17:48:16 +01:00
|
|
|
s.sort()
|
2011-11-06 21:22:52 +01:00
|
|
|
return '\n'.join(['%s|%s' % (x.Title(), x.id) for x in s])
|
|
|
|
|
2011-11-11 14:30:06 +01:00
|
|
|
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')
|
2011-11-14 15:55:55 +01:00
|
|
|
|
|
|
|
id = self.request.form.get('id')
|
|
|
|
if id:
|
|
|
|
try:
|
|
|
|
t = getattr(self.polgroups_folder, id)
|
|
|
|
except AttributeError:
|
|
|
|
return 'XXX'
|
|
|
|
return t.Title()
|
|
|
|
|
2011-11-11 14:30:06 +01:00
|
|
|
s = []
|
2011-11-23 18:37:01 +01:00
|
|
|
q = unicode(self.request.form.get('q'), 'utf-8').lower()
|
2011-11-11 14:30:06 +01:00
|
|
|
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
|
|
|
|
topics = tabellio.config.utils.get_topics_dict()
|
|
|
|
self.request.response.setHeader('Content-type', 'text/plain')
|
2011-11-14 15:55:55 +01:00
|
|
|
|
|
|
|
id = self.request.form.get('id')
|
|
|
|
if id:
|
|
|
|
try:
|
|
|
|
return '%s' % topics.get(id, id)[0]
|
|
|
|
except KeyError:
|
|
|
|
return 'XXX'
|
|
|
|
|
2011-11-23 18:37:01 +01:00
|
|
|
query_terms = [normalizer.normalize(x).lower() for x in unicode(self.request.form.get('q'), 'utf-8').split()]
|
|
|
|
print 'query terms:', query_terms
|
|
|
|
|
|
|
|
sorted_topics = topics.items()
|
|
|
|
sorted_topics.sort(lambda x,y: cmp(x[1][1].lower(), y[1][1].lower()))
|
2011-11-14 15:55:55 +01:00
|
|
|
|
2011-11-11 14:30:06 +01:00
|
|
|
r = []
|
2011-11-23 18:37:01 +01:00
|
|
|
for key, value in sorted_topics:
|
2011-11-11 14:30:06 +01:00
|
|
|
for term in query_terms:
|
2011-11-23 18:37:01 +01:00
|
|
|
if not term in value[1].lower():
|
2011-11-11 14:30:06 +01:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
r.append('%s|%s' % (value[0], key))
|
|
|
|
if len(r) > 30:
|
|
|
|
break
|
2011-11-23 18:37:01 +01:00
|
|
|
return '\n'.join(r)
|
2011-11-11 14:30:06 +01:00
|
|
|
|
|
|
|
|
2011-11-06 21:22:52 +01:00
|
|
|
class IAuthorsWidget(ITextWidget):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class AuthorsWidget(text.TextWidget):
|
|
|
|
implements(IAuthorsWidget)
|
|
|
|
klass = u'authors'
|
|
|
|
|
|
|
|
def FieldAuthorsWidget(field, request):
|
|
|
|
return widget.FieldWidget(field, AuthorsWidget(request))
|
|
|
|
|
2011-11-11 14:30:06 +01:00
|
|
|
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))
|
2011-11-06 21:22:52 +01:00
|
|
|
|
2011-11-20 12:10:45 +01:00
|
|
|
def FieldDroppedCheckboxWidget(field, request):
|
|
|
|
return widget.FieldWidget(field, CheckBoxWidget(request))
|
|
|
|
|
2011-11-20 15:28:21 +01:00
|
|
|
def FieldRadioboxesWidget(field, request):
|
|
|
|
return widget.FieldWidget(field, RadioWidget(request))
|
|
|
|
|
2011-10-02 13:42:25 +02:00
|
|
|
class IFolderWithDocuments(interface.Interface):
|
|
|
|
pass
|
|
|
|
|
2011-10-21 17:54:21 +02:00
|
|
|
class IFolderWithPfbDocuments(interface.Interface):
|
|
|
|
pass
|
|
|
|
|
2011-11-22 12:34:50 +01:00
|
|
|
def cmp_term(x, y):
|
|
|
|
from plone.i18n.normalizer.fr import normalizer
|
|
|
|
return cmp(normalizer.normalize(x.title), normalizer.normalize(y.title))
|
|
|
|
|
2011-10-21 19:33:36 +02:00
|
|
|
@grok.provider(IContextSourceBinder)
|
|
|
|
def possible_document_types(context):
|
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
|
|
|
possible_doctypes = catalog.uniqueValuesFor('doctype')
|
|
|
|
terms = []
|
|
|
|
for doctype in possible_doctypes:
|
2011-11-05 13:37:14 +01:00
|
|
|
if not doctype:
|
|
|
|
continue
|
2011-10-21 19:33:36 +02:00
|
|
|
doctype_id = doctype.encode('ascii', 'replace')
|
2011-11-13 16:40:37 +01:00
|
|
|
doctype_str = MAPPING.get(doctype, doctype)
|
|
|
|
terms.append(SimpleVocabulary.createTerm(doctype_id, doctype_id, doctype_str))
|
2011-11-22 12:34:50 +01:00
|
|
|
terms.sort(cmp_term)
|
2011-10-21 19:33:36 +02:00
|
|
|
return SimpleVocabulary(terms)
|
|
|
|
|
2011-11-21 18:43:45 +01:00
|
|
|
def get_docdos_type_id(context, type_id):
|
|
|
|
if type_id in MAPPING.keys():
|
|
|
|
return type_id
|
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
|
|
|
possible_doctypes = catalog.uniqueValuesFor('doctype')
|
|
|
|
possible_dostypes = catalog.uniqueValuesFor('dostype')
|
|
|
|
for iter_type_id in (possible_dostypes + possible_doctypes):
|
|
|
|
if iter_type_id is None:
|
|
|
|
continue
|
|
|
|
rep_id = iter_type_id.encode('ascii', 'replace')
|
|
|
|
if type_id in (iter_type_id, rep_id):
|
|
|
|
return iter_type_id
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2011-11-05 12:16:21 +01:00
|
|
|
@grok.provider(IContextSourceBinder)
|
|
|
|
def possible_dossier_types(context):
|
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
|
|
|
possible_dostypes = catalog.uniqueValuesFor('dostype')
|
|
|
|
terms = []
|
|
|
|
for dostype in possible_dostypes:
|
2011-11-05 13:37:14 +01:00
|
|
|
if not dostype:
|
|
|
|
continue
|
2011-11-05 12:16:21 +01:00
|
|
|
dostype_id = dostype.encode('ascii', 'replace')
|
2011-11-13 16:40:37 +01:00
|
|
|
dostype_str = MAPPING.get(dostype, dostype)
|
|
|
|
terms.append(SimpleVocabulary.createTerm(dostype_id, dostype_id, dostype_str))
|
2011-11-22 12:34:50 +01:00
|
|
|
terms.sort(cmp_term)
|
2011-11-05 12:16:21 +01:00
|
|
|
return SimpleVocabulary(terms)
|
|
|
|
|
2011-11-05 18:55:40 +01:00
|
|
|
@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')
|
2011-11-13 16:40:37 +01:00
|
|
|
questype_str = MAPPING.get(questype, questype)
|
|
|
|
terms.append(SimpleVocabulary.createTerm(questype_id, questype_id, questype_str))
|
2011-11-22 12:34:50 +01:00
|
|
|
terms.sort(cmp_term)
|
2011-11-05 18:55:40 +01:00
|
|
|
return SimpleVocabulary(terms)
|
2011-11-05 12:16:21 +01:00
|
|
|
|
2011-11-06 16:13:56 +01:00
|
|
|
@grok.provider(IContextSourceBinder)
|
|
|
|
def possible_sessions(context):
|
|
|
|
terms = []
|
|
|
|
for term in tabellio.config.utils.get_legisl_and_sessions():
|
|
|
|
term_id = term.encode('ascii', 'replace')
|
|
|
|
terms.append(SimpleVocabulary.createTerm(term_id, term_id, term))
|
|
|
|
return SimpleVocabulary(terms)
|
|
|
|
|
2011-11-20 12:10:45 +01:00
|
|
|
@grok.provider(IContextSourceBinder)
|
|
|
|
def possible_polgroups(context):
|
|
|
|
terms = []
|
|
|
|
|
|
|
|
current = getToolByName(context, 'portal_url').getPortalObject()
|
|
|
|
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
|
|
|
for part in settings.polgroupsPath.split('/'):
|
|
|
|
if not part:
|
|
|
|
continue
|
|
|
|
current = getattr(current, part)
|
|
|
|
|
|
|
|
for object in current.objectValues():
|
|
|
|
if object.portal_type != 'themis.datatypes.polgroup':
|
|
|
|
continue
|
|
|
|
polgroup_id = object.id
|
|
|
|
polgroup_str = object.Title()
|
|
|
|
terms.append(SimpleVocabulary.createTerm(polgroup_id, polgroup_id, polgroup_str))
|
|
|
|
return SimpleVocabulary(terms)
|
|
|
|
|
2011-11-23 10:51:13 +01:00
|
|
|
@grok.provider(IContextSourceBinder)
|
|
|
|
def possible_active_polgroups(context):
|
|
|
|
terms = []
|
|
|
|
|
|
|
|
current = getToolByName(context, 'portal_url').getPortalObject()
|
|
|
|
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
|
|
|
for part in settings.polgroupsPath.split('/'):
|
|
|
|
if not part:
|
|
|
|
continue
|
|
|
|
current = getattr(current, part)
|
|
|
|
|
|
|
|
for object in current.objectValues():
|
|
|
|
if object.portal_type != 'themis.datatypes.polgroup':
|
|
|
|
continue
|
|
|
|
if not object.active:
|
|
|
|
continue
|
|
|
|
polgroup_id = object.id
|
|
|
|
polgroup_str = object.Title()
|
|
|
|
terms.append(SimpleVocabulary.createTerm(polgroup_id, polgroup_id, polgroup_str))
|
|
|
|
return SimpleVocabulary(terms)
|
|
|
|
|
|
|
|
|
2011-11-20 12:10:45 +01:00
|
|
|
|
|
|
|
@grok.provider(IContextSourceBinder)
|
|
|
|
def possible_topics(context):
|
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
|
|
|
topics = tabellio.config.utils.get_topics_dict()
|
|
|
|
terms = []
|
2011-11-20 21:07:28 +01:00
|
|
|
for key, value in sorted(topics.items()):
|
2011-11-20 12:10:45 +01:00
|
|
|
topic_id = key
|
|
|
|
topic_str = value[0]
|
|
|
|
terms.append(SimpleVocabulary.createTerm(topic_id, topic_id, topic_str))
|
|
|
|
return SimpleVocabulary(terms)
|
2011-11-06 16:13:56 +01:00
|
|
|
|
2011-10-03 14:21:24 +02:00
|
|
|
class IDocumentSearch(interface.Interface):
|
2011-11-05 18:55:40 +01:00
|
|
|
search_type_is_document = schema.TextLine(title=u'Search Type', default=u'1', required=False)
|
2011-09-08 08:56:35 +02:00
|
|
|
nodoc = schema.TextLine(title=_(u'Document Number'), required=False)
|
|
|
|
nosuite = schema.TextLine(title=_(u'Suite Number'), required=False)
|
2011-11-05 12:16:21 +01:00
|
|
|
doctype = schema.Choice(title=_(u'Type'), required=False,
|
|
|
|
source=possible_document_types)
|
2011-09-08 08:56:35 +02:00
|
|
|
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
|
|
|
text = schema.TextLine(title=_(u'Text'), required=False)
|
2011-11-06 21:22:52 +01:00
|
|
|
authors = schema.TextLine(title=_(u'Authors'), required=False)
|
2011-11-11 14:30:06 +01:00
|
|
|
polgroups = schema.TextLine(title=_(u'Political Groups'), required=False)
|
|
|
|
topics = schema.TextLine(title=_(u'Topics'), required=False)
|
2011-11-06 16:13:56 +01:00
|
|
|
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
|
|
|
source=possible_sessions)
|
2011-09-08 08:56:35 +02:00
|
|
|
start = schema.Date(title=_(u'Start'), required=False)
|
|
|
|
end = schema.Date(title=_(u'End'), required=False)
|
|
|
|
|
2011-11-22 12:34:50 +01:00
|
|
|
sort_on = schema.Choice(title=_(u'Sort By'), required=True,
|
|
|
|
default=_(u'Session'),
|
|
|
|
values=[_(u'Session'), _(u'Type'), _(u'Number')])
|
|
|
|
|
2011-09-08 08:56:35 +02:00
|
|
|
|
2011-10-03 14:21:24 +02:00
|
|
|
class DocumentSearchForm(form.Form):
|
2011-11-05 12:16:21 +01:00
|
|
|
method = 'get'
|
2011-11-06 21:22:52 +01:00
|
|
|
prefix = 'document'
|
2011-10-03 14:21:24 +02:00
|
|
|
fields = field.Fields(IDocumentSearch)
|
2011-11-06 21:22:52 +01:00
|
|
|
fields['authors'].widgetFactory = FieldAuthorsWidget
|
2011-11-11 14:30:06 +01:00
|
|
|
fields['polgroups'].widgetFactory = FieldPolgroupsWidget
|
|
|
|
fields['topics'].widgetFactory = FieldTopicsWidget
|
2011-09-08 08:56:35 +02:00
|
|
|
ignoreContext = True
|
2011-11-23 10:51:13 +01:00
|
|
|
template = ViewPageTemplateFile('form_templates/view_form.pt')
|
2011-09-08 08:56:35 +02:00
|
|
|
|
2011-11-05 12:16:21 +01:00
|
|
|
def updateWidgets(self):
|
|
|
|
super(DocumentSearchForm, self).updateWidgets()
|
2011-11-05 18:55:40 +01:00
|
|
|
self.widgets['search_type_is_document'].mode = z3c.form.interfaces.HIDDEN_MODE
|
2011-11-05 12:16:21 +01:00
|
|
|
|
2011-10-21 20:40:31 +02:00
|
|
|
@button.buttonAndHandler(_(u'Search'))
|
2011-09-08 08:56:35 +02:00
|
|
|
def handleApply(self, action):
|
|
|
|
data, errors = self.extractData()
|
|
|
|
if not errors and False:
|
|
|
|
plone_utils = getToolByName(self.context.context, 'plone_utils')
|
|
|
|
plone_utils.addPortalMessage(_('Your search has been completed!'))
|
|
|
|
return self.request.response.redirect('./')
|
|
|
|
return
|
|
|
|
|
2011-10-03 14:21:24 +02:00
|
|
|
|
|
|
|
class IDossierSearch(interface.Interface):
|
2011-11-05 18:55:40 +01:00
|
|
|
search_type_is_dossier = schema.TextLine(title=u'Search Type', default=u'1', required=False)
|
|
|
|
|
2011-10-03 14:21:24 +02:00
|
|
|
nodos = schema.TextLine(title=_(u'Dossier Number'), required=False)
|
2011-11-05 12:16:21 +01:00
|
|
|
dostype = schema.Choice(title=_(u'Type'), required=False,
|
|
|
|
source=possible_dossier_types)
|
2011-10-03 14:21:24 +02:00
|
|
|
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
2011-11-06 21:22:52 +01:00
|
|
|
authors = schema.TextLine(title=_(u'Authors'), required=False)
|
2011-11-11 14:30:06 +01:00
|
|
|
polgroups = schema.TextLine(title=_(u'Political Groups'), required=False)
|
2011-11-17 11:11:53 +01:00
|
|
|
participants = schema.TextLine(title=_(u'Participants'), required=False)
|
2011-11-11 14:30:06 +01:00
|
|
|
topics = schema.TextLine(title=_(u'Topics'), required=False)
|
2011-11-06 16:13:56 +01:00
|
|
|
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
|
|
|
source=possible_sessions)
|
2011-11-17 18:35:17 +01:00
|
|
|
adopted = schema.Bool(title=_(u'Limit to adopted'), required=False, default=False)
|
|
|
|
decreted = schema.Bool(title=_(u'Limit to decreted'), required=False, default=False)
|
2011-10-03 14:21:24 +02:00
|
|
|
start = schema.Date(title=_(u'Start'), required=False)
|
|
|
|
end = schema.Date(title=_(u'End'), required=False)
|
|
|
|
|
2011-11-22 12:34:50 +01:00
|
|
|
sort_on = schema.Choice(title=_(u'Sort By'), required=True,
|
|
|
|
default=_(u'Session'),
|
|
|
|
values=[_(u'Session'), _(u'Type'), _(u'Number')])
|
|
|
|
|
2011-10-03 14:21:24 +02:00
|
|
|
|
|
|
|
class DossierSearchForm(form.Form):
|
2011-11-06 21:22:52 +01:00
|
|
|
prefix = 'dossier'
|
2011-11-05 12:16:21 +01:00
|
|
|
method = 'get'
|
2011-10-03 14:21:24 +02:00
|
|
|
fields = field.Fields(IDossierSearch)
|
2011-11-06 21:22:52 +01:00
|
|
|
fields['authors'].widgetFactory = FieldAuthorsWidget
|
2011-11-17 11:11:53 +01:00
|
|
|
fields['participants'].widgetFactory = FieldAuthorsWidget
|
2011-11-11 14:30:06 +01:00
|
|
|
fields['polgroups'].widgetFactory = FieldPolgroupsWidget
|
|
|
|
fields['topics'].widgetFactory = FieldTopicsWidget
|
2011-10-03 14:21:24 +02:00
|
|
|
ignoreContext = True
|
2011-11-23 10:51:13 +01:00
|
|
|
template = ViewPageTemplateFile('form_templates/view_form.pt')
|
2011-10-03 14:21:24 +02:00
|
|
|
|
2011-11-05 18:55:40 +01:00
|
|
|
def updateWidgets(self):
|
|
|
|
super(DossierSearchForm, self).updateWidgets()
|
|
|
|
self.widgets['search_type_is_dossier'].mode = z3c.form.interfaces.HIDDEN_MODE
|
|
|
|
|
2011-10-21 20:40:31 +02:00
|
|
|
@button.buttonAndHandler(_(u'Search'))
|
2011-10-03 14:21:24 +02:00
|
|
|
def handleApply(self, action):
|
|
|
|
data, errors = self.extractData()
|
|
|
|
if not errors and False:
|
|
|
|
plone_utils = getToolByName(self.context.context, 'plone_utils')
|
|
|
|
plone_utils.addPortalMessage(_('Your search has been completed!'))
|
|
|
|
return self.request.response.redirect('./')
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
class IQuestionSearch(interface.Interface):
|
2011-11-05 18:55:40 +01:00
|
|
|
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)
|
2011-10-03 14:21:24 +02:00
|
|
|
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
2011-11-06 21:22:52 +01:00
|
|
|
authors = schema.TextLine(title=_(u'Authors'), required=False)
|
2011-11-11 14:30:06 +01:00
|
|
|
polgroups = schema.TextLine(title=_(u'Political Groups'), required=False)
|
|
|
|
topics = schema.TextLine(title=_(u'Topics'), required=False)
|
2011-11-06 16:13:56 +01:00
|
|
|
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
|
|
|
source=possible_sessions)
|
2011-10-03 14:21:24 +02:00
|
|
|
start = schema.Date(title=_(u'Start'), required=False)
|
|
|
|
end = schema.Date(title=_(u'End'), required=False)
|
|
|
|
|
2011-11-22 12:34:50 +01:00
|
|
|
sort_on = schema.Choice(title=_(u'Sort By'), required=True,
|
|
|
|
default=_(u'Session'),
|
|
|
|
values=[_(u'Session'), _(u'Type')])
|
|
|
|
|
2011-10-03 14:21:24 +02:00
|
|
|
|
|
|
|
class QuestionSearchForm(form.Form):
|
2011-11-06 21:22:52 +01:00
|
|
|
prefix = 'question'
|
2011-10-03 14:21:24 +02:00
|
|
|
fields = field.Fields(IQuestionSearch)
|
2011-11-06 21:22:52 +01:00
|
|
|
fields['authors'].widgetFactory = FieldAuthorsWidget
|
2011-11-11 14:30:06 +01:00
|
|
|
fields['polgroups'].widgetFactory = FieldPolgroupsWidget
|
|
|
|
fields['topics'].widgetFactory = FieldTopicsWidget
|
2011-10-03 14:21:24 +02:00
|
|
|
ignoreContext = True
|
2011-11-23 10:51:13 +01:00
|
|
|
template = ViewPageTemplateFile('form_templates/view_form.pt')
|
2011-10-03 14:21:24 +02:00
|
|
|
|
2011-11-05 18:55:40 +01:00
|
|
|
def updateWidgets(self):
|
|
|
|
super(QuestionSearchForm, self).updateWidgets()
|
|
|
|
self.widgets['search_type_is_question'].mode = z3c.form.interfaces.HIDDEN_MODE
|
|
|
|
|
2011-10-21 20:40:31 +02:00
|
|
|
@button.buttonAndHandler(_(u'Search'))
|
2011-10-03 14:21:24 +02:00
|
|
|
def handleApply(self, action):
|
|
|
|
data, errors = self.extractData()
|
|
|
|
if not errors and False:
|
|
|
|
plone_utils = getToolByName(self.context.context, 'plone_utils')
|
|
|
|
plone_utils.addPortalMessage(_('Your search has been completed!'))
|
|
|
|
return self.request.response.redirect('./')
|
|
|
|
return
|
|
|
|
|
2011-11-24 10:40:24 +01:00
|
|
|
class QuestionPfbSearchForm(QuestionSearchForm):
|
|
|
|
fields = field.Fields(IQuestionSearch)
|
|
|
|
fields['sort_on'].widgetFactory = FieldRadioboxesWidget
|
|
|
|
|
2011-10-02 13:42:25 +02:00
|
|
|
|
2011-10-21 17:54:21 +02:00
|
|
|
class IDocumentPfbSearch(interface.Interface):
|
2011-11-05 18:55:40 +01:00
|
|
|
search_type_is_document = schema.TextLine(title=u'Search Type', default=u'1')
|
|
|
|
|
2011-10-21 17:54:21 +02:00
|
|
|
nodoc = schema.TextLine(title=_(u'Document Number'), required=False)
|
2011-11-20 12:10:45 +01:00
|
|
|
l_doctypes = schema.List(title=_(u'Types'), required=False,
|
|
|
|
value_type=schema.Choice(title=_(u'Type'), required=False,
|
|
|
|
source=possible_document_types))
|
2011-11-25 13:50:39 +01:00
|
|
|
ttitle = schema.TextLine(title=_(u'Title'), required=False,
|
|
|
|
description=_(u'Description for the title field'))
|
2011-10-21 17:54:21 +02:00
|
|
|
text = schema.TextLine(title=_(u'Text'), required=False)
|
2011-11-06 21:22:52 +01:00
|
|
|
authors = schema.TextLine(title=_(u'Authors'), required=False)
|
2011-11-20 12:10:45 +01:00
|
|
|
l_polgroups = schema.List(title=_(u'Political Groups'), required=False,
|
|
|
|
value_type=schema.Choice(title=_(u'Political Group'),
|
|
|
|
required=False, source=possible_polgroups))
|
|
|
|
l_topics = schema.List(title=_(u'Topics'), required=False,
|
|
|
|
value_type=schema.Choice(required=False,
|
|
|
|
source=possible_topics));
|
2011-11-06 16:13:56 +01:00
|
|
|
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
|
|
|
source=possible_sessions)
|
2011-10-21 17:54:21 +02:00
|
|
|
start = schema.Date(title=_(u'Start'), required=False)
|
|
|
|
end = schema.Date(title=_(u'End'), required=False)
|
|
|
|
|
|
|
|
sort_on = schema.Choice(title=_(u'Sort By'), required=True,
|
2011-11-22 12:34:50 +01:00
|
|
|
default=_(u'Session'),
|
|
|
|
values=[_(u'Session'), _(u'Type'), _(u'Number')])
|
2011-10-21 17:54:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
class DocumentPfbSearchForm(form.Form):
|
2011-11-05 12:16:21 +01:00
|
|
|
method = 'get'
|
2011-11-11 14:30:06 +01:00
|
|
|
prefix = 'document'
|
2011-10-21 17:54:21 +02:00
|
|
|
fields = field.Fields(IDocumentPfbSearch)
|
2011-11-06 21:22:52 +01:00
|
|
|
fields['authors'].widgetFactory = FieldAuthorsWidget
|
2011-11-20 12:10:45 +01:00
|
|
|
fields['l_doctypes'].widgetFactory = FieldDroppedCheckboxWidget
|
|
|
|
fields['l_polgroups'].widgetFactory = FieldDroppedCheckboxWidget
|
|
|
|
fields['l_topics'].widgetFactory = FieldDroppedCheckboxWidget
|
2011-11-20 15:28:21 +01:00
|
|
|
fields['sort_on'].widgetFactory = FieldRadioboxesWidget
|
2011-10-21 17:54:21 +02:00
|
|
|
ignoreContext = True
|
2011-11-23 10:51:13 +01:00
|
|
|
template = ViewPageTemplateFile('form_templates/view_form.pt')
|
2011-10-21 17:54:21 +02:00
|
|
|
|
2011-11-05 18:55:40 +01:00
|
|
|
def updateWidgets(self):
|
|
|
|
super(DocumentPfbSearchForm, self).updateWidgets()
|
|
|
|
self.widgets['search_type_is_document'].mode = z3c.form.interfaces.HIDDEN_MODE
|
|
|
|
|
2011-11-20 16:09:57 +01:00
|
|
|
@button.buttonAndHandler(_(u'Submit'))
|
2011-10-21 17:54:21 +02:00
|
|
|
def handleApply(self, action):
|
|
|
|
data, errors = self.extractData()
|
|
|
|
if not errors and False:
|
|
|
|
plone_utils = getToolByName(self.context.context, 'plone_utils')
|
|
|
|
plone_utils.addPortalMessage(_('Your search has been completed!'))
|
|
|
|
return self.request.response.redirect('./')
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2011-11-23 17:27:36 +01:00
|
|
|
class IAdoptedDocumentPfbSearch(interface.Interface):
|
|
|
|
search_type_is_adopteddocument = schema.TextLine(title=u'Search Type', default=u'1')
|
|
|
|
|
|
|
|
nodoc = schema.TextLine(title=_(u'Document Number'), required=False)
|
|
|
|
l_doctypes = schema.List(title=_(u'Types'), required=False,
|
|
|
|
value_type=schema.Choice(title=_(u'Type'), required=False,
|
|
|
|
values=[_(u'Projets'), _(u'Propositions')]))
|
|
|
|
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
|
|
|
text = schema.TextLine(title=_(u'Text'), required=False)
|
|
|
|
authors = schema.TextLine(title=_(u'Authors'), required=False)
|
|
|
|
l_polgroups = schema.List(title=_(u'Political Groups'), required=False,
|
|
|
|
value_type=schema.Choice(title=_(u'Political Group'),
|
|
|
|
required=False, source=possible_polgroups))
|
|
|
|
l_topics = schema.List(title=_(u'Topics'), required=False,
|
|
|
|
value_type=schema.Choice(required=False,
|
|
|
|
source=possible_topics));
|
|
|
|
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
|
|
|
source=possible_sessions)
|
|
|
|
start = schema.Date(title=_(u'Start'), required=False)
|
|
|
|
end = schema.Date(title=_(u'End'), required=False)
|
|
|
|
adopted = schema.Bool(title=_(u'Limit to adopted'), required=False, default=True)
|
|
|
|
|
|
|
|
sort_on = schema.Choice(title=_(u'Sort By'), required=True,
|
|
|
|
default=_(u'Session'),
|
|
|
|
values=[_(u'Session'), _(u'Type'), _(u'Number')])
|
|
|
|
|
|
|
|
|
|
|
|
class AdoptedDocumentPfbSearchForm(form.Form):
|
|
|
|
prefix = 'adopteddocument'
|
|
|
|
fields = field.Fields(IAdoptedDocumentPfbSearch)
|
|
|
|
fields['authors'].widgetFactory = FieldAuthorsWidget
|
|
|
|
fields['l_doctypes'].widgetFactory = FieldDroppedCheckboxWidget
|
|
|
|
fields['l_polgroups'].widgetFactory = FieldDroppedCheckboxWidget
|
|
|
|
fields['l_topics'].widgetFactory = FieldDroppedCheckboxWidget
|
|
|
|
fields['sort_on'].widgetFactory = FieldRadioboxesWidget
|
|
|
|
ignoreContext = True
|
|
|
|
template = ViewPageTemplateFile('form_templates/view_form.pt')
|
|
|
|
|
|
|
|
def updateWidgets(self):
|
|
|
|
super(AdoptedDocumentPfbSearchForm, self).updateWidgets()
|
|
|
|
self.widgets['adopted'].mode = z3c.form.interfaces.HIDDEN_MODE
|
|
|
|
self.widgets['search_type_is_adopteddocument'].mode = z3c.form.interfaces.HIDDEN_MODE
|
|
|
|
|
|
|
|
@button.buttonAndHandler(_(u'Submit'))
|
|
|
|
def handleApply(self, action):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-20 19:26:18 +01:00
|
|
|
class IDeputySearch(interface.Interface):
|
|
|
|
search_type_is_deputy = schema.TextLine(title=u'Search Type', default=u'1', required=False)
|
|
|
|
|
|
|
|
name = schema.TextLine(title=_(u'Name'), required=False)
|
|
|
|
polgroup = schema.Choice(title=_(u'Political Group'),
|
2011-11-23 10:51:13 +01:00
|
|
|
required=False, source=possible_active_polgroups)
|
2011-11-20 19:26:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DeputySearchForm(form.Form):
|
|
|
|
prefix = 'deputy'
|
|
|
|
fields = field.Fields(IDeputySearch)
|
|
|
|
ignoreContext = True
|
2011-11-23 10:51:13 +01:00
|
|
|
template = ViewPageTemplateFile('form_templates/view_form.pt')
|
2011-11-20 19:26:18 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2011-11-20 20:18:21 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2011-11-05 12:16:21 +01:00
|
|
|
class IGlobalSearchForm(interface.Interface):
|
2011-11-05 18:55:40 +01:00
|
|
|
search_type_is_document = schema.TextLine(title=u'Search Type', required=False)
|
2011-11-23 17:27:36 +01:00
|
|
|
search_type_is_adopteddocument = schema.TextLine(title=u'Search Type', required=False)
|
2011-11-05 18:55:40 +01:00
|
|
|
search_type_is_dossier = schema.TextLine(title=u'Search Type', required=False)
|
|
|
|
search_type_is_question = schema.TextLine(title=u'Search Type', required=False)
|
2011-11-05 12:16:21 +01:00
|
|
|
|
|
|
|
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,
|
|
|
|
source=possible_document_types)
|
|
|
|
|
|
|
|
nodos = schema.TextLine(title=_(u'Dossier Number'), required=False)
|
|
|
|
dostype = schema.Choice(title=_(u'Type'), required=False,
|
|
|
|
source=possible_dossier_types)
|
|
|
|
|
2011-11-05 18:55:40 +01:00
|
|
|
questype = schema.Choice(title=_(u'Type'), required=False,
|
|
|
|
source=possible_question_types)
|
|
|
|
|
2011-11-05 12:16:21 +01:00
|
|
|
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
|
|
|
text = schema.TextLine(title=_(u'Text'), required=False)
|
2011-11-06 21:22:52 +01:00
|
|
|
authors = schema.TextLine(title=_(u'Authors'), required=False)
|
2011-11-17 11:11:53 +01:00
|
|
|
participants = schema.TextLine(title=_(u'Participants'), required=False)
|
2011-11-20 16:09:57 +01:00
|
|
|
polgroups = schema.TextLine(title=_(u'Political Groups'), required=False)
|
2011-11-11 14:30:06 +01:00
|
|
|
topics = schema.TextLine(title=_(u'Topics'), required=False)
|
2011-11-06 16:13:56 +01:00
|
|
|
session = schema.Choice(title=_(u'Legislature / Session'), required=False,
|
|
|
|
source=possible_sessions)
|
2011-11-05 12:16:21 +01:00
|
|
|
start = schema.Date(title=_(u'Start'), required=False)
|
|
|
|
end = schema.Date(title=_(u'End'), required=False)
|
2011-11-17 18:35:17 +01:00
|
|
|
adopted = schema.Bool(title=_(u'Limit to adopted'), required=False, default=False)
|
|
|
|
decreted = schema.Bool(title=_(u'Limit to decreted'), required=False, default=False)
|
2011-11-05 12:16:21 +01:00
|
|
|
|
2011-11-20 12:10:45 +01:00
|
|
|
l_doctypes = schema.List(title=_(u'Types'), required=False,
|
|
|
|
value_type=schema.Choice(title=_(u'Type'), required=False,
|
|
|
|
source=possible_document_types))
|
|
|
|
l_polgroups = schema.List(title=_(u'Political Groups'), required=False,
|
|
|
|
value_type=schema.Choice(title=_(u'Political Group'),
|
|
|
|
required=False, source=possible_polgroups))
|
|
|
|
l_topics = schema.List(title=_(u'Topics'), required=False,
|
|
|
|
value_type=schema.Choice(required=False,
|
|
|
|
source=possible_topics));
|
|
|
|
|
2011-11-21 18:28:28 +01:00
|
|
|
sort_on = schema.Choice(title=_(u'Sort By'), required=False,
|
|
|
|
default=_(u'Type'),
|
|
|
|
values=[_(u'Type'), _(u'Number'), _(u'Session')])
|
|
|
|
|
2011-11-05 12:16:21 +01:00
|
|
|
|
|
|
|
class GlobalSearchForm(form.Form):
|
|
|
|
fields = field.Fields(IGlobalSearchForm)
|
|
|
|
ignoreContext = True
|
|
|
|
|
2011-10-02 13:42:25 +02:00
|
|
|
class SearchView(BrowserView):
|
2011-11-07 10:27:51 +01:00
|
|
|
batch_macros = ViewPageTemplateFile('batch_macros.pt')
|
2011-11-23 10:51:13 +01:00
|
|
|
js_macros = ViewPageTemplateFile('js_macros.pt')
|
2011-11-07 10:27:51 +01:00
|
|
|
|
2011-11-20 18:27:40 +01:00
|
|
|
def portal_url(self):
|
|
|
|
return getToolByName(self.context, 'portal_url').getPortalPath()
|
|
|
|
|
2011-11-16 13:14:03 +01:00
|
|
|
def db_connection(self):
|
|
|
|
portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
|
|
|
return portal.db._wrapper.connection
|
|
|
|
db_connection = property(db_connection)
|
|
|
|
|
|
|
|
def _get_ids_cache_key(method, self, text):
|
|
|
|
return (text, )
|
|
|
|
|
|
|
|
@ram.cache(_get_ids_cache_key)
|
|
|
|
def get_ids_from_postgres(self, text):
|
|
|
|
try:
|
|
|
|
cursor = self.db_connection.cursor()
|
|
|
|
except AttributeError:
|
|
|
|
return []
|
|
|
|
# looks like there's no way to quote things properly for to_tsquery,
|
|
|
|
from plone.i18n.normalizer.fr import normalizer
|
|
|
|
text = re.sub(r'[^\w\s]', ' ', normalizer.normalize(text))
|
|
|
|
cursor.execute("""SELECT t_document.id
|
|
|
|
FROM t_document JOIN t_file
|
|
|
|
ON (t_document.text1id = t_file.fileid OR
|
|
|
|
t_document.textdefid = t_file.fileid)
|
|
|
|
WHERE object_fts @@ to_tsquery('default_french', '''%s''')""" % text)
|
|
|
|
ids = [x[0] for x in cursor.fetchall()]
|
|
|
|
cursor.close()
|
|
|
|
return ids
|
|
|
|
|
|
|
|
def get_batchlinkparams(self):
|
|
|
|
d = dict()
|
|
|
|
for key in self.request.form:
|
|
|
|
d[key] = self.request.form[key]
|
|
|
|
if type(d[key]) is str:
|
|
|
|
d[key] = unicode(d[key], 'utf-8').encode('utf-8')
|
|
|
|
elif type(d[key]) is unicode:
|
|
|
|
d[key] = d[key].encode('utf-8')
|
|
|
|
return d
|
|
|
|
|
2011-11-05 18:55:40 +01:00
|
|
|
def search_results(self, search_type):
|
2011-11-23 17:27:36 +01:00
|
|
|
print 'search type:', search_type
|
2011-11-16 13:14:03 +01:00
|
|
|
|
2011-11-06 21:22:52 +01:00
|
|
|
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'):
|
|
|
|
GlobalSearchForm.prefix = 'dossier'
|
|
|
|
elif self.request.form.get('question.widgets.search_type_is_question'):
|
|
|
|
GlobalSearchForm.prefix = 'question'
|
2011-11-23 17:27:36 +01:00
|
|
|
elif self.request.form.get('adopteddocument.widgets.search_type_is_adopteddocument'):
|
|
|
|
GlobalSearchForm.prefix = 'adopteddocument'
|
2011-11-06 21:22:52 +01:00
|
|
|
|
2011-11-05 12:16:21 +01:00
|
|
|
f = GlobalSearchForm(self.context, self.request)
|
2011-10-21 17:54:21 +02:00
|
|
|
f.update()
|
2011-11-06 21:22:52 +01:00
|
|
|
|
2011-10-21 17:54:21 +02:00
|
|
|
data, errors = f.extractData()
|
|
|
|
kw = {}
|
2011-10-21 19:33:36 +02:00
|
|
|
|
2011-11-05 18:55:40 +01:00
|
|
|
if not data.get('search_type_is_%s' % search_type):
|
|
|
|
return None
|
2011-11-23 17:27:36 +01:00
|
|
|
print 'data:', data
|
2011-11-05 18:55:40 +01:00
|
|
|
|
2011-10-21 17:54:21 +02:00
|
|
|
if data.get('ttitle'):
|
|
|
|
kw['Title'] = data.get('ttitle')
|
2011-10-21 19:33:36 +02:00
|
|
|
|
2011-11-05 12:16:21 +01:00
|
|
|
if data.get('nodoc'):
|
2011-11-05 14:38:13 +01:00
|
|
|
kw['no'] = data.get('nodoc')
|
|
|
|
|
|
|
|
if data.get('nosuite'):
|
|
|
|
kw['nodoc'] = data.get('nosuite')
|
2011-11-05 12:16:21 +01:00
|
|
|
|
|
|
|
if data.get('nodos'):
|
2011-11-17 18:35:39 +01:00
|
|
|
kw['no'] = data.get('nodos')
|
2011-11-05 12:16:21 +01:00
|
|
|
|
2011-10-21 19:33:36 +02:00
|
|
|
if data.get('doctype'):
|
2011-11-21 18:43:45 +01:00
|
|
|
kw['doctype'] = get_docdos_type_id(self.context, data.get('doctype'))
|
2011-11-05 12:16:21 +01:00
|
|
|
if data.get('dostype'):
|
2011-11-21 18:43:45 +01:00
|
|
|
kw['dostype'] = get_docdos_type_id(self.context, data.get('dostype'))
|
2011-11-20 12:10:45 +01:00
|
|
|
if data.get('l_doctypes'):
|
2011-11-21 18:43:45 +01:00
|
|
|
kw['doctype'] = [get_docdos_type_id(self.context, x) for x in data.get('l_doctypes')]
|
2011-11-06 15:19:39 +01:00
|
|
|
|
2011-10-21 17:54:21 +02:00
|
|
|
if data.get('start') and data.get('end'):
|
|
|
|
kw['dateDoc'] = {'query': [data.get('start'), data.get('end')], 'range': 'minmax'}
|
|
|
|
elif data.get('start'):
|
|
|
|
kw['dateDoc'] = {'query': data.get('start'), 'range': 'min'}
|
|
|
|
elif data.get('end'):
|
|
|
|
kw['dateDoc'] = {'query': data.get('end'), 'range': 'max'}
|
|
|
|
|
2011-11-06 16:13:56 +01:00
|
|
|
if data.get('session'):
|
|
|
|
kw['session'] = tabellio.config.utils.get_list_of_sessions(data.get('session'))
|
|
|
|
|
2011-11-06 21:22:52 +01:00
|
|
|
if data.get('authors'):
|
|
|
|
kw['authorsDoc'] = {'query': data.get('authors').strip().split(),
|
|
|
|
'operator': 'and'}
|
|
|
|
|
2011-11-17 11:11:53 +01:00
|
|
|
if data.get('participants'):
|
|
|
|
kw['interveningPersonsDoc'] = {
|
|
|
|
'query': data.get('participants').strip().split(),
|
|
|
|
'operator': 'and'}
|
|
|
|
|
2011-11-06 15:19:39 +01:00
|
|
|
if data.get('polgroups'):
|
2011-11-11 14:30:06 +01:00
|
|
|
kw['polgroupsDoc'] = {'query': data.get('polgroups').strip().split(),
|
|
|
|
'operator': 'and'}
|
2011-11-20 12:10:45 +01:00
|
|
|
if data.get('l_polgroups'):
|
|
|
|
kw['polgroupsDoc'] = {'query': [possible_polgroups(self.context).getTermByToken(x).title for x in data.get('l_polgroups')],
|
|
|
|
'operator': 'and'}
|
2011-11-11 14:30:06 +01:00
|
|
|
|
|
|
|
if data.get('topics'):
|
|
|
|
kw['topics'] = {'query': data.get('topics').strip().split(),
|
|
|
|
'operator': 'and'}
|
2011-11-20 12:10:45 +01:00
|
|
|
if data.get('l_topics'):
|
|
|
|
kw['topics'] = {'query': [possible_topics(self.context).getTermByToken(x).title for x in data.get('l_topics')],
|
|
|
|
'operator': 'and'}
|
2011-11-06 15:19:39 +01:00
|
|
|
|
2011-11-17 18:35:17 +01:00
|
|
|
if data.get('adopted'):
|
|
|
|
kw['adopted'] = data.get('adopted')
|
|
|
|
|
|
|
|
if data.get('decreted'):
|
|
|
|
kw['decreted'] = data.get('decreted')
|
|
|
|
|
2011-11-16 13:14:03 +01:00
|
|
|
if not kw and not data.get('text'):
|
2011-10-21 17:54:21 +02:00
|
|
|
return []
|
|
|
|
|
2011-11-16 13:14:03 +01:00
|
|
|
if data.get('text'):
|
|
|
|
# plaintext search, get document ids from postgresql
|
|
|
|
kw['id'] = self.get_ids_from_postgres(data.get('text'))
|
|
|
|
|
2011-11-06 21:22:52 +01:00
|
|
|
if data.get('search_type_is_document'):
|
|
|
|
kw['portal_type'] = 'tabellio.documents.document'
|
2011-11-23 17:27:36 +01:00
|
|
|
elif data.get('search_type_is_adopteddocument'):
|
|
|
|
kw['portal_type'] = 'tabellio.documents.document'
|
2011-11-06 21:22:52 +01:00
|
|
|
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'
|
|
|
|
|
2011-11-22 12:34:50 +01:00
|
|
|
from plone.i18n.normalizer.fr import normalizer
|
|
|
|
def cmp_doctype(x, y):
|
|
|
|
if not (x.doctype is None or y.doctype is None or
|
|
|
|
x.doctype is Missing.Value or y.doctype is Missing.Value):
|
|
|
|
type_x = normalizer.normalize(MAPPING.get(x.doctype, x.doctype))
|
|
|
|
type_y = normalizer.normalize(MAPPING.get(y.doctype, y.doctype))
|
|
|
|
t = cmp(type_x, type_y)
|
|
|
|
else:
|
|
|
|
t = -cmp(x.doctype, y.doctype)
|
|
|
|
if t == 0:
|
|
|
|
t = -cmp(x.session, y.session)
|
|
|
|
if t == 0:
|
|
|
|
t = -cmp(x.no, y.no)
|
|
|
|
if t == 0:
|
|
|
|
t = cmp(x.nodoc, y.nodoc)
|
|
|
|
return t
|
|
|
|
|
|
|
|
def get_no_as_int(i):
|
|
|
|
if i:
|
2011-11-23 13:04:30 +01:00
|
|
|
try:
|
|
|
|
return int(i.split('-')[0])
|
|
|
|
except ValueError:
|
|
|
|
return 99999
|
2011-11-22 12:34:50 +01:00
|
|
|
return 0
|
|
|
|
|
2011-11-24 10:26:53 +01:00
|
|
|
ordered_sessions = tabellio.config.utils.get_ordered_sessions()
|
|
|
|
def cmp_session_name(x, y):
|
|
|
|
if x is y or x == y:
|
|
|
|
return 0
|
|
|
|
if x not in ordered_sessions:
|
|
|
|
return -1
|
|
|
|
if y not in ordered_sessions:
|
|
|
|
return +1
|
|
|
|
return cmp(ordered_sessions.index(x), ordered_sessions.index(y))
|
|
|
|
|
2011-11-22 12:34:50 +01:00
|
|
|
def cmp_dostype(x, y):
|
|
|
|
if not (x.dostype is None or y.dostype is None or
|
|
|
|
x.dostype is Missing.Value or y.dostype is Missing.Value):
|
|
|
|
type_x = normalizer.normalize(MAPPING.get(x.dostype, x.dostype))
|
|
|
|
type_y = normalizer.normalize(MAPPING.get(y.dostype, y.dostype))
|
|
|
|
else:
|
|
|
|
t = -cmp(x.dostype, y.dostype)
|
|
|
|
t = cmp(type_x, type_y)
|
|
|
|
if t == 0:
|
2011-11-24 10:26:53 +01:00
|
|
|
t = -cmp_session_name(x.session, y.session)
|
2011-11-22 12:34:50 +01:00
|
|
|
if t == 0:
|
|
|
|
t = -cmp(x.no, y.no)
|
|
|
|
return t
|
|
|
|
|
|
|
|
def cmp_questype(x, y):
|
|
|
|
if not (x.questype is None or y.questype is None or
|
|
|
|
x.questype is Missing.Value or y.questype is Missing.Value):
|
|
|
|
type_x = normalizer.normalize(MAPPING.get(x.questype, x.questype))
|
|
|
|
type_y = normalizer.normalize(MAPPING.get(y.questype, y.questype))
|
|
|
|
else:
|
|
|
|
t = -cmp(x.questype, y.questype)
|
|
|
|
t = cmp(type_x, type_y)
|
|
|
|
if t == 0:
|
2011-11-24 10:26:53 +01:00
|
|
|
t = -cmp_session_name(x.session, y.session)
|
2011-11-22 12:34:50 +01:00
|
|
|
if t == 0:
|
|
|
|
t = -cmp(x.dateDoc, y.dateDoc)
|
|
|
|
return t
|
|
|
|
|
|
|
|
def cmp_number(x, y):
|
|
|
|
t = -cmp(get_no_as_int(x.no), get_no_as_int(y.no))
|
|
|
|
if t == 0:
|
2011-11-24 10:26:53 +01:00
|
|
|
t = -cmp_session_name(x.session, y.session)
|
2011-11-22 12:34:50 +01:00
|
|
|
if t == 0:
|
|
|
|
t = cmp(x.nodoc, y.nodoc)
|
|
|
|
return t
|
|
|
|
|
|
|
|
def cmp_session(x, y):
|
2011-11-24 10:26:53 +01:00
|
|
|
t = -cmp_session_name(x.session, y.session)
|
2011-11-22 12:34:50 +01:00
|
|
|
if t == 0:
|
|
|
|
t = -cmp(get_no_as_int(x.no), get_no_as_int(y.no))
|
2011-11-24 10:26:53 +01:00
|
|
|
if t == 0 and hasattr(x, 'nodoc'):
|
|
|
|
t = cmp(x.nodoc, y.nodoc)
|
2011-11-22 12:34:50 +01:00
|
|
|
return t
|
|
|
|
|
|
|
|
cmp_function = None
|
|
|
|
if data.get('sort_on') == 'Type':
|
|
|
|
if data.get('search_type_is_document'):
|
|
|
|
cmp_function = cmp_doctype
|
2011-11-23 17:27:36 +01:00
|
|
|
elif data.get('search_type_is_adopteddocument'):
|
|
|
|
cmp_function = cmp_doctype
|
2011-11-22 12:34:50 +01:00
|
|
|
elif data.get('search_type_is_dossier'):
|
|
|
|
cmp_function = cmp_dostype
|
|
|
|
elif data.get('search_type_is_question'):
|
|
|
|
cmp_function = cmp_questype
|
|
|
|
elif data.get('sort_on') == 'Number':
|
|
|
|
cmp_function = cmp_number
|
|
|
|
elif data.get('sort_on') == 'Session':
|
|
|
|
cmp_function = cmp_session
|
2011-11-05 18:55:40 +01:00
|
|
|
|
2011-11-05 12:16:21 +01:00
|
|
|
catalog = getToolByName(self.context, 'portal_catalog')
|
2011-11-24 10:26:53 +01:00
|
|
|
print 'kw:', kw
|
2011-11-22 12:34:50 +01:00
|
|
|
return sorted(catalog(**kw), cmp_function)
|
2011-10-21 17:54:21 +02:00
|
|
|
|
2011-11-20 19:26:18 +01:00
|
|
|
def deputy_search_form(self):
|
|
|
|
f = DeputySearchForm(self.context, self.request)
|
|
|
|
f.update()
|
|
|
|
return f.render()
|
|
|
|
|
2011-10-21 17:54:21 +02:00
|
|
|
def document_pfb_search_form(self):
|
|
|
|
f = DocumentPfbSearchForm(self.context, self.request)
|
|
|
|
f.update()
|
|
|
|
return f.render()
|
|
|
|
|
2011-11-24 10:40:24 +01:00
|
|
|
def question_pfb_search_form(self):
|
|
|
|
f = QuestionPfbSearchForm(self.context, self.request)
|
|
|
|
f.update()
|
|
|
|
return f.render()
|
|
|
|
|
2011-10-03 14:21:24 +02:00
|
|
|
def document_search_form(self):
|
|
|
|
f = DocumentSearchForm(self.context, self.request)
|
|
|
|
f.update()
|
|
|
|
return f.render()
|
|
|
|
|
2011-11-05 18:55:40 +01:00
|
|
|
def document_search_results(self):
|
|
|
|
return self.search_results(search_type='document')
|
|
|
|
|
2011-11-23 17:27:36 +01:00
|
|
|
def adopted_document_pfb_search_form(self):
|
|
|
|
f = AdoptedDocumentPfbSearchForm(self.context, self.request)
|
|
|
|
f.update()
|
|
|
|
return f.render()
|
|
|
|
|
|
|
|
def adopted_document_search_results(self):
|
|
|
|
return self.search_results(search_type='adopteddocument')
|
|
|
|
|
2011-10-03 14:21:24 +02:00
|
|
|
def dossier_search_form(self):
|
|
|
|
f = DossierSearchForm(self.context, self.request)
|
|
|
|
f.update()
|
|
|
|
return f.render()
|
|
|
|
|
2011-11-05 18:55:40 +01:00
|
|
|
def dossier_search_results(self):
|
|
|
|
return self.search_results(search_type='dossier')
|
|
|
|
|
2011-10-03 14:21:24 +02:00
|
|
|
def question_search_form(self):
|
|
|
|
f = QuestionSearchForm(self.context, self.request)
|
2011-10-02 13:42:25 +02:00
|
|
|
f.update()
|
|
|
|
return f.render()
|
2011-09-08 08:56:35 +02:00
|
|
|
|
2011-11-05 18:55:40 +01:00
|
|
|
def question_search_results(self):
|
|
|
|
return self.search_results(search_type='question')
|
|
|
|
|
2011-11-20 20:18:21 +01:00
|
|
|
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 = {}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2011-11-20 20:37:31 +01:00
|
|
|
def docform_url(self):
|
2011-11-20 18:32:00 +01:00
|
|
|
catalog = getToolByName(self.context, 'portal_catalog')
|
|
|
|
try:
|
|
|
|
return catalog(
|
|
|
|
portal_type='Folder',
|
2011-11-20 20:37:31 +01:00
|
|
|
object_provides=('tabellio.searchform.form.IFolderWithPfbDocuments',
|
|
|
|
'tabellio.searchform.form.IFolderWithDocuments'),
|
2011-11-20 18:32:00 +01:00
|
|
|
limit=1)[0].getObject().absolute_url()
|
|
|
|
except IndexError:
|
|
|
|
return '#'
|
|
|
|
|
2011-11-20 19:26:18 +01:00
|
|
|
def deputiesform_url(self):
|
|
|
|
catalog = getToolByName(self.context, 'portal_catalog')
|
|
|
|
try:
|
|
|
|
return catalog(
|
|
|
|
portal_type='Folder',
|
|
|
|
object_provides=('tabellio.webviews.deputy.IDeputiesAndOthersFolderView',
|
|
|
|
'tabellio.webviews.deputy.IPfbDeputiesFolderView',
|
|
|
|
'tabellio.webviews.deputy.IFolderView'),
|
|
|
|
limit=1)[0].getObject().absolute_url()
|
|
|
|
except IndexError:
|
|
|
|
return '#'
|
|
|
|
|
2011-11-20 20:37:31 +01:00
|
|
|
def eventform_url(self):
|
|
|
|
return self.portal_url() + '/eventsearch'
|
|
|
|
|
2011-11-21 13:57:09 +01:00
|
|
|
def decrets_years(self):
|
|
|
|
now = time.localtime()
|
|
|
|
return range(1973, now[0]+1)
|
|
|
|
|
|
|
|
def decrets_year(self):
|
|
|
|
now = time.localtime()
|
|
|
|
year = int(self.request.form.get('year') or now[0])
|
|
|
|
return year
|
|
|
|
|
|
|
|
def decrets(self):
|
|
|
|
now = time.localtime()
|
|
|
|
year = int(self.request.form.get('year') or now[0])
|
|
|
|
|
|
|
|
start = datetime.datetime(year, 1, 1)
|
|
|
|
end = datetime.datetime(year+1, 1, 1)
|
|
|
|
|
|
|
|
catalog = getToolByName(self.context, 'portal_catalog')
|
|
|
|
rs = catalog(portal_type='tabellio.documents.document',
|
|
|
|
doctype='DECCCF',
|
|
|
|
dateDoc={'query': (start, end), 'range': 'min:max'},
|
|
|
|
sort_on='dateDoc')
|
|
|
|
return rs
|
|
|
|
|
2011-11-18 11:06:01 +01:00
|
|
|
|
|
|
|
class Reflex(BrowserView):
|
|
|
|
def __call__(self):
|
|
|
|
kw = {}
|
|
|
|
if self.request.form.get('no'):
|
|
|
|
kw['no'] = self.request.form.get('no')
|
|
|
|
if self.request.form.get('sess'):
|
|
|
|
kw['session'] = self.request.form.get('sess')
|
|
|
|
if self.request.form.get('nodoc'):
|
|
|
|
kw['nodoc'] = self.request.form.get('nodoc')
|
2011-11-18 13:36:38 +01:00
|
|
|
|
|
|
|
if self.request.form.get('type') == 'document':
|
|
|
|
kw['portal_type'] = 'tabellio.documents.document'
|
|
|
|
elif self.request.form.get('type') == 'dossier':
|
|
|
|
kw['portal_type'] = 'tabellio.documents.dossier'
|
2011-11-18 11:06:01 +01:00
|
|
|
|
|
|
|
catalog = getToolByName(self.context, 'portal_catalog')
|
|
|
|
rs = catalog(**kw)
|
|
|
|
if not rs:
|
|
|
|
return self.request.response.redirect('.')
|
|
|
|
return self.request.response.redirect(rs[0].getURL())
|
2011-11-20 18:32:00 +01:00
|
|
|
|