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 = [ ...@@ -40,6 +40,7 @@ urlpatterns = [
# Module "Graph Explorer" # Module "Graph Explorer"
url(r'^projects/(\d+)/corpora/(\d+)/explorer$', explorer), url(r'^projects/(\d+)/corpora/(\d+)/explorer$', explorer),
url(r'^projects/(\d+)/corpora/(\d+)/graph$', Graph.as_view()), 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+)/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))
#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 * ...@@ -4,6 +4,7 @@ from gargantext.util.db_cache import *
from gargantext.models import * from gargantext.models import *
from gargantext.constants import * from gargantext.constants import *
from sqlalchemy import delete
from gargantext.util.validation import validate from gargantext.util.validation import validate
from collections import defaultdict from collections import defaultdict
...@@ -71,22 +72,21 @@ class NodeListResource(APIView): ...@@ -71,22 +72,21 @@ class NodeListResource(APIView):
] ]
}) })
def post(self, request):
"""Create a new node.
NOT IMPLEMENTED
"""
def delete(self, request): def delete(self, request):
"""Removes the list of nodes corresponding to the query. """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) parameters = get_parameters(request)
query.delete() 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() session.commit()
return JsonHttpResponse({
'parameters': parameters, return JsonHttpResponse({'deleted': result.rowcount})
'count': count,
}, 200)
class NodeResource(APIView): class NodeResource(APIView):
...@@ -104,7 +104,6 @@ class NodeResource(APIView): ...@@ -104,7 +104,6 @@ class NodeResource(APIView):
parameters, query, count = _query_nodes(request, node_id) parameters, query, count = _query_nodes(request, node_id)
if not len(query): if not len(query):
raise Http404() raise Http404()
from sqlalchemy import delete
result = session.execute( result = session.execute(
delete(Node).where(Node.id == node_id) delete(Node).where(Node.id == node_id)
) )
......
...@@ -8,7 +8,7 @@ urlpatterns = [ ...@@ -8,7 +8,7 @@ urlpatterns = [
url(r'^nodes$' , nodes.NodeListResource.as_view()), url(r'^nodes$' , nodes.NodeListResource.as_view()),
url(r'^nodes/(\d+)$' , nodes.NodeResource.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 # get a list of ngram_ids or ngram_infos by list_id
# #
...@@ -21,7 +21,6 @@ urlpatterns = [ ...@@ -21,7 +21,6 @@ urlpatterns = [
# - an optional maplist # - an optional maplist
# - an optional grouplist # - an optional grouplist
# aka lexical model # aka lexical model
url(r'^ngramlists/family$', ngramlists.ListFamily.as_view()), url(r'^ngramlists/family$' , ngramlists.ListFamily.as_view()),
url(r'^nodes/(\d+)/graph$' , nodes.CorpusGraph.as_view()),
] ]
...@@ -73,31 +73,3 @@ def docs_by_journals(request, project_id, corpus_id): ...@@ -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") ...@@ -230,9 +230,9 @@ $("#move2trash")
console.log(ids2trash) console.log(ids2trash)
$.ajax({ $.ajax({
url: "/tests/move2trash/", url : window.location.origin + "/api/nodes?ids="+ids2trash,
data: "nodeids="+JSON.stringify(ids2trash), //data: 'ids:'+JSON.stringify(ids2trash),
type: 'POST', type: 'DELETE',
beforeSend: function(xhr) { beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken")); 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