Commit ae0e6b8a authored by delanoe's avatar delanoe

[FEAT] Documents are deleted with REST API

       USAGE: methode DELETE : /api/nodes?ids=1,2,3

[FIX] Clean code after exploration.
parent c55cad0c
......@@ -40,6 +40,7 @@ urlpatterns = [
# Module "Graph Explorer"
url(r'^projects/(\d+)/corpora/(\d+)/explorer$', explorer),
url(r'^projects/(\d+)/corpora/(\d+)/graph$', Graph.as_view()),
# to be removed:
url(r'^projects/(\d+)/corpora/(\d+)/node_link.json$', Graph.as_view())
#url(r'^projects/(\d+)/corpora/(\d+)/explorer$', include(graphExplorer.urls))
#url(r'^projects/(\d+)/corpora/(\d+)/explorer$', include(graphExplorer_urls))
......
......@@ -4,6 +4,7 @@ from gargantext.util.db_cache import *
from gargantext.models import *
from gargantext.constants import *
from sqlalchemy import delete
from gargantext.util.validation import validate
from collections import defaultdict
......@@ -71,22 +72,21 @@ class NodeListResource(APIView):
]
})
def post(self, request):
"""Create a new node.
NOT IMPLEMENTED
"""
def delete(self, request):
"""Removes the list of nodes corresponding to the query.
WARNING! THIS IS TOTALLY UNTESTED!!!!!
TODO : Should be a delete method!
"""
parameters, query, count = _query_nodes(request)
query.delete()
parameters = get_parameters(request)
parameters = validate(parameters, {'ids': list} )
node_ids = [int(n) for n in parameters['ids'].split(',')]
result = session.execute(
delete(Node).where(Node.id.in_(node_ids))
)
session.commit()
return JsonHttpResponse({
'parameters': parameters,
'count': count,
}, 200)
return JsonHttpResponse({'deleted': result.rowcount})
class NodeResource(APIView):
......@@ -104,7 +104,6 @@ class NodeResource(APIView):
parameters, query, count = _query_nodes(request, node_id)
if not len(query):
raise Http404()
from sqlalchemy import delete
result = session.execute(
delete(Node).where(Node.id == node_id)
)
......
......@@ -8,7 +8,7 @@ urlpatterns = [
url(r'^nodes$' , nodes.NodeListResource.as_view()),
url(r'^nodes/(\d+)$' , nodes.NodeResource.as_view()),
url(r'^nodes/(\d+)/facets$', nodes.CorpusFacet.as_view()),
url(r'^nodes/(\d+)/facets$' , nodes.CorpusFacet.as_view()),
# get a list of ngram_ids or ngram_infos by list_id
#
......@@ -21,7 +21,6 @@ urlpatterns = [
# - an optional maplist
# - an optional grouplist
# aka lexical model
url(r'^ngramlists/family$', ngramlists.ListFamily.as_view()),
url(r'^nodes/(\d+)/graph$' , nodes.CorpusGraph.as_view()),
url(r'^ngramlists/family$' , ngramlists.ListFamily.as_view()),
]
......@@ -73,31 +73,3 @@ def docs_by_journals(request, project_id, corpus_id):
},
)
@requires_auth
def graph(request, project_id, corpus_id):
'''
Graph
'''
# we pass our corpus
corpus = cache.Node[corpus_id]
# and the project just for project.id in corpusBannerTop
project = cache.Node[project_id]
# rendered page : journals.html
return render(
template_name = 'pages/corpora/journals.html',
request = request,
context = {
'debug': settings.DEBUG,
'date': datetime.now(),
'project': project,
'corpus' : corpus,
'view': 'journals'
},
)
......@@ -230,9 +230,9 @@ $("#move2trash")
console.log(ids2trash)
$.ajax({
url: "/tests/move2trash/",
data: "nodeids="+JSON.stringify(ids2trash),
type: 'POST',
url : window.location.origin + "/api/nodes?ids="+ids2trash,
//data: 'ids:'+JSON.stringify(ids2trash),
type: 'DELETE',
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment