Merge deputies and ministries in lists (#773)
This commit is contained in:
parent
b8a023b840
commit
989dee6ad0
|
@ -38,36 +38,60 @@ class CommissionsSource(object):
|
|||
# hack to let schema editor handle the field
|
||||
yield u'DO NOT TOUCH'
|
||||
|
||||
|
||||
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())
|
||||
|
||||
def get_terms_for_persons(context, include_deputies=False, include_ministries=False):
|
||||
catalog = getToolByName(context, 'portal_catalog')
|
||||
|
||||
if include_deputies:
|
||||
results = catalog(portal_type='themis.datatypes.deputy')
|
||||
deputies = [x.getObject() for x in results]
|
||||
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)
|
||||
else:
|
||||
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))
|
||||
|
||||
return terms
|
||||
|
||||
|
||||
class DeputiesSource(object):
|
||||
implements(IContextSourceBinder)
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def get_terms(cls, context):
|
||||
catalog = getToolByName(context, 'portal_catalog')
|
||||
results = catalog(portal_type='themis.datatypes.deputy')
|
||||
deputies = [x.getObject() for x in results]
|
||||
deputies.sort(cmp_person)
|
||||
def format_deputy(x):
|
||||
if x.polgroup:
|
||||
return '%s %s (%s)' % (x.lastname, x.firstname, x.polgroup.to_object.title)
|
||||
else:
|
||||
return '%s %s (?)' % (x.lastname, x.firstname)
|
||||
deputies_terms = [SimpleVocabulary.createTerm(
|
||||
'deputy:'+x.id, 'deputy:'+x.id, format_deputy(x))
|
||||
for x in deputies]
|
||||
return deputies_terms
|
||||
|
||||
def __call__(self, context):
|
||||
return SimpleVocabulary(self.get_terms(context))
|
||||
return SimpleVocabulary(get_terms_for_persons(context, include_deputies=True))
|
||||
|
||||
def __iter__(self):
|
||||
# hack to let schema editor handle the field
|
||||
|
@ -77,26 +101,10 @@ class DeputiesSource(object):
|
|||
class MinistriesSource(object):
|
||||
implements(IContextSourceBinder)
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def get_terms(cls, context):
|
||||
catalog = getToolByName(context, 'portal_catalog')
|
||||
results = catalog(portal_type='themis.datatypes.ministry')
|
||||
ministries = [x.getObject() for x in results]
|
||||
ministries.sort(cmp_person)
|
||||
def format_ministry(x):
|
||||
return '%s %s (ministre)' % (x.lastname, x.firstname)
|
||||
ministries_terms = [SimpleVocabulary.createTerm(
|
||||
'ministry:'+x.id, 'ministry:'+x.id, format_ministry(x))
|
||||
for x in ministries]
|
||||
college_term = SimpleVocabulary.createTerm(
|
||||
'ministry:college','ministry:college', u'Collège')
|
||||
return [college_term] + ministries_terms
|
||||
|
||||
def __call__(self, context):
|
||||
return SimpleVocabulary(self.get_terms(context))
|
||||
college_term = [SimpleVocabulary.createTerm(
|
||||
'ministry:college','ministry:college', u'Collège')]
|
||||
return SimpleVocabulary(get_terms_for_persons(context, include_ministries=True) + college_term)
|
||||
|
||||
def __iter__(self):
|
||||
# hack to let schema editor handle the field
|
||||
|
@ -110,10 +118,10 @@ class DeputiesAndMinistriesSource(object):
|
|||
pass
|
||||
|
||||
def __call__(self, context):
|
||||
catalog = getToolByName(context, 'portal_catalog')
|
||||
deputies_terms = DeputiesSource.get_terms(context)
|
||||
ministries_terms = MinistriesSource.get_terms(context)
|
||||
return SimpleVocabulary(deputies_terms + ministries_terms)
|
||||
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)
|
||||
|
||||
def __iter__(self):
|
||||
# hack to let schema editor handle the field
|
||||
|
@ -161,8 +169,11 @@ class ContactsSource(object):
|
|||
|
||||
def __call__(self, context):
|
||||
catalog = getToolByName(context, 'portal_catalog')
|
||||
deputies_terms = DeputiesSource.get_terms(context)
|
||||
ministries_terms = MinistriesSource.get_terms(context)
|
||||
|
||||
depmin_terms = get_terms_for_persons(context,
|
||||
include_deputies=True, include_ministries=True)
|
||||
college_term = [SimpleVocabulary.createTerm(
|
||||
'ministry:college','ministry:college', u'Collège')]
|
||||
|
||||
results = catalog(portal_type='themis.datatypes.contact')
|
||||
contacts = [x.getObject() for x in results]
|
||||
|
@ -172,14 +183,13 @@ class ContactsSource(object):
|
|||
contact_ids = [x.id for x in contacts]
|
||||
contacts_terms = [SimpleVocabulary.createTerm(
|
||||
'contact:'+x.id, 'contact:'+x.id, x.title) for x in contacts]
|
||||
return ContactsVocabulary(context, contact_ids, deputies_terms + ministries_terms + contacts_terms)
|
||||
return ContactsVocabulary(context, contact_ids, depmin_terms + college_term + contacts_terms)
|
||||
|
||||
def __iter__(self):
|
||||
# hack to let schema editor handle the field
|
||||
yield u'DO NOT TOUCH'
|
||||
|
||||
|
||||
|
||||
class SubjectsSource(object):
|
||||
implements(IContextSourceBinder)
|
||||
|
||||
|
|
Reference in New Issue