本文整理汇总了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