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
df9e976a
Commit
df9e976a
authored
Aug 03, 2017
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] Quick'n'dirty termlists overwrite feature
parent
d4f65542
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
15 deletions
+39
-15
ngramlists_tools.py
gargantext/util/ngramlists_tools.py
+11
-8
ngramlists.py
gargantext/views/api/ngramlists.py
+6
-4
terms.html
templates/pages/corpora/terms.html
+22
-3
No files found.
gargantext/util/ngramlists_tools.py
View file @
df9e976a
...
...
@@ -568,7 +568,8 @@ def import_ngramlists(the_file, delimiter=DEFAULT_CSV_DELIM,
'map'
:
UnweightedList
(),
'main'
:
UnweightedList
(),
'stop'
:
UnweightedList
(),
'groupings'
:
Translations
()
'groupings'
:
Translations
(),
'new_ngram_count'
:
n_added_ng
,
}
for
list_type
in
imported_nodes_ngrams
:
...
...
@@ -664,6 +665,7 @@ def merge_ngramlists(new_lists={}, onto_corpus=None, del_originals=[]):
for
ng_id
in
new_lists
[
list_type
]
.
items
:
collect
(
ng_id
)
if
new_lists
.
get
(
'new_ngram_count'
,
0
)
>
0
:
from
gargantext.util.toolchain.main
import
t
print
(
"MERGE DEBUG: starting index_new_ngrams"
,
t
())
n_added
=
index_new_ngrams
(
all_possibly_new_ngram_ids
,
onto_corpus
)
...
...
@@ -828,7 +830,7 @@ def merge_ngramlists(new_lists={}, onto_corpus=None, del_originals=[]):
@
shared_task
def
import_and_merge_ngramlists
(
file_contents
,
onto_corpus_id
):
def
import_and_merge_ngramlists
(
file_contents
,
onto_corpus_id
,
overwrite
=
False
):
"""
A single function to run import_ngramlists and merge_ngramlists together
"""
...
...
@@ -838,6 +840,7 @@ def import_and_merge_ngramlists(file_contents, onto_corpus_id):
corpus_node
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
onto_corpus_id
)
.
first
()
# merge the new_lists onto those of the target corpus
log_msg
=
merge_ngramlists
(
new_lists
,
onto_corpus
=
corpus_node
)
del_originals
=
[
'stop'
,
'main'
,
'map'
]
if
overwrite
else
[]
log_msg
=
merge_ngramlists
(
new_lists
,
onto_corpus
=
corpus_node
,
del_originals
=
del_originals
)
return
log_msg
gargantext/views/api/ngramlists.py
View file @
df9e976a
...
...
@@ -92,7 +92,8 @@ class CSVLists(APIView):
log_msg
=
"Async generation"
corpus_node_id
=
corpus_node
.
id
scheduled
(
import_and_merge_ngramlists
)(
csv_contents
,
corpus_node_id
)
scheduled
(
import_and_merge_ngramlists
)(
csv_contents
,
corpus_node_id
,
overwrite
=
bool
(
params
.
get
(
'overwrite'
)))
return
JsonHttpResponse
({
'log'
:
log_msg
,
...
...
@@ -153,7 +154,8 @@ class CSVLists(APIView):
# attempt to merge and send response
try
:
# merge the source_lists onto those of the target corpus
log_msg
=
merge_ngramlists
(
source_lists
,
onto_corpus
=
corpus_node
)
delete
=
todo_lists
if
bool
(
params
.
get
(
'overwrite'
))
else
[]
log_msg
=
merge_ngramlists
(
source_lists
,
onto_corpus
=
corpus_node
,
del_originals
=
delete
)
return
JsonHttpResponse
({
'log'
:
log_msg
,
},
200
)
...
...
templates/pages/corpora/terms.html
View file @
df9e976a
...
...
@@ -250,6 +250,23 @@ em {
<br/>
<div
class=
"checkbox"
>
<label>
<input
type=
"checkbox"
id=
"importoverwrite"
>
Overwrite old lists
<script>
function
updateSubmitLabel
()
{
$
(
'#importsubmit'
).
val
(
$
(
this
).
is
(
':checked'
)
?
'Overwrite current table'
:
'Import and merge with current table'
);
}
$
(
function
()
{
updateSubmitLabel
.
call
(
$
(
'#importoverwrite'
));
$
(
'#importoverwrite'
).
change
(
updateSubmitLabel
);
});
</script>
</label>
</div>
<br/>
<input
type=
"submit"
class=
"btn btn-xs btn-info"
id=
"importsubmit"
value=
"Import and merge with current table"
/>
</form>
</div>
...
...
@@ -372,6 +389,8 @@ function listmergeUpdate(aFormData){
// all params are added in the url like a GET
theUrl
+=
"&from_corpus="
+
sourceCorpusId
theUrl
+=
"&todo="
+
todoLists
.
join
(
','
)
if
(
$
(
'#importoverwrite'
).
is
(
':checked'
))
theUrl
+=
"&overwrite=1"
// result url looks like this : /api/ngramlists/import?onto_corpus=2&from=13308&todo=map,stop
// console.log(theUrl)
...
...
@@ -424,7 +443,7 @@ function listmergeCsvPost(theFile){
//postCorpusFile
$
.
ajax
({
url
:
"{{importroute | safe}}"
,
url
:
"{{importroute | safe}}"
+
(
$
(
'#importoverwrite'
).
is
(
':checked'
)
?
'&overwrite=1'
:
''
)
,
type
:
'POST'
,
async
:
true
,
contentType
:
false
,
...
...
@@ -436,11 +455,11 @@ function listmergeCsvPost(theFile){
success
:
function
(
response
)
{
my_html
=
'<h3 style="color:green">File upload, you will receive a notification email</h3>'
my_html
+=
"<p class='note'>"
+
response
[
'log'
].
replace
(
/
\n
/g
,
'<br/>'
)
+
"</p>"
my_html
+=
"<p'>(this page will reload in 3s)</p>"
my_html
+=
"<p'>(this page will reload in 3
0
s)</p>"
$
(
'#formanswer'
).
html
(
my_html
);
console
.
log
(
response
)
;
// reload after 3s
setTimeout
(
"location.reload(true)"
,
3000
);
setTimeout
(
"location.reload(true)"
,
3000
0
);
},
error
:
function
(
result
,
t
)
{
if
(
t
!=
'timeout'
)
{
...
...
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