Commit 69e5fb9d authored by PkSM3's avatar PkSM3

[UPDATE] successfyllu deleting duplicated doc and reload page(for the moment)

parent e9bceac5
...@@ -622,29 +622,20 @@ class Nodes(APIView): ...@@ -622,29 +622,20 @@ class Nodes(APIView):
'metadata': dict(node.metadata), 'metadata': dict(node.metadata),
}) })
# deleting node by id
def delete(self, request, node_id): def delete(self, request, node_id):
session = get_session() session = get_session()
# get the minimum ID for each of the nodes sharing the same metadata node = models.Node.objects.filter(id = node_id)
node = models.Node.objects.filter(id = node_id).first() msgres = ""
# delete the stuff try:
delete_query = (session node.delete()
.query(Node) msgres = node_id+" deleted!"
.filter(Node.parent_id == node_id) except:
) msgres ="error deleting: "+node_id
print("in Nodes.delete():")
print("node to delete: "+node_id)
print(delete_query)
print("--")
count = delete_query.count()
# delete_query.delete(synchronize_session=False)
# session.flush()
# # return the result
return JsonHttpResponse({ return JsonHttpResponse({
'deleted': count, 'deleted': msgres,
}) })
# return duplicates_query
class CorpusController: class CorpusController:
......
...@@ -222,13 +222,9 @@ function updateDocuments(pagenumber,pagenav) { ...@@ -222,13 +222,9 @@ function updateDocuments(pagenumber,pagenav) {
} }
//else: "Read Documents" collapsible is open!, so do nothing //else: "Read Documents" collapsible is open!, so do nothing
} }
$.ajax({
url: 'http://localhost:8000/api/nodes/44335',
type: 'DELETE',
success: function(result) {
console.log("Do something with the result");
}
});
var current_docs = {} var current_docs = {}
var BIS_dict = {} var BIS_dict = {}
var corpusid = window.location.href.split("corpus")[1].replace(/\//g, '')//replace all the slashes var corpusid = window.location.href.split("corpus")[1].replace(/\//g, '')//replace all the slashes
......
...@@ -27,13 +27,55 @@ ...@@ -27,13 +27,55 @@
</ul> </ul>
<script> <script>
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
// Only send the token to relative URLs i.e. locally.
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
}
});
function deleteNode(node_id) {
$.ajax({
url: '/api/nodes/'+node_id,
type: 'DELETE',
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
},
success: function(result) {
console.log(result)
location.reload();
},
error: function(result) {
console.log("Data not found");
console.log(result)
}
});
}
current_docs = [] current_docs = []
{% for doc in documents %} {% for doc in documents %}
id = "doc_{{doc.id}}" id = "doc_{{doc.id}}"
title = "{{doc.name}}" title = "{{doc.name}}"
if(BIS_dict[title]) { if(BIS_dict[title]) {
var ahref = 'here goes the delete url' var delimg = '<a title="Delete this document!" style="cursor: pointer;" onclick="deleteNode('+"{{doc.id}}"+')"><img width="20px" src="/static/img/delete-big.png"></img></a>'
var delimg = '<a><img width="20px" src="/static/img/delete-big.png"></img></a>'
$("#"+id).prepend( delimg ) $("#"+id).prepend( delimg )
} }
{% endfor %} {% endfor %}
......
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