Commit b8e3f83b authored by Administrator's avatar Administrator

Merge branch 'samuel' into unstable

parents 024b2ca5 6cd09846
...@@ -620,7 +620,20 @@ class Nodes(APIView): ...@@ -620,7 +620,20 @@ class Nodes(APIView):
'metadata': dict(node.metadata), 'metadata': dict(node.metadata),
}) })
# deleting node by id
def delete(self, request, node_id):
session = get_session()
node = models.Node.objects.filter(id = node_id)
msgres = ""
try:
node.delete()
msgres = node_id+" deleted!"
except:
msgres ="error deleting: "+node_id
return JsonHttpResponse({
'deleted': msgres,
})
class CorpusController: class CorpusController:
......
...@@ -54,7 +54,7 @@ urlpatterns = patterns('', ...@@ -54,7 +54,7 @@ urlpatterns = patterns('',
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+)$', 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()),
url(r'^api/project/(\d+)/corpus/(\d+)/timerange/(\d+)/(\d+)$', views.subcorpusJSON), url(r'^api/project/(\d+)/corpus/(\d+)/timerange/(\d+)/(\d+)$', views.subcorpusJSON),
url(r'^api/nodes/(\d+)/ngrams$', gargantext_web.api.CorpusController.ngrams), url(r'^api/nodes/(\d+)/ngrams$', gargantext_web.api.CorpusController.ngrams),
......
...@@ -218,7 +218,6 @@ def project(request, project_id): ...@@ -218,7 +218,6 @@ def project(request, project_id):
#form = CorpusForm(request.POST, request.FILES) #form = CorpusForm(request.POST, request.FILES)
#print(str(request.POST)) #print(str(request.POST))
name = str(request.POST['name']) name = str(request.POST['name'])
try: try:
resource_type = ResourceType.objects.get(id=str(request.POST['type'])) resource_type = ResourceType.objects.get(id=str(request.POST['type']))
except Exception as error: except Exception as error:
...@@ -258,6 +257,8 @@ def project(request, project_id): ...@@ -258,6 +257,8 @@ def project(request, project_id):
) )
corpus.save() corpus.save()
print(request.user, resource_type , file )
print(corpus.language) print(corpus.language)
corpus.add_resource( corpus.add_resource(
user=request.user, user=request.user,
......
...@@ -129,11 +129,34 @@ class Node(CTENode): ...@@ -129,11 +129,34 @@ class Node(CTENode):
return Resource.objects.select_related('node_resource').filter(node_resource__node = self) return Resource.objects.select_related('node_resource').filter(node_resource__node = self)
def add_resource(self, **kwargs): def add_resource(self, **kwargs):
print("printing arguments for add_resource():")
print(kwargs)
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
import os
thefile = kwargs["file"]
path = default_storage.save('tmp/somename.zip', ContentFile(thefile.read()))
tmp_file = os.path.join(MEDIA_ROOT, path)
print(tmp_file)
kwargs["file"] = tmp_file
print("final kwargs:")
print(kwargs)
# only for tests # only for tests
resource = Resource(guid=str(time()), digest=str(time()), **kwargs ) resource = Resource(guid=str(time()), digest=str(time()), **kwargs )
#resource = Resource(**kwargs) #resource = Resource(**kwargs)
resource.save() resource.save()
print("printing rresource.file:")
print(resource.file)
# print("printing the resource 01____:")
# print(resource.file)
# print("printing the resource 02____: asdasdasd")
# User # User
if 'user' not in kwargs and 'user_id' not in kwargs: if 'user' not in kwargs and 'user_id' not in kwargs:
resource.user = self.user resource.user = self.user
...@@ -170,6 +193,8 @@ class Node(CTENode): ...@@ -170,6 +193,8 @@ class Node(CTENode):
'europress_french' : EuropressFileParser, 'europress_french' : EuropressFileParser,
'europress_english' : EuropressFileParser, 'europress_english' : EuropressFileParser,
})[resource.type.name]() })[resource.type.name]()
print("parse_resources:")
print(resource.file)
metadata_list += parser.parse(str(resource.file)) metadata_list += parser.parse(str(resource.file))
# retrieve info from the database # retrieve info from the database
type_id = NodeType.objects.get(name='Document').id type_id = NodeType.objects.get(name='Document').id
......
...@@ -70,18 +70,20 @@ class EuropressFileParser(FileParser): ...@@ -70,18 +70,20 @@ class EuropressFileParser(FileParser):
if isinstance(text, bytes): if isinstance(text, bytes):
text = text.decode(encoding) text = text.decode(encoding)
format_date_fr = re.compile('\d*\s*\w+\s+\d{4}', re.UNICODE) format_date_fr = re.compile('\d*\s*\w+\s+\d{4}', re.UNICODE)
test_date_fr = format_date_fr.match(text) if text is not None:
test_date_fr = format_date_fr.match(text)
format_date_en = re.compile('\w+\s+\d+,\s+\d{4}', re.UNICODE) format_date_en = re.compile('\w+\s+\d+,\s+\d{4}', re.UNICODE)
test_date_en = format_date_en.match(text) test_date_en = format_date_en.match(text)
format_sect = re.compile('(\D+),', re.UNICODE)
format_sect = re.compile('(\D+),', re.UNICODE) test_sect = format_sect.match(text)
test_sect = format_sect.match(text) format_page = re.compile(', p. (\w+)', re.UNICODE)
test_page = format_page.match(text)
format_page = re.compile(', p. (\w+)', re.UNICODE) else:
test_page = format_page.match(text) test_date_fr = None
test_date_en = None
test_sect = None
test_page = None
if test_date_fr is not None: if test_date_fr is not None:
self.localeEncoding = "fr_FR" self.localeEncoding = "fr_FR"
......
...@@ -224,6 +224,23 @@ function updateDocuments(pagenumber,pagenav) { ...@@ -224,6 +224,23 @@ function updateDocuments(pagenumber,pagenav) {
} }
var current_docs = {}
var BIS_dict = {}
var corpusid = window.location.href.split("corpus")[1].replace(/\//g, '')//replace all the slashes
var theurl = "http://localhost:8000/api/nodes/"+corpusid+"/children/duplicates?keys=title&limit=9999"
$.ajax({
url: theurl,
success: function(data) {
bisarray = data.data
for(var i in bisarray) {
onebis = bisarray[i].values
BIS_dict[onebis[0]] = [bisarray[i].count , 0];// [ total amount , removed ]
}
pr(BIS_dict)
}
});
// var gainOrLossChart = dc.pieChart("#gain-loss-chart"); // var gainOrLossChart = dc.pieChart("#gain-loss-chart");
// var fluctuationChart = dc.barChart("#fluctuation-chart"); // var fluctuationChart = dc.barChart("#fluctuation-chart");
// var quarterChart = dc.pieChart("#quarter-chart"); // var quarterChart = dc.pieChart("#quarter-chart");
......
{% if date %}
<p>Today: {{date}}</p>
{% endif %}
<div class="pagination"> <div class="pagination">
<span class="step-links"> <span class="step-links">
{% if documents.has_previous %} {% if documents.has_previous %}
...@@ -25,9 +21,56 @@ ...@@ -25,9 +21,56 @@
<ul> <ul>
{% for doc in documents %} {% for doc in documents %}
{% if doc.date %} {% if doc.date %}
<li> <b>{{ doc.date }}</b>: <a target="_blank" href="/nodeinfo/{{doc.id}}">{{ doc.name}}</a> , @ {{ doc.metadata.source}}</li> <li><div id="doc_{{doc.id}}"> <b>{{ doc.date }}</b>: <a target="_blank" href="/nodeinfo/{{doc.id}}">{{ doc.name}}</a> , @ {{ doc.metadata.source}}</div></li>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
<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;
}
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 = []
{% for doc in documents %}
id = "doc_{{doc.id}}"
title = "{{doc.name}}"
if(BIS_dict[title]) {
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>'
$("#"+id).prepend( delimg )
}
{% endfor %}
</script>
{% endif %} {% endif %}
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