本文整理汇总了Python中arches.app.search.search_engine_factory.SearchEngineFactory._add_prefix方法的典型用法代码示例。如果您正苦于以下问题:Python SearchEngineFactory._add_prefix方法的具体用法?Python SearchEngineFactory._add_prefix怎么用?Python SearchEngineFactory._add_prefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arches.app.search.search_engine_factory.SearchEngineFactory
的用法示例。
在下文中一共展示了SearchEngineFactory._add_prefix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import _add_prefix [as 别名]
def delete(self, request, resourceid=None):
lang = request.GET.get('lang', settings.LANGUAGE_CODE)
se = SearchEngineFactory().create()
req = dict(request.GET)
ids_to_delete = req['resourcexids[]']
root_resourceinstanceid = req['root_resourceinstanceid']
for resourcexid in ids_to_delete:
try:
ret = models.ResourceXResource.objects.get(pk=resourcexid).delete()
except:
print 'resource relation does not exist'
start = request.GET.get('start', 0)
se.es.indices.refresh(index=se._add_prefix("resource_relations"))
resource = Resource.objects.get(pk=root_resourceinstanceid[0])
page = 1 if request.GET.get('page') == '' else int(request.GET.get('page', 1))
related_resources = resource.get_related_resources(lang=lang, start=start, limit=1000, page=page)
ret = []
if related_resources is not None:
ret = self.paginate_related_resources(related_resources, page, request)
return JSONResponse(ret, indent=4)
示例2: post
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import _add_prefix [as 别名]
def post(self, request, resourceid=None):
lang = request.GET.get('lang', settings.LANGUAGE_CODE)
se = SearchEngineFactory().create()
res = dict(request.POST)
relationship_type = res['relationship_properties[relationship_type]'][0]
datefrom = res['relationship_properties[datefrom]'][0]
dateto = res['relationship_properties[dateto]'][0]
dateto = None if dateto == '' else dateto
datefrom = None if datefrom == '' else datefrom
notes = res['relationship_properties[notes]'][0]
root_resourceinstanceid = res['root_resourceinstanceid']
instances_to_relate = []
relationships_to_update = []
if 'instances_to_relate[]' in res:
instances_to_relate = res['instances_to_relate[]']
if 'relationship_ids[]' in res:
relationships_to_update = res['relationship_ids[]']
def get_relatable_resources(graphid):
"""
Takes the graphid of a resource, finds the graphs root node, and returns the relatable graphids
"""
nodes = models.Node.objects.filter(graph_id=graphid)
top_node = [node for node in nodes if node.istopnode==True][0]
relatable_resources = [str(node.graph_id) for node in top_node.get_relatable_resources()]
return relatable_resources
def confirm_relationship_permitted(to_id, from_id):
resource_instance_to = models.ResourceInstance.objects.filter(resourceinstanceid=to_id)[0]
resource_instance_from = models.ResourceInstance.objects.filter(resourceinstanceid=from_id)[0]
relatable_to = get_relatable_resources(resource_instance_to.graph_id)
relatable_from = get_relatable_resources(resource_instance_from.graph_id)
relatable_to_is_valid = str(resource_instance_to.graph_id) in relatable_from
relatable_from_is_valid = str(resource_instance_from.graph_id) in relatable_to
return (relatable_to_is_valid == True and relatable_from_is_valid == True)
for instanceid in instances_to_relate:
permitted = confirm_relationship_permitted(instanceid, root_resourceinstanceid[0])
if permitted == True:
rr = models.ResourceXResource(
resourceinstanceidfrom = Resource(root_resourceinstanceid[0]),
resourceinstanceidto = Resource(instanceid),
notes = notes,
relationshiptype = relationship_type,
datestarted = datefrom,
dateended = dateto
)
rr.save()
else:
print 'relationship not permitted'
for relationshipid in relationships_to_update:
rr = models.ResourceXResource.objects.get(pk=relationshipid)
rr.notes = notes
rr.relationshiptype = relationship_type
rr.datestarted = datefrom
rr.dateended = dateto
rr.save()
start = request.GET.get('start', 0)
se.es.indices.refresh(index=se._add_prefix("resource_relations"))
resource = Resource.objects.get(pk=root_resourceinstanceid[0])
page = 1 if request.GET.get('page') == '' else int(request.GET.get('page', 1))
related_resources = resource.get_related_resources(lang=lang, start=start, limit=1000, page=page)
ret = []
if related_resources is not None:
ret = self.paginate_related_resources(related_resources, page, request)
return JSONResponse(ret, indent=4)