Skip to content

Commit

Permalink
Trata excessão ao carregar o vocabulaio.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed Dec 27, 2017
1 parent c41be11 commit e7a060e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Alterações
2.0.3 (unreleased)
^^^^^^^^^^^^^^^^^^

- Nothing changed yet.
- Trata excessão ao carregar o vocabulaio.
[rodfersou]


2.0.2 (2017-12-22)
Expand Down
24 changes: 19 additions & 5 deletions src/brasil/gov/vcge/dx/widget.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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."""

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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

Expand Down

0 comments on commit e7a060e

Please sign in to comment.