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
75d4a738
Commit
75d4a738
authored
Jun 21, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'romain-goodies' into unstable
parents
3a445e73
aacd15ef
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
347 additions
and
145 deletions
+347
-145
constants.py
gargantext/constants.py
+3
-0
ngramlists_tools.py
gargantext/util/ngramlists_tools.py
+215
-129
ngramlists.py
gargantext/views/api/ngramlists.py
+24
-11
tables.css
static/lib/gargantext/tables.css
+1
-1
terms.html
templates/pages/corpora/terms.html
+104
-4
No files found.
gargantext/constants.py
View file @
75d4a738
...
...
@@ -250,6 +250,9 @@ DEFAULT_INDEX_SUBGRAMS = False # False <=> traditional
# at indexing after extraction)
# ngram lists import/export parameters -----------------------------------------
DEFAULT_CSV_DELIM
=
'
\t
'
# for import/export CSV defaults
DEFAULT_CSV_DELIM_GROUP
=
'|&|'
# ------------------------------------------------------------------------------
...
...
gargantext/util/ngramlists_tools.py
View file @
75d4a738
This diff is collapsed.
Click to expand it.
gargantext/views/api/ngramlists.py
View file @
75d4a738
...
...
@@ -66,29 +66,42 @@ class CSVLists(APIView):
/!
\
We assume we checked the file size client-side before upload
£TODO check authentication and user.id
"""
if
not
request
.
user
.
is_authenticated
():
res
=
HttpResponse
(
"Unauthorized"
)
res
.
status_code
=
401
return
res
# this time the corpus param is the one with the target lists to be patched
params
=
get_parameters
(
request
)
corpus_id
=
int
(
params
.
pop
(
"onto_corpus"
))
corpus_node
=
cache
.
Node
[
corpus_id
]
if
request
.
user
.
id
!=
corpus_node
.
user_id
:
res
=
HttpResponse
(
"Unauthorized"
)
res
.
status_code
=
401
return
res
# request also contains the file
# csv_file has type django.core.files.uploadedfile.InMemoryUploadedFile
# ----------------------
csv_file
=
request
.
data
[
'csvfile'
]
# import the csv
new_lists
=
import_ngramlists
(
csv_file
)
del
csv_file
# merge the new_lists onto those of the target corpus
log_msg
=
merge_ngramlists
(
new_lists
,
onto_corpus
=
corpus_node
)
return
JsonHttpResponse
({
'log'
:
log_msg
,
},
200
)
try
:
new_lists
=
import_ngramlists
(
csv_file
)
del
csv_file
# merge the new_lists onto those of the target corpus
log_msg
=
merge_ngramlists
(
new_lists
,
onto_corpus
=
corpus_node
)
return
JsonHttpResponse
({
'log'
:
log_msg
,
},
200
)
except
Exception
as
e
:
return
JsonHttpResponse
({
'err'
:
str
(
e
),
},
400
)
...
...
static/lib/gargantext/tables.css
View file @
75d4a738
...
...
@@ -87,7 +87,7 @@ p.note > label {
opacity
:
0.3
;
}
tr
:hover
{
#my-ajax-table
tr
:hover
{
cursor
:
pointer
;
font-weight
:
bold
;
}
...
...
templates/pages/corpora/terms.html
View file @
75d4a738
...
...
@@ -7,6 +7,53 @@
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static "
lib
/
gargantext
/
tables
.
css
"%}"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static "
lib
/
gargantext
/
charts
.
css
"%}"
/>
<style>
#formatinfos-announce
{
font-size
:
12px
;
padding-top
:
.5em
;
}
#formatinfos
{
background-color
:
#CCC
;
font-size
:
12px
;
padding
:
1em
;
border-radius
:
1em
;
margin
:
1.5em
;
}
#formatinfos
table
{
margin-left
:
2.5em
;
margin-bottom
:
1em
;
margin-top
:
1em
;
}
#formatinfos
tr
:hover
{
font-weight
:
normal
}
#formatinfos
td
{
color
:
inherit
;
hover
:
none
;
}
#formatinfos
h4
{
font-size
:
14px
;
color
:
#777
;
font-weight
:
bold
;
}
#formatinfos
p
{
font-size
:
14px
;
}
#formatinfos
em
{
font-weight
:
bold
;
}
</style>
<script
type=
"text/javascript"
src=
"{% static "
lib
/
d3
/
d3
.
js
"%}"
></script>
<script
type=
"text/javascript"
src=
"{% static "
lib
/
d3
/
crossfilter
.
js
"%}"
></script>
<script
type=
"text/javascript"
src=
"{% static "
lib
/
d3
/
dc
.
js
"%}"
></script>
...
...
@@ -126,7 +173,7 @@
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-hidden=
"true"
>
×
</button>
<h3
id=
"myModalLabel"
>
Import a
CSV term
list
</h3>
<h3
id=
"myModalLabel"
>
Import a
Term
list
</h3>
</div>
<div
class=
"modal-body"
id=
"uploadform"
>
<form
id=
"csvimportform"
...
...
@@ -134,8 +181,36 @@
enctype=
"multipart/form-data"
method=
"post"
>
{% csrf_token %}
<label>
From your disk:
</label>
<label>
From
a CSV on
your disk:
</label>
<input
type=
"file"
id=
"csvfile"
accept=
"text/csv"
>
<p
id=
"formatinfos-announce"
>
<span
id=
"formatinfos-icon"
class=
"glyphicon glyphicon-triangle-right"
onclick=
"toggleFormatInfos()"
></span>
More infos about CSV expected format
</p>
<div
id=
"formatinfos"
style=
"display:none;"
>
<h4>
Example table
</h4>
<table
class=
"table-condensed note"
>
<tr><th>
status
</th>
<th>
label
</th>
<th>
forms
</th></tr>
<tr><td>
map
</td>
<td>
barograph
</td>
<td></td></tr>
<tr><td>
map
</td>
<td>
seafaring
</td>
<td>
seafarer|
&
|ocean travel
</td></tr>
<tr><td>
main
</td>
<td>
electromagnetic
</td>
<td>
electro-magnetic
</td></tr>
</table>
<h4>
Remarks
</h4>
<ul>
<li>
Tabulation is the expected delimiter between columns.
</li>
<li>
The only mandatory column is
<em>
label
</em>
.
</li>
<li>
If
<em>
status
</em>
is absent, default target status is "map"
</li>
<li>
When a column is there, always add its header on the 1st line:
<em>
status
</em>
,
<em>
label
</em>
,
<em>
forms
</em></li>
<li>
The label will be always added as a form, even if it's not in 'forms' column
</li>
<li>
The string
<em>
|
&
|
</em>
(3 characters) is the expected delimiter between forms.
</li>
</ul>
</div>
<br/>
<label>
From another corpus:
</label>
<p>
TODO
</p>
...
...
@@ -153,6 +228,28 @@
<script
type=
"text/javascript"
src=
"{% static "
lib
/
gargantext
/
NGrams_dyna_chart_and_table
.
js
"
%}"
></script>
<script
type=
"text/javascript"
>
var
formatInfosOpen
=
false
;
function
toggleFormatInfos
()
{
// when already open => we close
if
(
formatInfosOpen
)
{
// hide div
$
(
'#formatinfos'
).
hide
()
// change icon
$
(
'#formatinfos-icon'
)[
0
].
classList
.
remove
(
'glyphicon-triangle-bottom'
)
$
(
'#formatinfos-icon'
)[
0
].
classList
.
add
(
'glyphicon-triangle-right'
)
// toggle flag
formatInfosOpen
=
false
;
}
else
{
// opposite case
$
(
'#formatinfos'
).
show
()
$
(
'#formatinfos-icon'
)[
0
].
classList
.
remove
(
'glyphicon-triangle-right'
)
$
(
'#formatinfos-icon'
)[
0
].
classList
.
add
(
'glyphicon-triangle-bottom'
)
formatInfosOpen
=
true
;
}
}
/* merci c24b !
* Uses csvimportroute variable from the django template
...
...
@@ -202,7 +299,7 @@ function postCSV(e){
xhr
.
setRequestHeader
(
"X-CSRFToken"
,
getCookie
(
"csrftoken"
));
},
success
:
function
(
response
)
{
my_html
=
"<h2 color='green'>IMPORT OK ! </h2>"
my_html
=
'<h3 style="color:green">IMPORT OK</h3>'
my_html
+=
"<p class='note'>"
+
response
[
'log'
].
replace
(
/
\n
/g
,
'<br/>'
)
+
"</p>"
my_html
+=
"<p'>(this page will reload in 3s)</p>"
$
(
'#formanswer'
).
html
(
my_html
);
...
...
@@ -211,7 +308,10 @@ function postCSV(e){
setTimeout
(
"location.reload(true)"
,
3000
);
},
error
:
function
(
result
)
{
$
(
'#formanswer'
).
html
(
'Erreur'
);
my_html
=
'<h3 style="color:red">Error</h3>'
my_html
+=
"<p class='note'>please correct your CSV file and retry</p>"
my_html
+=
"<p>"
+
result
.
responseJSON
[
'err'
]
+
"</p>"
$
(
'#formanswer'
).
html
(
my_html
);
console
.
error
(
result
);
},
});
...
...
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