Commit 5803f7b6 authored by Julien Muchembled's avatar Julien Muchembled

ListBox: simplify code

parent 9053cc93
...@@ -31,7 +31,7 @@ from six.moves import xrange ...@@ -31,7 +31,7 @@ from six.moves import xrange
from six import string_types as basestring from six import string_types as basestring
import sys import sys
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
from AccessControl import ClassSecurityInfo, Unauthorized from AccessControl import ClassSecurityInfo
from Products.Formulator.DummyField import fields from Products.Formulator.DummyField import fields
from Products.Formulator import Widget, Validator from Products.Formulator import Widget, Validator
from Products.Formulator.Field import ZMIField from Products.Formulator.Field import ZMIField
...@@ -2338,27 +2338,22 @@ class ListBoxRendererLine: ...@@ -2338,27 +2338,22 @@ class ListBoxRendererLine:
if not tales: if not tales:
if getattr(aq_self(brain), alias, None) is not None: if getattr(aq_self(brain), alias, None) is not None:
original_value = getattr(brain, alias) original_value = getattr(brain, alias)
processed_value = original_value
else: else:
# Get the trailing part.
try: try:
# Get the trailing part. property_id = sql[sql.rindex('.') + 1:]
try: except ValueError:
property_id = sql[sql.rindex('.') + 1:] property_id = sql
except ValueError: accessor_name = 'get' + UpperCase(property_id)
property_id = sql try:
# Make sure the object have the attribute, and this is not
try: # acquired, but still get the attribute on the acquisition wrapper
accessor_name = 'get%s' % UpperCase(property_id) getattr(aq_base(obj), accessor_name)
# Make sure the object have the attribute, and this is not except AttributeError:
# acquired, but still get the attribute on the acquisition wrapper original_value = getattr(obj, property_id, None)
getattr(aq_base(obj), accessor_name) else:
processed_value = original_value = getattr(obj, accessor_name) original_value = getattr(obj, accessor_name)
except AttributeError: processed_value = original_value
original_value = getattr(obj, property_id, None)
processed_value = original_value
except (AttributeError, KeyError, Unauthorized):
original_value = None
processed_value = 'Could not evaluate %s' % property_id
# If the value is callable, evaluate it. # If the value is callable, evaluate it.
if callable(original_value): if callable(original_value):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment