2011-06-13 21:38:31 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2011-08-11 21:43:54 +02:00
|
|
|
from zope import component
|
2011-06-07 21:56:13 +02:00
|
|
|
from zope.browser.interfaces import ITerms
|
|
|
|
from zope.interface import implements, classProvides
|
|
|
|
from zope.schema.interfaces import ISource, IContextSourceBinder
|
|
|
|
|
|
|
|
from zope.app.form.browser.interfaces import ISourceQueryView
|
|
|
|
|
|
|
|
from zope.schema.interfaces import IVocabularyFactory
|
|
|
|
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
|
|
|
|
|
2011-06-13 22:41:04 +02:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
2011-06-07 21:56:13 +02:00
|
|
|
|
2011-08-11 21:43:54 +02:00
|
|
|
from plone.registry.interfaces import IRegistry
|
2011-10-17 16:44:13 +02:00
|
|
|
from plone.formwidget.contenttree import ObjPathSourceBinder
|
2011-08-11 21:43:54 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
from tabellio.config.interfaces import ITabellioSettings
|
|
|
|
except ImportError:
|
|
|
|
ITabellioSettings = None
|
|
|
|
|
|
|
|
|
2011-06-13 22:41:04 +02:00
|
|
|
class CommissionsSource(object):
|
|
|
|
implements(IContextSourceBinder)
|
2011-06-07 21:56:13 +02:00
|
|
|
|
2011-06-13 22:41:04 +02:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
2011-06-07 21:56:13 +02:00
|
|
|
|
2011-06-13 22:41:04 +02:00
|
|
|
def __call__(self, context):
|
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
|
|
|
results = catalog(portal_type='themis.datatypes.commission')
|
|
|
|
commissions = sorted([x.getObject().title for x in results])
|
|
|
|
terms = [SimpleVocabulary.createTerm(x, x.encode('ascii', 'replace'), x) for x in commissions]
|
|
|
|
return SimpleVocabulary(terms)
|
2011-06-07 21:56:13 +02:00
|
|
|
|
2011-06-13 22:41:04 +02:00
|
|
|
def __iter__(self):
|
|
|
|
# hack to let schema editor handle the field
|
|
|
|
yield u'DO NOT TOUCH'
|
2011-06-07 22:10:22 +02:00
|
|
|
|
2011-10-24 15:42:09 +02:00
|
|
|
|
2011-06-14 15:53:21 +02:00
|
|
|
def cmp_person(x, y):
|
|
|
|
t = cmp(x.lastname.lower(), y.lastname.lower())
|
|
|
|
if t: return t
|
|
|
|
return cmp(x.firstname.lower(), y.lastname.lower())
|
|
|
|
|
2011-10-24 21:35:19 +02:00
|
|
|
def get_terms_for_persons(context, include_deputies=False,
|
|
|
|
include_ministries=False, include_ministries_collaborators=False):
|
2011-10-24 15:42:09 +02:00
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
2011-06-07 22:10:22 +02:00
|
|
|
|
2011-10-24 15:42:09 +02:00
|
|
|
if include_deputies:
|
2011-06-14 09:08:43 +02:00
|
|
|
results = catalog(portal_type='themis.datatypes.deputy')
|
|
|
|
deputies = [x.getObject() for x in results]
|
2011-10-24 15:42:09 +02:00
|
|
|
else:
|
|
|
|
deputies = []
|
|
|
|
|
|
|
|
if include_ministries:
|
|
|
|
results = catalog(portal_type='themis.datatypes.ministry')
|
|
|
|
ministries = [x.getObject() for x in results]
|
|
|
|
else:
|
|
|
|
ministries = []
|
|
|
|
|
|
|
|
list = []
|
|
|
|
if include_deputies:
|
|
|
|
list.extend(deputies)
|
|
|
|
if include_ministries:
|
|
|
|
list.extend(ministries)
|
|
|
|
|
|
|
|
list.sort(cmp_person)
|
|
|
|
|
|
|
|
terms = []
|
|
|
|
for person in list:
|
|
|
|
if person in deputies:
|
|
|
|
prefix = 'deputy'
|
|
|
|
if person.polgroup:
|
|
|
|
label = '%s %s (%s)' % (person.lastname, person.firstname, person.polgroup.to_object.title)
|
2011-07-27 19:03:12 +02:00
|
|
|
else:
|
2011-10-24 15:42:09 +02:00
|
|
|
label ='%s %s (?)' % (person.lastname, person.firstname)
|
|
|
|
else:
|
|
|
|
prefix = 'ministry'
|
|
|
|
label = '%s %s (ministre)' % (person.lastname, person.firstname)
|
|
|
|
|
|
|
|
terms.append(SimpleVocabulary.createTerm(
|
|
|
|
'%s:%s' % (prefix, person.id),
|
|
|
|
'%s:%s' % (prefix, person.id),
|
|
|
|
label))
|
|
|
|
|
2011-10-24 21:35:19 +02:00
|
|
|
if include_ministries_collaborators:
|
|
|
|
results = catalog(portal_type='themis.datatypes.ministry')
|
|
|
|
ministries = [x.getObject() for x in results]
|
|
|
|
ministries.sort(cmp_person)
|
|
|
|
for person in ministries:
|
|
|
|
terms.append(SimpleVocabulary.createTerm(
|
|
|
|
'ministry-collab:%s' % person.id,
|
|
|
|
'ministry-collab:%s' % person.id,
|
|
|
|
'Collaborateur du Ministre %s %s' % (person.firstname, person.lastname)))
|
|
|
|
|
2011-10-24 15:42:09 +02:00
|
|
|
return terms
|
|
|
|
|
|
|
|
|
|
|
|
class DeputiesSource(object):
|
|
|
|
implements(IContextSourceBinder)
|
2011-06-14 15:53:21 +02:00
|
|
|
|
|
|
|
def __call__(self, context):
|
2011-10-24 15:42:09 +02:00
|
|
|
return SimpleVocabulary(get_terms_for_persons(context, include_deputies=True))
|
2011-06-14 09:08:43 +02:00
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
# hack to let schema editor handle the field
|
|
|
|
yield u'DO NOT TOUCH'
|
2011-06-13 21:38:31 +02:00
|
|
|
|
2011-06-14 09:08:43 +02:00
|
|
|
|
2011-06-14 15:53:21 +02:00
|
|
|
class MinistriesSource(object):
|
|
|
|
implements(IContextSourceBinder)
|
|
|
|
|
|
|
|
def __call__(self, context):
|
2011-10-24 15:42:09 +02:00
|
|
|
college_term = [SimpleVocabulary.createTerm(
|
|
|
|
'ministry:college','ministry:college', u'Collège')]
|
|
|
|
return SimpleVocabulary(get_terms_for_persons(context, include_ministries=True) + college_term)
|
2011-06-14 15:53:21 +02:00
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
# hack to let schema editor handle the field
|
|
|
|
yield u'DO NOT TOUCH'
|
|
|
|
|
|
|
|
|
|
|
|
class DeputiesAndMinistriesSource(object):
|
|
|
|
implements(IContextSourceBinder)
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __call__(self, context):
|
2011-10-24 15:42:09 +02:00
|
|
|
college_term = [SimpleVocabulary.createTerm(
|
|
|
|
'ministry:college','ministry:college', u'Collège')]
|
|
|
|
return SimpleVocabulary(get_terms_for_persons(context,
|
|
|
|
include_deputies=True, include_ministries=True) + college_term)
|
2011-06-14 15:53:21 +02:00
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
# hack to let schema editor handle the field
|
|
|
|
yield u'DO NOT TOUCH'
|
|
|
|
|
|
|
|
|
2011-06-15 21:44:40 +02:00
|
|
|
class ContactsVocabulary(SimpleVocabulary):
|
|
|
|
context = None
|
|
|
|
|
|
|
|
def __init__(self, context, contact_ids, *args, **kwargs):
|
|
|
|
self.context = context
|
|
|
|
self.contact_ids = contact_ids
|
|
|
|
super(ContactsVocabulary, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def getTermByToken(self, token):
|
|
|
|
try:
|
|
|
|
return super(ContactsVocabulary, self).getTermByToken(token)
|
|
|
|
except LookupError:
|
|
|
|
if not token:
|
|
|
|
raise
|
|
|
|
if token.startswith('contact:'):
|
|
|
|
raise
|
|
|
|
|
|
|
|
# a simple string, create a contact object to match
|
|
|
|
portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
|
|
|
plone_tool = getToolByName(self.context, 'plone_utils')
|
|
|
|
new_id = plone_tool.normalizeString(token)
|
|
|
|
if not portal.contacts.has_key(new_id):
|
|
|
|
portal.contacts.invokeFactory(
|
|
|
|
'themis.datatypes.contact', new_id, title=token)
|
|
|
|
|
2011-07-27 19:03:51 +02:00
|
|
|
return self.createTerm('contact:'+new_id, 'contact:' + new_id, token)
|
2011-06-15 21:44:40 +02:00
|
|
|
|
|
|
|
def search(self, qs):
|
|
|
|
q = qs.lower()
|
2011-07-29 21:42:38 +02:00
|
|
|
t = [self.by_value.get('contact:'+kw) for kw in self.contact_ids if q in kw.lower()]
|
2011-06-15 21:44:40 +02:00
|
|
|
return t
|
2011-06-14 15:53:21 +02:00
|
|
|
|
|
|
|
|
2011-06-14 09:08:43 +02:00
|
|
|
class ContactsSource(object):
|
|
|
|
implements(IContextSourceBinder)
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
2011-12-07 17:59:47 +01:00
|
|
|
def fastGetTitleByToken(self, context, token):
|
|
|
|
if not ':' in token:
|
|
|
|
return token
|
|
|
|
if token == 'ministry:college':
|
|
|
|
return u'Collège'
|
|
|
|
prefix, value = token.split(':')
|
|
|
|
portal = getToolByName(context, 'portal_url').getPortalObject()
|
|
|
|
if prefix == 'deputy':
|
|
|
|
url = 'deputes'
|
|
|
|
elif prefix in ('ministry', 'ministry-collab'):
|
|
|
|
url = 'ministres'
|
|
|
|
elif prefix == 'contact':
|
|
|
|
url = 'contacts'
|
|
|
|
else:
|
|
|
|
raise KeyError(token)
|
|
|
|
try:
|
|
|
|
return getattr(getattr(portal, url), value).Title()
|
|
|
|
except AttributeError:
|
|
|
|
raise KeyError(token)
|
|
|
|
|
2011-06-14 09:08:43 +02:00
|
|
|
def __call__(self, context):
|
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
2011-10-24 15:42:09 +02:00
|
|
|
|
|
|
|
depmin_terms = get_terms_for_persons(context,
|
|
|
|
include_deputies=True, include_ministries=True)
|
|
|
|
college_term = [SimpleVocabulary.createTerm(
|
|
|
|
'ministry:college','ministry:college', u'Collège')]
|
2011-06-14 15:53:21 +02:00
|
|
|
|
2011-06-14 09:08:43 +02:00
|
|
|
results = catalog(portal_type='themis.datatypes.contact')
|
|
|
|
contacts = [x.getObject() for x in results]
|
|
|
|
def cmp_contact(x, y):
|
|
|
|
return cmp(x.title, y.title)
|
|
|
|
contacts.sort(cmp_contact)
|
2011-06-15 21:44:40 +02:00
|
|
|
contact_ids = [x.id for x in contacts]
|
2011-06-14 09:08:43 +02:00
|
|
|
contacts_terms = [SimpleVocabulary.createTerm(
|
2011-07-27 16:15:12 +02:00
|
|
|
'contact:'+x.id, 'contact:'+x.id, x.title) for x in contacts]
|
2011-10-24 15:42:09 +02:00
|
|
|
return ContactsVocabulary(context, contact_ids, depmin_terms + college_term + contacts_terms)
|
2011-06-14 09:08:43 +02:00
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
# hack to let schema editor handle the field
|
|
|
|
yield u'DO NOT TOUCH'
|
2011-06-13 21:38:31 +02:00
|
|
|
|
|
|
|
|
2011-10-24 21:35:19 +02:00
|
|
|
class SpeakersSource(object):
|
|
|
|
implements(IContextSourceBinder)
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __call__(self, context):
|
|
|
|
extra_terms = [SimpleVocabulary.createTerm(
|
|
|
|
'speaker:cour-des-comptes', 'speaker:cour-des-comptes', u'Cour des comptes'),
|
|
|
|
SimpleVocabulary.createTerm(
|
|
|
|
'speaker:huis-clos', 'speaker:huis-clos', u'Orateur(s) à huis clos')]
|
|
|
|
return SimpleVocabulary(get_terms_for_persons(context,
|
|
|
|
include_deputies=True,
|
|
|
|
include_ministries=True,
|
|
|
|
include_ministries_collaborators=True) + extra_terms)
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
# hack to let schema editor handle the field
|
|
|
|
yield u'DO NOT TOUCH'
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-13 21:38:31 +02:00
|
|
|
class SubjectsSource(object):
|
|
|
|
implements(IContextSourceBinder)
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
# XXX get this list from the catalog
|
|
|
|
self.terms = [
|
2011-06-16 10:07:11 +02:00
|
|
|
u"Action sociale",
|
2011-06-13 21:38:31 +02:00
|
|
|
u"Budget",
|
2011-10-24 21:14:38 +02:00
|
|
|
u"Budget du PFB",
|
2011-06-13 21:38:31 +02:00
|
|
|
u"Cohésion sociale",
|
2011-06-16 10:07:11 +02:00
|
|
|
u"Compétences résiduaires",
|
2011-10-24 21:14:38 +02:00
|
|
|
u"Compte du PFB",
|
2011-06-16 10:07:11 +02:00
|
|
|
u"Coordination de la politique du Collège",
|
|
|
|
u"Culture",
|
|
|
|
u"Enseignement",
|
|
|
|
u"Famille",
|
2011-06-13 21:38:31 +02:00
|
|
|
u"Fonction publique / administration",
|
|
|
|
u"Formation professionnelle",
|
|
|
|
u"Politique d'aide aux personnes handicapées",
|
2011-10-24 21:14:38 +02:00
|
|
|
u"Règlement du PFB",
|
2011-06-16 10:07:11 +02:00
|
|
|
u"Relations internationales",
|
|
|
|
u"Santé",
|
2011-06-13 21:38:31 +02:00
|
|
|
u"Sport",
|
2011-06-16 10:07:11 +02:00
|
|
|
u"Tourisme",
|
|
|
|
u"Transport scolaire",
|
2011-06-13 21:38:31 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def __call__(self, context):
|
|
|
|
terms = [SimpleVocabulary.createTerm(x, x.encode('ascii', 'replace'), x) for x in self.terms]
|
|
|
|
return SimpleVocabulary(terms)
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
# hack to let schema editor handle the field
|
|
|
|
yield u'DO NOT TOUCH'
|
2011-06-14 09:37:06 +02:00
|
|
|
|
|
|
|
|
2011-06-27 08:26:25 +02:00
|
|
|
class LegislativeSessionsSource(object): # Legislative sessions
|
2011-06-14 09:37:06 +02:00
|
|
|
implements(IContextSourceBinder)
|
|
|
|
|
|
|
|
def __init__(self):
|
2011-08-11 21:43:54 +02:00
|
|
|
self.terms = None
|
|
|
|
|
|
|
|
def _setup(self):
|
|
|
|
if self.terms:
|
|
|
|
return
|
|
|
|
|
|
|
|
if ITabellioSettings:
|
|
|
|
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
|
|
|
sessions = settings.sessions
|
|
|
|
if sessions:
|
|
|
|
self.terms = [x.split(':')[1].strip() for x in sessions.splitlines() if x]
|
|
|
|
return
|
|
|
|
|
|
|
|
# fallback to an hardcoded list
|
2011-06-14 09:37:06 +02:00
|
|
|
self.terms = [
|
|
|
|
u"2010 - 2011",
|
|
|
|
u"2009 - 2010",
|
|
|
|
u"Session Ordinaire 2009",
|
|
|
|
u"2008 - 2009",
|
|
|
|
u"2007 - 2008",
|
2011-07-27 19:02:56 +02:00
|
|
|
u"2006 - 2007",
|
|
|
|
u"2005 - 2006",
|
2011-07-28 15:05:40 +02:00
|
|
|
u"2004 - 2005",
|
|
|
|
u"Session Extraordinaire 2004",
|
|
|
|
u"2003 - 2004",
|
|
|
|
u"2002 - 2003",
|
|
|
|
u"2001 - 2002",
|
|
|
|
u"2000 - 2001",
|
|
|
|
u"1999 - 2000",
|
|
|
|
u"Session Extraordinaire 1999",
|
|
|
|
u"1998 - 1999",
|
|
|
|
u"1997 - 1998",
|
|
|
|
u"1996 - 1997",
|
|
|
|
u"1995 - 1996",
|
|
|
|
u"1994 - 1995",
|
|
|
|
u"1993 - 1994",
|
|
|
|
u"1992 - 1993",
|
|
|
|
u"1991 - 1992",
|
|
|
|
u"1990 - 1991",
|
|
|
|
u"1989 - 1990",
|
2011-06-14 09:37:06 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def __call__(self, context):
|
2011-08-11 21:43:54 +02:00
|
|
|
self._setup()
|
2011-06-14 09:37:06 +02:00
|
|
|
terms = [SimpleVocabulary.createTerm(x, x.encode('ascii', 'replace'), x) for x in self.terms]
|
|
|
|
return SimpleVocabulary(terms)
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
# hack to let schema editor handle the field
|
|
|
|
yield u'DO NOT TOUCH'
|
2011-10-17 16:44:13 +02:00
|
|
|
|
|
|
|
class RelatedDocObjPathSourceBinder(ObjPathSourceBinder):
|
|
|
|
def __iter__(self):
|
|
|
|
# hack to let schema editor handle the field
|
|
|
|
yield u'DO NOT TOUCH'
|