From 158428aadcf24376b83381a9627426e822af2cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 7 Dec 2011 17:59:47 +0100 Subject: [PATCH] add new method to get title out of vocab --- themis/fields/vocabs.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/themis/fields/vocabs.py b/themis/fields/vocabs.py index 6c58ef1..62b42da 100644 --- a/themis/fields/vocabs.py +++ b/themis/fields/vocabs.py @@ -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')