add new method to get title out of vocab

This commit is contained in:
Frédéric Péters 2011-12-07 17:59:47 +01:00
parent 410e105e26
commit 158428aadc
1 changed files with 20 additions and 0 deletions

View File

@ -178,6 +178,26 @@ class ContactsSource(object):
def __init__(self):
pass
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)
def __call__(self, context):
catalog = getToolByName(context, 'portal_catalog')