From 5e67e100e7309f9e252a8556c9ea2892d1d4ba14 Mon Sep 17 00:00:00 2001 From: Rodrigo Ferreira de Souza Date: Wed, 27 Dec 2017 15:48:40 -0200 Subject: [PATCH] =?UTF-8?q?Trata=20excess=C3=A3o=20ao=20carregar=20o=20voc?= =?UTF-8?q?abulaio.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.rst | 3 ++- src/brasil/gov/vcge/dx/widget.py | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8d4fa39..4972d8b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Alterações 2.0.3 (unreleased) ^^^^^^^^^^^^^^^^^^ -- Nothing changed yet. +- Trata excessão ao carregar o vocabulario. + [rodfersou] 2.0.2 (2017-12-22) diff --git a/src/brasil/gov/vcge/dx/widget.py b/src/brasil/gov/vcge/dx/widget.py index 15b4dd9..78f53b0 100644 --- a/src/brasil/gov/vcge/dx/widget.py +++ b/src/brasil/gov/vcge/dx/widget.py @@ -1,4 +1,5 @@ # -*- coding:utf-8 -*- +from brasil.gov.vcge.config import PROJECTNAME from Products.CMFPlone.utils import base_hasattr from Products.CMFPlone.utils import safe_unicode from Products.Five.browser import BrowserView @@ -8,9 +9,13 @@ from zope.component import queryUtility from zope.schema.interfaces import IVocabularyFactory +import logging import zope.interface +logger = logging.getLogger(PROJECTNAME) + + class ISkosWidget(interfaces.ISequenceWidget): """Sequence widget.""" @@ -118,9 +123,13 @@ def existing(self): # Ignore no value entries. They are in the request only. if token == self.noValueToken: continue - term = terms.getTermByToken(token) - data.append({'value': token, - 'title': term.title}) + try: + term = terms.getTermByToken(token) + data.append({'value': token, + 'title': term.title}) + except LookupError: + logger.warning('Token "{0}" not found.'.format(token)) + continue return data @property @@ -131,8 +140,12 @@ def displayValue(self): # Ignore no value entries. They are in the request only. if token == self.noValueToken: continue - term = terms.getTermByToken(token) - value.append(term.title) + try: + term = terms.getTermByToken(token) + value.append(term.title) + except LookupError: + logger.warning('Token "{0}" not found.'.format(token)) + continue return value def extract(self, default=interfaces.NO_VALUE): @@ -151,6 +164,7 @@ def extract(self, default=interfaces.NO_VALUE): try: terms.getTermByToken(token) except LookupError: + logger.warning('Token "{0}" not found.'.format(token)) return default return value