Commit 0cc607d3 authored by PkSM3's avatar PkSM3

[UPDATE] delete all duplicates

parent 6d6ccfa1
...@@ -234,20 +234,23 @@ class NodesChildrenDuplicates(APIView): ...@@ -234,20 +234,23 @@ class NodesChildrenDuplicates(APIView):
# get the minimum ID for each of the nodes sharing the same metadata # get the minimum ID for each of the nodes sharing the same metadata
kept_node_ids_query = self._fetch_duplicates(request, node_id, [func.min(Node.id).label('id')], 0) kept_node_ids_query = self._fetch_duplicates(request, node_id, [func.min(Node.id).label('id')], 0)
kept_node_ids = [kept_node.id for kept_node in kept_node_ids_query] kept_node_ids = [kept_node.id for kept_node in kept_node_ids_query]
# delete the stuff duplicate_nodes = models.Node.objects.filter( parent_id=node_id ).exclude(id__in=kept_node_ids)
delete_query = (session # # delete the stuff
.query(Node) # delete_query = (session
.filter(Node.parent_id == node_id) # .query(Node)
.filter(~Node.id.in_(kept_node_ids)) # .filter(Node.parent_id == node_id)
) # .filter(~Node.id.in_(kept_node_ids))
count = delete_query.count() # )
delete_query.delete(synchronize_session=False) count = len(duplicate_nodes)
session.flush() for node in duplicate_nodes:
# return the result print("deleting node ",node.id)
node.delete()
# print(delete_query)
# # delete_query.delete(synchronize_session=True)
# session.flush()
return JsonHttpResponse({ return JsonHttpResponse({
'deleted': count, 'deleted': count
}) })
# return duplicates_query
...@@ -621,6 +624,7 @@ class Nodes(APIView): ...@@ -621,6 +624,7 @@ class Nodes(APIView):
}) })
# deleting node by id # deleting node by id
# currently, very dangerous
def delete(self, request, node_id): def delete(self, request, node_id):
session = get_session() session = get_session()
node = models.Node.objects.filter(id = node_id) node = models.Node.objects.filter(id = node_id)
......
...@@ -53,6 +53,7 @@ urlpatterns = patterns('', ...@@ -53,6 +53,7 @@ urlpatterns = patterns('',
url(r'^api/nodes/(\d+)/children/metadata$', gargantext_web.api.NodesChildrenMetatadata.as_view()), url(r'^api/nodes/(\d+)/children/metadata$', gargantext_web.api.NodesChildrenMetatadata.as_view()),
url(r'^api/nodes/(\d+)/children/queries$', gargantext_web.api.NodesChildrenQueries.as_view()), url(r'^api/nodes/(\d+)/children/queries$', gargantext_web.api.NodesChildrenQueries.as_view()),
url(r'^api/nodes/(\d+)/children/duplicates$', gargantext_web.api.NodesChildrenDuplicates.as_view()), url(r'^api/nodes/(\d+)/children/duplicates$', gargantext_web.api.NodesChildrenDuplicates.as_view()),
# url(r'^api/nodes/(\d+)/children/duplicates/delete$', gargantext_web.api.NodesChildrenDuplicates.delete ),
url(r'^api/nodes/(\d+)$', gargantext_web.api.Nodes.as_view()), url(r'^api/nodes/(\d+)$', gargantext_web.api.Nodes.as_view()),
url(r'^api/nodes$', gargantext_web.api.NodesList.as_view()), url(r'^api/nodes$', gargantext_web.api.NodesList.as_view()),
......
...@@ -239,6 +239,7 @@ $.ajax({ ...@@ -239,6 +239,7 @@ $.ajax({
BIS_dict[untitlebis[0]] = [bisarray[i].count , 0];// [ total amount , removed ] BIS_dict[untitlebis[0]] = [bisarray[i].count , 0];// [ total amount , removed ]
} }
pr(BIS_dict) pr(BIS_dict)
if(Object.keys(BIS_dict).length>0) $("#delAll").css("visibility", "visible"); $("#delAll").show();
} }
}); });
......
...@@ -19,6 +19,12 @@ ...@@ -19,6 +19,12 @@
{% if documents %} {% if documents %}
<div id="delAll" style="visibility: hidden;">
<button onclick="deleteDuplicates(theurl);">Delete Duplicates</button>
</div>
<ul> <ul>
{% for doc in documents %} {% for doc in documents %}
{% if doc.date %} {% if doc.date %}
...@@ -45,6 +51,26 @@ function getCookie(name) { ...@@ -45,6 +51,26 @@ function getCookie(name) {
return cookieValue; return cookieValue;
} }
function deleteDuplicates(url) {
console.log("hello world")
console.log(url)
$.ajax({
url: url,
type: 'DELETE',
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
},
success: function(data) {
console.log("in DeleteDuplicates")
console.log(data)
$("#delAll").remove();
},
error: function(result) {
console.log("Data not found");
console.log(result)
}
});
}
function deleteNode(node_id) { function deleteNode(node_id) {
$.ajax({ $.ajax({
...@@ -111,6 +137,11 @@ function deleteNode(node_id) { ...@@ -111,6 +137,11 @@ function deleteNode(node_id) {
//'+"{{doc.id}}"+',\"'+title+'\" //'+"{{doc.id}}"+',\"'+title+'\"
current_docs = {} current_docs = {}
if(Object.keys(BIS_dict).length>0) {
$("#delAll").css("visibility", "visible");
$("#delAll").show();
} else $("#delAll").remove()
{% for doc in documents %} {% for doc in documents %}
id = "doc_{{doc.id}}" id = "doc_{{doc.id}}"
title = $("<div/>").html("{{doc.name}}").text() title = $("<div/>").html("{{doc.name}}").text()
......
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