本文整理汇总了Python中arches.app.search.search_engine_factory.SearchEngineFactory.delete方法的典型用法代码示例。如果您正苦于以下问题:Python SearchEngineFactory.delete方法的具体用法?Python SearchEngineFactory.delete怎么用?Python SearchEngineFactory.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arches.app.search.search_engine_factory.SearchEngineFactory
的用法示例。
在下文中一共展示了SearchEngineFactory.delete方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: related_resources
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def related_resources(request, resourceid):
## get allowed resource types based on permissions
allowedtypes = get_allowed_types(request)
is_anon = False
if request.user.username == "anonymous":
is_anon = True
if request.method == 'GET':
lang = request.GET.get('lang', settings.LANGUAGE_CODE)
start = request.GET.get('start', 0)
resources = get_related_resources(resourceid, lang, start=start, limit=15, allowedtypes=allowedtypes, is_anon=is_anon)
return JSONResponse(resources, indent=4)
if 'edit' in request.user.user_groups and request.method == 'DELETE':
se = SearchEngineFactory().create()
data = JSONDeserializer().deserialize(request.body)
entityid1 = data.get('entityid1')
entityid2 = data.get('entityid2')
resourcexid = data.get('resourcexid')
realtionshiptype = data.get('realtionshiptype')
resource = Resource(entityid1)
resource.delete_resource_relationship(entityid2, realtionshiptype)
se.delete(index='resource_relations', doc_type='all', id=resourcexid)
return JSONResponse({ 'success': True })
示例2: resource_manager
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def resource_manager(request, resourcetypeid='', form_id='default', resourceid=''):
if resourceid != '':
resource = Resource(resourceid)
elif resourcetypeid != '':
resource = Resource({'entitytypeid': resourcetypeid})
if form_id == 'default':
form_id = resource.form_groups[0]['forms'][0]['id']
form = resource.get_form(form_id)
if request.method == 'DELETE':
resource.delete_index()
se = SearchEngineFactory().create()
realtionships = resource.get_related_resources(return_entities=False)
for realtionship in realtionships:
se.delete(index='resource_relations', doc_type='all', id=realtionship.resourcexid)
realtionship.delete()
resource.delete()
return JSONResponse({ 'success': True })
if request.method == 'POST':
data = JSONDeserializer().deserialize(request.POST.get('formdata', {}))
form.update(data, request.FILES)
with transaction.atomic():
if resourceid != '':
resource.delete_index()
resource.save(user=request.user)
resource.index()
resourceid = resource.entityid
return redirect('resource_manager', resourcetypeid=resourcetypeid, form_id=form_id, resourceid=resourceid)
min_max_dates = models.Dates.objects.aggregate(Min('val'), Max('val'))
if request.method == 'GET':
if form != None:
lang = request.GET.get('lang', settings.LANGUAGE_CODE)
form.load(lang)
return render(request, 'resource-manager.htm', {
'form': form,
'formdata': JSONSerializer().serialize(form.data),
'form_template': 'views/forms/' + form_id + '.htm',
'form_id': form_id,
'resourcetypeid': resourcetypeid,
'resourceid': resourceid,
'main_script': 'resource-manager',
'active_page': 'ResourceManger',
'resource': resource,
'resource_name': resource.get_primary_name(),
'resource_type_name': resource.get_type_name(),
'form_groups': resource.form_groups,
'min_date': min_max_dates['val__min'].year if min_max_dates['val__min'] != None else 0,
'max_date': min_max_dates['val__max'].year if min_max_dates['val__min'] != None else 1,
'timefilterdata': JSONSerializer().serialize(Concept.get_time_filter_data()),
})
else:
return HttpResponseNotFound('<h1>Arches form not found.</h1>')
示例3: index_resources
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def index_resources():
"""
Deletes any existing indicies from elasticsearch related to resources
and then indexes all resources from the database
"""
result_summary = {}
se = SearchEngineFactory().create()
# clear existing indexes
for index_type in ['resource_relations', 'entity', 'resource', 'maplayers']:
se.delete_index(index=index_type)
se.delete(index='term', body='{"query":{"bool":{"must":[{"constant_score":{"filter":{"missing":{"field":"value.options.conceptid"}}}}],"must_not":[],"should":[]}}}')
Resource().prepare_term_index(create=True)
cursor = connection.cursor()
cursor.execute("""select entitytypeid from data.entity_types where isresource = TRUE""")
resource_types = cursor.fetchall()
Resource().prepare_resource_relations_index(create=True)
for resource_type in resource_types:
Resource().prepare_search_index(resource_type[0], create=True)
index_resources_by_type(resource_types, result_summary)
se.es.indices.refresh(index='entity')
for resource_type in resource_types:
result_summary[resource_type[0]]['indexed'] = se.es.count(index="entity", doc_type=resource_type[0])['count']
print '\nResource Index Results:'
for k, v in result_summary.iteritems():
status = 'Passed' if v['database'] == v['indexed'] else 'failed'
print "Status: {0}, Resource Type: {1}, In Database: {2}, Indexed: {3}".format(status, k, v['database'], v['indexed'])
示例4: related_resources
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def related_resources(request, resourceid):
if request.method == 'GET':
lang = request.GET.get('lang', settings.LANGUAGE_CODE)
start = request.GET.get('start', 0)
return JSONResponse(get_related_resources(resourceid, lang, start=start, limit=15), indent=4)
if 'edit' in request.user.user_groups and request.method == 'DELETE':
se = SearchEngineFactory().create()
data = JSONDeserializer().deserialize(request.body)
entityid1 = data.get('entityid1')
entityid2 = data.get('entityid2')
resourcexid = data.get('resourcexid')
realtionshiptype = data.get('realtionshiptype')
resource = Resource(entityid1)
resource.delete_resource_relationship(entityid2, realtionshiptype)
se.delete(index='resource_relations', doc_type='all', id=resourcexid)
return JSONResponse({ 'success': True })
示例5: index_concepts
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def index_concepts():
"""
Collects all concepts and indexes both concepts and concept_labels
"""
se = SearchEngineFactory().create()
se.delete_index(index='concept_labels')
se.delete(index='term', body='{"query":{"bool":{"must_not":[{"constant_score":{"filter":{"missing":{"field":"value.options.conceptid"}}}}],"must":[],"should":[]}}}')
Resource().prepare_term_index(create=True)
print 'indexing concepts'
start = datetime.now()
cursor = connection.cursor()
cursor.execute("""select conceptid from concepts.concepts""")
conceptids = cursor.fetchall()
for c in conceptids:
if c[0] not in CORE_CONCEPTS:
concept = Concept().get(id=c[0], include_subconcepts=True, include_parentconcepts=False, include=['label'])
concept.index()
end = datetime.now()
duration = end - start
print 'indexing concepts required', duration.seconds, 'seconds'
cursor = connection.cursor()
sql = """
select conceptid, conceptlabel from concepts.vw_concepts where conceptid not in ('%s')
""" % ("','".join(CORE_CONCEPTS))
cursor.execute(sql)
concepts = cursor.fetchall()
concept_index_results = {'count':len(concepts), 'passed':0, 'failed':0}
for conceptid, conceptvalue in concepts:
result = get_indexed_concepts(se, conceptid, conceptvalue)
if result != 'passed':
concept_index_results['failed'] += 1
else:
concept_index_results['passed'] += 1
status = 'Passed' if concept_index_results['failed'] == 0 else 'Failed'
print '\nConcept Index Results:'
print "Status: {0}, In Database: {1}, Indexed: {2}".format(status, concept_index_results['count'], concept_index_results['passed'])
示例6: delete
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def delete(self, *args, **kwargs):
se = SearchEngineFactory().create()
request = kwargs.pop('request', None)
for tiles in self.tiles.itervalues():
for tile in tiles:
tile.delete(*args, request=request, **kwargs)
query = Query(se)
bool_query = Bool()
bool_query.filter(Terms(field='tileid', terms=[self.tileid]))
query.add_query(bool_query)
results = query.search(index='strings', doc_type='term')['hits']['hits']
for result in results:
se.delete(index='strings', doc_type='term', id=result['_id'])
self.__preDelete(request)
super(Tile, self).delete(*args, **kwargs)
resource = Resource.objects.get(resourceinstanceid=self.resourceinstance.resourceinstanceid)
resource.index()
示例7: delete
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def delete(self):
"""
Deletes a single resource and any related indexed data
"""
se = SearchEngineFactory().create()
related_resources = self.get_related_resources(lang="en-US", start=0, limit=15)
for rr in related_resources['resource_relationships']:
models.ResourceXResource.objects.get(pk=rr['resourcexid']).delete()
query = Query(se)
bool_query = Bool()
bool_query.filter(Terms(field='resourceinstanceid', terms=[self.resourceinstanceid]))
query.add_query(bool_query)
results = query.search(index='strings', doc_type='term')['hits']['hits']
for result in results:
se.delete(index='strings', doc_type='term', id=result['_id'])
se.delete(index='resource', doc_type=str(self.graph_id), id=self.resourceinstanceid)
super(Resource, self).delete()
示例8: update
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def update(self, data, files):
se = SearchEngineFactory().create()
related_resources_data = data.get('related-resources', [])
original_relations = self.resource.get_related_resources()
if self.resource.entityid == '':
self.resource.save()
relationship_ids = []
for related_resource in related_resources_data:
relationship_id = related_resource['relationship']['resourcexid']
relationship_ids.append(relationship_id)
resource_id = related_resource['relatedresourceid']
relationship_type_id = related_resource['relationship']['relationshiptype']
if isinstance(relationship_type_id, dict):
relationship_type_id = relationship_type_id['value']
notes = related_resource['relationship']['notes']
date_started = related_resource['relationship']['datestarted']
date_ended = related_resource['relationship']['dateended']
if not relationship_id:
relationship = self.resource.create_resource_relationship(resource_id,
relationship_type_id=relationship_type_id,
notes=notes,
date_started=date_started,
date_ended=date_ended
)
else:
relationship = RelatedResource.objects.get(pk=relationship_id)
relationship.relationshiptype = relationship_type_id
relationship.notes = notes
relationship.datestarted = date_started
relationship.dateended = date_ended
relationship.save()
se.delete(index='resource_relations', doc_type='all', id=relationship_id)
se.index_data(index='resource_relations', doc_type='all', body=model_to_dict(relationship), idfield='resourcexid')
for relatedentity in original_relations:
if relatedentity['relationship'].resourcexid not in relationship_ids:
se.delete(index='resource_relations', doc_type='all', id=relatedentity['relationship'].resourcexid)
relatedentity['relationship'].delete()
示例9: UnloadRelations
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def UnloadRelations(source):
"""
Simple utility to unload relations
AZ 17/1/17
"""
with open(source, 'rb') as csvfile:
reader = csv.DictReader(csvfile, delimiter= ',')
se = SearchEngineFactory().create()
for row in reader:
entity = Resource()
entity.entityid = row['RESOURCEID_FROM']
related_oldindex = get_related_resources(row['RESOURCEID_FROM'])
if related_oldindex:
for releted_res in related_oldindex['resource_relationships']:
if str(releted_res['entityid2']) == str(row['RESOURCEID_TO']):
se.delete(index='resource_relations', doc_type='all', id=releted_res['resourcexid'])
try:
relationship = RelatedResource.objects.get(entityid1=entity.entityid, entityid2=row['RESOURCEID_TO'],relationshiptype=row['RELATION_TYPE'])
entity.delete_resource_relationship(row['RESOURCEID_TO'], row['RELATION_TYPE'])
except:
print "Issues deleting DB instance of relation with entity1 %s and entity2 %s . Most likely, the instance has already been deleted" % (row['RESOURCEID_FROM'], row['RESOURCEID_TO'])
pass
示例10: delete_index
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def delete_index(self):
"""
removes an entity from the search index
"""
se = SearchEngineFactory().create()
se.delete(index='entity', doc_type=self.entitytypeid, id=self.entityid)
se.delete(index='resource', doc_type=self.entitytypeid, id=self.entityid)
se.delete(index='maplayers', doc_type=self.entitytypeid, id=self.entityid)
def delete_indexes(entity):
if entity.businesstablename == 'strings' or entity.businesstablename == 'domains':
se.delete_terms(entity.entityid)
entity = Entity().get(self.entityid)
entity.traverse(delete_indexes)
示例11: delete
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def delete(self):
from arches.app.search.search_engine_factory import SearchEngineFactory
se = SearchEngineFactory().create()
se.delete(index='resource_relations', doc_type='all', id=self.resourcexid)
super(ResourceXResource, self).delete()
示例12: resource_manager
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def resource_manager(request, resourcetypeid='', form_id='default', resourceid=''):
## get and check all permissions here
permissions = request.user.get_all_permissions()
res_perms = {k:[] for k in settings.RESOURCE_TYPE_CONFIGS().keys()}
for k,v in res_perms.iteritems():
for p in permissions:
t,res = p.split(".")[:2]
if k.startswith(res):
v.append(t)
if resourceid == '' and not 'CREATE' in res_perms[resourcetypeid]:
return redirect(settings.LOGIN_URL)
if not 'EDIT' in res_perms[resourcetypeid]:
return redirect(settings.LOGIN_URL)
## finish permission testing
if resourceid != '':
resource = Resource(resourceid)
elif resourcetypeid != '':
resource = Resource({'entitytypeid': resourcetypeid})
if form_id == 'default':
form_id = resource.form_groups[0]['forms'][0]['id']
form = resource.get_form(form_id)
if request.method == 'DELETE':
resource.delete_index()
se = SearchEngineFactory().create()
relationships = resource.get_related_resources(return_entities=False)
for relationship in relationships:
se.delete(index='resource_relations', doc_type='all', id=relationship.resourcexid)
relationship.delete()
resource.delete()
return JSONResponse({ 'success': True })
if request.method == 'POST':
data = JSONDeserializer().deserialize(request.POST.get('formdata', {}))
form.update(data, request.FILES)
with transaction.atomic():
if resourceid != '':
resource.delete_index()
resource.save(user=request.user)
resource.index()
resourceid = resource.entityid
return redirect('resource_manager', resourcetypeid=resourcetypeid, form_id=form_id, resourceid=resourceid)
min_max_dates = models.Dates.objects.aggregate(Min('val'), Max('val'))
if request.method == 'GET':
if form != None:
lang = request.GET.get('lang', settings.LANGUAGE_CODE)
form.load(lang)
return render_to_response('resource-manager.htm', {
'form': form,
'formdata': JSONSerializer().serialize(form.data),
'form_template': 'views/forms/' + form_id + '.htm',
'form_id': form_id,
'resourcetypeid': resourcetypeid,
'resourceid': resourceid,
'main_script': 'resource-manager',
'active_page': 'ResourceManger',
'resource': resource,
'resource_name': resource.get_primary_name(),
'resource_type_name': resource.get_type_name(),
'form_groups': resource.form_groups,
'min_date': min_max_dates['val__min'].year if min_max_dates['val__min'] != None else 0,
'max_date': min_max_dates['val__max'].year if min_max_dates['val__min'] != None else 1,
'timefilterdata': JSONSerializer().serialize(Concept.get_time_filter_data()),
},
context_instance=RequestContext(request))
else:
return HttpResponseNotFound('<h1>Arches form not found.</h1>')
示例13: resource_manager
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def resource_manager(request, resourcetypeid='', form_id='default', resourceid=''):
if resourceid != '':
resource = Resource(resourceid)
elif resourcetypeid != '':
resource = Resource({'entitytypeid': resourcetypeid})
if form_id == 'default':
form_id = resource.form_groups[0]['forms'][0]['id']
form = resource.get_form(form_id)
# Pravice preverjamo zaenkrat le preko grup
# Uporabnik mora imeti dodeljeno grupo z nazivom tipa resourca
if (request.user.username != 'anonymous'):
user = User.objects.get(username=request.user.username)
user_groups = user.groups.values_list('name', flat=True)
else:
user_groups = []
if (not 'EDIT_' + resourcetypeid in user_groups and not 'PUBLISH_' + resourcetypeid in user_groups and not request.user.is_staff and not request.user.is_superuser):
raise UserNotAuthorized('User does have permission for this resource!')
group_ownerships = 0
group_ownership = ''
for group in user_groups:
if group.startswith('OWNERSHIP_'):
group_ownership = group[10:]
group_ownerships = group_ownerships + 1
if (group_ownerships == 0 and (resourceid == '' or (resourceid != '' and not request.user.is_staff and not request.user.is_superuser))):
raise UserNotAuthorized('User does have a ownership group! Please contact Early Watercraft administrator to resolve this issue.')
if (group_ownerships > 1 and (resourceid == '' or (resourceid != '' and not request.user.is_staff and not request.user.is_superuser))):
raise UserNotAuthorized('User have more than one ownership group! Please contact Early Watercraft administrator to resolve this issue.')
if request.method == 'DELETE':
resource.delete_index()
se = SearchEngineFactory().create()
realtionships = resource.get_related_resources(return_entities=False)
for realtionship in realtionships:
se.delete(index='resource_relations', doc_type='all', id=realtionship.resourcexid)
realtionship.delete()
resource.delete()
return JSONResponse({ 'success': True })
if request.method == 'POST':
data = JSONDeserializer().deserialize(request.POST.get('formdata', {}))
current_status = resource.get_current_status()
if (resourceid != ''):
current_group = resource.get_current_group()
else:
current_group = group_ownership
user_can_edit_document = get_user_can_edit_document(current_status, current_group, user, resourcetypeid, user_groups, group_ownership)
if (not user_can_edit_document):
return HttpResponseNotFound('<h1>User can not edit this document!</h1>')
if 'action' in request.POST:
action = request.POST.get('action')
if action == 'ready-for-approval':
current_status = 'Pending approval'
resource.set_resource_status(current_status, user)
empty_errors_cache()
errors = []
actions = get_possible_actions(current_status, False, user)
if settings.EMAIL_ENABLED:
resource_url = request.build_absolute_uri(resolve_url('resource_manager', resourcetypeid=resourcetypeid, form_id='summary', resourceid=resourceid))
# Dobimo seznam vseh publisherjev v trenutni skupini uporabnika
if group_ownership <> '':
search_group = 'OWNERSHIP_' + group_ownership
current_group = Group.objects.get(name=search_group)
current_users = current_group.user_set.all()
search_group = 'PUBLISH_' + resourcetypeid
publisher_group = Group.objects.get(name=search_group)
publisher_users = publisher_group.user_set.all()
recipients = []
for user1 in current_users:
if user1 in publisher_users:
if user1.username <> user.username:
recipients.append(user1.first_name + ' ' + user1.last_name + '<' + user1.email + '>')
# Pripravmo seznam mailov
if len(recipients)>0:
resource_type_name= settings.RESOURCE_TYPE_CONFIGS()[resourcetypeid]['name']
status = 'Pending approval'
resource_name = resource.get_primary_name()
subject = resource_name + ' (' + resource_type_name + ') - ' + status
from_email = settings.EMAIL_FROM
text_content = 'User ' + user.first_name + ' ' + user.last_name + ' (' + user.username + ') has submitted a document ' + resource_name + ' (' + resource_type_name + ') for approval.'
html_content = 'User <strong>' + user.first_name + ' ' + user.last_name + ' (' + user.username + ')</strong> has submitted a document <a href="' + resource_url + '">' + resource_name + ' (' + resource_type_name + ')</a> for approval.<br>'
#print html_content
msg = EmailMultiAlternatives(subject, text_content, from_email, recipients)
msg.attach_alternative(html_content, "text/html")
msg.content_subtype = "html" # Main content is now text/html
# Posljemo mail
connection = mail.get_connection()
# Manually open the connection
connection.open()
#.........这里部分代码省略.........
示例14: delete
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import delete [as 别名]
def delete(self):
se = SearchEngineFactory().create()
se.delete(index='resource_relations', doc_type='all', id=self.resourcexid)
super(ResourceXResource, self).delete()