22
22
)
23
23
from zope .component import adapter
24
24
from zope .component import getMultiAdapter
25
- from zope .component import getUtility
25
+ from zope .component import queryUtility
26
26
from zope .component import queryMultiAdapter
27
27
from zope .globalrequest import getRequest
28
28
from zope .i18n import translate
29
29
from zope .interface import implementer
30
30
from zope .interface import Interface
31
- from zope .interface .interfaces import ComponentLookupError
32
31
from zope .schema import getFieldsInOrder
33
32
34
33
import logging
@@ -49,16 +48,16 @@ def get_taxonomy_information(field_name, context, res):
49
48
50
49
request = getRequest ()
51
50
52
- try :
53
- taxonomy = getUtility (ITaxonomy , name = f"collective.taxonomy.{ field_name } " )
54
- taxonomy_voc = taxonomy .makeVocabulary (request .get ("LANGUAGE" ))
55
- except ComponentLookupError :
51
+ taxonomy = queryUtility (ITaxonomy , name = f"collective.taxonomy.{ field_name } " )
52
+ if not taxonomy :
56
53
# utility not found, return default
57
54
if isinstance (value , list ):
58
55
res [field_name ] = [{"token" : token , "title" : token } for token in value ]
59
56
else :
60
57
res [field_name ] = {"token" : value , "title" : value }
61
58
return res
59
+
60
+ taxonomy_voc = taxonomy .makeVocabulary (request .get ("LANGUAGE" ))
62
61
# il summary di un fullobject torna un value
63
62
# il summary di un brain torna una lista (collective.taxonomy ha motivi per
64
63
# fare così).
@@ -254,11 +253,10 @@ def get_design_meta_type(self):
254
253
if self .context .portal_type == "News Item" :
255
254
tipologia_notizia = getattr (self .context , "tipologia_notizia" , "" )
256
255
if tipologia_notizia :
257
- try :
258
- taxonomy = getUtility (
259
- ITaxonomy , name = "collective.taxonomy.tipologia_notizia"
260
- )
261
- except ComponentLookupError :
256
+ taxonomy = queryUtility (
257
+ ITaxonomy , name = "collective.taxonomy.tipologia_notizia"
258
+ )
259
+ if not taxonomy :
262
260
# utility not found, return default
263
261
return tipologia_notizia
264
262
taxonomy_voc = taxonomy .makeVocabulary (self .request .get ("LANGUAGE" ))
0 commit comments