本文整理匯總了Python中catalog.Catalog.get_instances方法的典型用法代碼示例。如果您正苦於以下問題:Python Catalog.get_instances方法的具體用法?Python Catalog.get_instances怎麽用?Python Catalog.get_instances使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類catalog.Catalog
的用法示例。
在下文中一共展示了Catalog.get_instances方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: fun_get_user_book
# 需要導入模塊: from catalog import Catalog [as 別名]
# 或者: from catalog.Catalog import get_instances [as 別名]
def fun_get_user_book(user, page=1, page_cap=8):
book_dict = user.managed_catalog_lib.load_all()
# print book_dict
total_num = len(book_dict)
if total_num == 0:
return 0, list()
book_list = book_dict.keys()
book_list.sort()
book_list.reverse()
min_index, max_index = get_index_list_by_page(book_list, page=page, page_cap=page_cap)
book_instance = Catalog.get_instances("_id", book_list[min_index:max_index])
res_list = []
for item in book_instance:
if item.node_sum == 0:
complete = 0
else:
complete = str(int(100 * (float(item.complete_count) / item.node_sum)))
res_list.append(
{
"book_id": item._id,
"book_name": item.name,
"book_owner_name": user.name,
"book_owner_id": user._id,
"book_complete": complete,
"book_complete_count": item.complete_count,
"book_node_sum": item.node_sum,
}
)
# print res_list
res_list.reverse()
return total_num, res_list
示例2: fun_get_all_book
# 需要導入模塊: from catalog import Catalog [as 別名]
# 或者: from catalog.Catalog import get_instances [as 別名]
def fun_get_all_book(user, page=1, page_cap=8):
book_instance = Catalog.get_instances()
sum_count = len(book_instance)
min_index, max_index = get_index_list_by_page(book_instance, page=page, page_cap=page_cap)
res_list = []
for item in book_instance[min_index:max_index]:
tmp_owner = item.owner
if item.node_sum == 0:
complete = 0
else:
complete = str(int(100 * (float(item.complete_count) / item.node_sum)))
res_list.append(
{
"book_id": item._id,
"book_name": item.name,
"book_owner_name": tmp_owner.name,
"book_owner_id": tmp_owner._id,
"book_complete": complete,
"book_complete_count": item.complete_count,
"book_node_sum": item.node_sum,
}
)
return sum_count, res_list