当前位置: 首页>>代码示例>>Python>>正文


Python SearchController.add_new_collection方法代码示例

本文整理汇总了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")
开发者ID:Web5design,项目名称:hue,代码行数:35,代码来源:views.py

示例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")
开发者ID:branchp,项目名称:hue,代码行数:20,代码来源:views.py


注:本文中的search.search_controller.SearchController.add_new_collection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。