本文整理汇总了Python中search.Search.get_by_code方法的典型用法代码示例。如果您正苦于以下问题:Python Search.get_by_code方法的具体用法?Python Search.get_by_code怎么用?Python Search.get_by_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类search.Search
的用法示例。
在下文中一共展示了Search.get_by_code方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_sobject_log
# 需要导入模块: from search import Search [as 别名]
# 或者: from search.Search import get_by_code [as 别名]
def create_sobject_log(cls, log, transaction_data=None):
if not transaction_data:
transaction_data = log.get_value("transaction")
# log a reference to each sobject affected
already_logged = {}
xml = Xml()
xml.read_string(transaction_data)
nodes = xml.get_nodes("transaction/*")
# list of sobjects not logged
not_logged = set([
'sthpw/transaction_log',
'sthpw/clipboard',
'sthpw/sobject_log',
'sthpw/file',
'sthpw/message',
'sthpw/message_log',
])
find_parent = set([
'sthpw/snapshot',
'sthpw/note',
'sthpw/task'
])
for node in nodes:
node_name = xml.get_node_name(node)
if node_name == "sobject":
search_type = Xml.get_attribute(node,"search_type")
search_type_obj = SearchType.get(search_type)
if search_type_obj.get_base_key() in not_logged:
continue
search_id = Xml.get_attribute(node,"search_id")
search_code = Xml.get_attribute(node,"search_code")
if search_code:
search_key = "%s?code=%s" % (search_type, search_code)
else:
search_key = "%s|%s" % (search_type, search_id)
if already_logged.get(search_key):
continue
already_logged[search_key] = True
# delete items are not presently logged ...
# TODO: maybe they should be
action = Xml.get_attribute(node,"action")
if action == "delete":
continue
if search_code:
sobject = Search.get_by_code(search_type, search_code)
else:
sobject = Search.get_by_id(search_type, search_id)
if sobject:
SObjectLog.create(sobject, log)
else:
# record has been deleted
if search_code:
print("Skipped SObject log creation for [%s?code=%s]" %(search_type, search_code))
else:
print("Skipped SObject log creation for [%s|%s]" %(search_type, search_id))
if search_type_obj.get_base_key() in find_parent:
try:
if sobject:
sobject = sobject.get_parent()
except (SearchException, SqlException):
# don't worry if this parent can't be found.
pass
if sobject:
SObjectLog.create(sobject, log)