本文整理汇总了Python中search.search_controller.SearchController.add_new_collection方法的典型用法代码示例。如果您正苦于以下问题:Python SearchController.add_new_collection方法的具体用法?Python SearchController.add_new_collection怎么用?Python SearchController.add_new_collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类search.search_controller.SearchController
的用法示例。
在下文中一共展示了SearchController.add_new_collection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: admin_collections_import
# 需要导入模块: from search.search_controller import SearchController [as 别名]
# 或者: from search.search_controller.SearchController import add_new_collection [as 别名]
def admin_collections_import(request):
if request.method == 'POST':
searcher = SearchController(request.user)
imported = []
not_imported = []
status = -1
message = ""
importables = json.loads(request.POST["selected"])
for imp in importables:
try:
searcher.add_new_collection(imp)
imported.append(imp['name'])
except Exception, e:
not_imported.append(imp['name'] + ": " + unicode(str(e), "utf8"))
if len(imported) == len(importables):
status = 0;
message = _('Collection(s) or core(s) imported successfully!')
elif len(not_imported) == len(importables):
status = 2;
message = _('There was an error importing the collection(s) or core(s)')
else:
status = 1;
message = _('Collection(s) or core(s) partially imported')
result = {
'status': status,
'message': message,
'imported': imported,
'notImported': not_imported
}
return HttpResponse(json.dumps(result), mimetype="application/json")
示例2: admin_collections_import
# 需要导入模块: from search.search_controller import SearchController [as 别名]
# 或者: from search.search_controller.SearchController import add_new_collection [as 别名]
def admin_collections_import(request):
if request.method == 'POST':
searcher = SearchController(request.user)
status = 0
err_message = _('Error')
result = {
'status': status,
'message': err_message
}
importables = json.loads(request.POST["selected"])
for imp in importables:
try:
searcher.add_new_collection(imp)
status += 1
except Exception, e:
err_message += unicode(str(e), "utf8") + "\n"
result['message'] = status == len(importables) and _('Imported successfully') or _('Imported with errors: ') + err_message
return HttpResponse(json.dumps(result), mimetype="application/json")