178 lines
5.4 KiB
Python
178 lines
5.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
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
|
|
|
|
class CommissionsSource(object):
|
|
implements(ISource)
|
|
classProvides(IContextSourceBinder)
|
|
|
|
def __init__(self, context=None):
|
|
# XXX get this list from the catalog
|
|
self.terms = [u'Commission de Controle des communications gouvernementales',
|
|
u'Commission de Cooperation avec d\'autres parlements',
|
|
u'Commission de la Sante',
|
|
u'Commission des Affaires sociales'] #...
|
|
|
|
def __contains__(self, value):
|
|
if self.get(value) is None:
|
|
return False
|
|
return True
|
|
|
|
def search(self, query):
|
|
return [SimpleTerm(x, x, x) for x in self.terms if query.lower() in x.lower()]
|
|
|
|
def get(self, value):
|
|
if value in self.terms:
|
|
return value
|
|
return None
|
|
|
|
class CommissionsSourceQueryView(object):
|
|
implements(ITerms, ISourceQueryView)
|
|
|
|
def __init__(self, context, request):
|
|
self.context = context
|
|
self.request = request
|
|
|
|
def getTerm(self, value):
|
|
commission = self.context.get(value)
|
|
token = value
|
|
title = value
|
|
return SimpleTerm(value, token=user, title=user)
|
|
|
|
def getValue(self, token):
|
|
if token not in self.context:
|
|
raise LookupError(token)
|
|
return token
|
|
|
|
def render(self, name):
|
|
return name
|
|
|
|
def results(self, name):
|
|
# check whether the normal search button was pressed
|
|
if name+".search" in self.request.form:
|
|
query_fieldname = name+".query"
|
|
if query_fieldname in self.request.form:
|
|
query = self.request.form[query_fieldname]
|
|
if query != '':
|
|
return self.context.search(query)
|
|
|
|
|
|
|
|
#class CommissionsVocabulary(object):
|
|
# implements(IVocabularyFactory)
|
|
#
|
|
# def __call__(self, context):
|
|
# terms = [SimpleVocabulary.createTerm(x, x, x) for x in ['pomme', 'poire', 'peche', 'abricot']]
|
|
# return SimpleVocabulary(terms)
|
|
#
|
|
#CommissionsVocabularyFactory = CommissionsVocabulary()
|
|
|
|
|
|
class AuthorsSource(object):
|
|
implements(ISource)
|
|
classProvides(IContextSourceBinder)
|
|
|
|
def __init__(self, context=None):
|
|
self.terms = [u'Aziz ALBISHARI',
|
|
u'Mohamed AZZOUZI',
|
|
u'Sfia BOUARFA',
|
|
u'Dominique BRAECKMAN',
|
|
u'Jacques BROTCHI',
|
|
u'Danielle CARON',
|
|
u'Mohammadi CHAHID',
|
|
u'Philippe CLOSE',
|
|
'Michel COLSON'] #...
|
|
|
|
def __contains__(self, value):
|
|
if self.get(value) is None:
|
|
return False
|
|
return True
|
|
|
|
def search(self, query):
|
|
return [SimpleTerm(x, x, x) for x in self.terms if query.lower() in x.lower()]
|
|
|
|
def get(self, value):
|
|
if value in self.terms:
|
|
return value
|
|
return None
|
|
|
|
class AuthorsSourceQueryView(object):
|
|
implements(ITerms, ISourceQueryView)
|
|
|
|
def __init__(self, context, request):
|
|
self.context = context
|
|
self.request = request
|
|
|
|
def getTerm(self, value):
|
|
commission = self.context.get(value)
|
|
token = value
|
|
title = value
|
|
return SimpleTerm(value, token=user, title=user)
|
|
|
|
def getValue(self, token):
|
|
if token not in self.context:
|
|
raise LookupError(token)
|
|
return token
|
|
|
|
def render(self, name):
|
|
return name
|
|
|
|
def results(self, name):
|
|
# check whether the normal search button was pressed
|
|
if name+".search" in self.request.form:
|
|
query_fieldname = name+".query"
|
|
if query_fieldname in self.request.form:
|
|
query = self.request.form[query_fieldname]
|
|
if query != '':
|
|
return self.context.search(query)
|
|
|
|
|
|
class SubjectsVocabulary(object):
|
|
implements(IVocabularyFactory)
|
|
|
|
def __call__(self): #, context):
|
|
terms = [SimpleVocabulary.createTerm(x, x, x) for x in ['pomme', 'poire', 'peche', 'abricot']]
|
|
return SimpleVocabulary(terms)
|
|
|
|
SubjectsVocabularyFactory = SubjectsVocabulary()
|
|
|
|
|
|
class SubjectsSource(object):
|
|
implements(IContextSourceBinder)
|
|
|
|
def __init__(self):
|
|
# XXX get this list from the catalog
|
|
self.terms = [
|
|
u"Budget",
|
|
u"Enseignement",
|
|
u"Tourisme",
|
|
u"Relations internationales",
|
|
u"Cohésion sociale",
|
|
u"Fonction publique / administration",
|
|
u"Santé",
|
|
u"Formation professionnelle",
|
|
u"Politique d'aide aux personnes handicapées",
|
|
u"Culture",
|
|
u"Transport scolaire",
|
|
u"Action sociale",
|
|
u"Famille",
|
|
u"Sport",
|
|
u"Compétences résiduaires",
|
|
u"Coordination de la politique du Collège",
|
|
]
|
|
|
|
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'
|