Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
27d3b588
Commit
27d3b588
authored
May 09, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Adding download button.
parent
91e14e3e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
27 deletions
+68
-27
nodes.py
gargantext/views/api/nodes.py
+37
-8
menu.html
templates/pages/menu.html
+31
-19
No files found.
gargantext/views/api/nodes.py
View file @
27d3b588
...
...
@@ -11,8 +11,11 @@ from gargantext.util.http import ValidationException, APIView \
from
collections
import
defaultdict
import
csv
_node_available_fields
=
[
'id'
,
'parent_id'
,
'name'
,
'typename'
,
'hyperdata'
,
'ngrams'
]
_node_default_fields
=
[
'id'
,
'parent_id'
,
'name'
,
'typename'
]
_node_available_formats
=
[
'json'
,
'csv'
,
'bibex'
]
_node_available_types
=
NODETYPES
...
...
@@ -21,6 +24,7 @@ def _query_nodes(request, node_id=None):
# parameters validation
parameters
=
get_parameters
(
request
)
parameters
=
validate
(
parameters
,
{
'type'
:
dict
,
'items'
:
{
'formated'
:
{
'type'
:
str
,
'required'
:
False
,
'default'
:
'json'
},
'pagination_limit'
:
{
'type'
:
int
,
'default'
:
10
},
'pagination_offset'
:
{
'type'
:
int
,
'default'
:
0
},
'fields'
:
{
'type'
:
list
,
'default'
:
_node_default_fields
,
'items'
:
{
...
...
@@ -65,14 +69,39 @@ class NodeListResource(APIView):
"""Displays the list of nodes corresponding to the query.
"""
parameters
,
query
,
count
=
_query_nodes
(
request
)
return
JsonHttpResponse
({
'parameters'
:
parameters
,
'count'
:
count
,
'records'
:
[
{
field
:
getattr
(
node
,
field
)
for
field
in
parameters
[
'fields'
]}
for
node
in
query
]
})
if
parameters
[
'formated'
]
==
'json'
:
return
JsonHttpResponse
({
'parameters'
:
parameters
,
'count'
:
count
,
'records'
:
[
{
field
:
getattr
(
node
,
field
)
for
field
in
parameters
[
'fields'
]}
for
node
in
query
]
})
elif
parameters
[
'formated'
]
==
'csv'
:
response
=
HttpResponse
(
content_type
=
'text/csv'
)
response
[
'Content-Disposition'
]
=
'attachment; filename="Gargantext_Corpus.csv"'
writer
=
csv
.
writer
(
response
)
keys
=
[
'title'
,
'journal'
,
'publication_date'
,
'abstract'
,
'authors'
]
writer
.
writerow
(
keys
)
for
node
in
query
:
data
=
list
()
for
key
in
keys
:
try
:
data
.
append
(
node
.
hyperdata
[
key
])
except
:
data
.
append
(
""
)
writer
.
writerow
(
data
)
return
response
def
post
(
self
,
request
):
...
...
templates/pages/menu.html
View file @
27d3b588
...
...
@@ -145,7 +145,7 @@
<!-- <li class="divider"></li> --!>
<div class="row">
<div class="col-md-
4
">
<div class="col-md-
5
">
{% if project %}
<h3><a href="/projects/{{project.id}}">
<span class="glyphicon glyphicon-book" aria-hidden="true"></span>
...
...
@@ -163,27 +163,39 @@
</h3>
{% endif %}
</div>
<div class="col-md-4">
<div class="col-md-5">
<h3>
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>
Author(s):
</h3>
<h4>
<div class="row">
<span class="glyphicon glyphicon-hand-right" aria-hidden="true"></span>
{{ user.username | truncatechars:15}}
</div>
</h4>
</div>
<div class="col-md-4">
<br>
<!-- <a class="btn btn-default" role="button" href="/project/{{project.id}}/corpus/{{corpus.id}}/{{view}}/update">Update</a> -->
<!--
<a class="btn btn-default" role="button" href="/project/{{project.id}}/corpus/{{ corpus.id }}/corpus.csv">Download</a>
<a type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="bottom"
data-content='
<ul>
<li> Rename </li>
<li> Add new documents </li>
<li><a href="/delete/{{corpus.id}}">Delete</a></li>
</ul>
'>Manage</a>
-->
<!-- <a class="btn btn-primary btn-lg" role="button" href="/admin/documents/corpus/{{ corpus.id }}/">Add documents</a></p> -->
<div class="col-md-1">
<div class="row"><br>
<a class="btn btn-default" role="button" href="/api/nodes?parent_id={{corpus.id}}&types[]=DOCUMENT&pagination_limit=100000&formated=csv">Download</a>
<!--<a class="btn btn-default" role="button" href="/project/{{project.id}}/corpus/{{corpus.id}}/{{view}}/update">Update</a>--!>
<!--
<a type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="bottom"
data-content='
<ul>
<li> Rename </li>
<li> Add new documents </li>
<li><a href="/delete/{{corpus.id}}">Delete</a></li>
</ul>
'>Manage</a>
<a class="btn btn-primary btn-lg" role="button" href="/admin/documents/corpus/{{ corpus.id }}/">Add documents</a></p>
--!>
</div>
</div>
</div>
</div>
</div>
</div>
{% else %}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment