Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trata excessão ao carregar o vocabulario. #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 vocabulario.
[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