Commit e4a1dc91 authored by Tomáš Peterka's avatar Tomáš Peterka

[json_style] Add yet-another attribut resolution method to mode=search results

parent fa05d604
......@@ -8,6 +8,7 @@ import time
from email.Utils import formatdate
import re
from zExceptions import Unauthorized
from Products.ERP5Type.Utils import UpperCase
if REQUEST is None:
REQUEST = context.REQUEST
......@@ -1244,14 +1245,27 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
else:
contents_value = search_property_getter(search_result, select)
if contents_value is None:
accessor_name = 'get' + UpperCase(select)
# check for attribute getter in the whole chain of acquisition
# why? because it does not work otherways (it's most probably wrong)
try:
# this was copied out from ListsBoxHTMLRenderer
if hasattr(search_result, accessor_name):
contents_value = getattr(search_result, accessor_name)()
except (AttributeError, KeyError, Unauthorized):
context.log("Could not evaluate {} nor {} on {}".format(
select, accessor_name, search_result))
context.log("search_property_getter({!s}, {}) -> {!s}".format(
search_result, select, contents_value))
if contents_value is not None:
if same_type(contents_value, DateTime()):
# Serialize DateTime
contents_value = contents_value.rfc822()
elif isinstance(contents_value, datetime.date):
contents_value = formatdate(time.mktime(contents_value.timetuple()))
elif getattr(contents_value, 'translate', None) is not None:
elif hasattr(contents_value, 'translate'):
contents_value = "%s" % contents_value
contents_item[select] = contents_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