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
ef3f6f95
Commit
ef3f6f95
authored
Oct 05, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix] terms table: we had too long PUT urls at big list changes (BUGS-34 et 40)
parent
2c5405a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
7 deletions
+33
-7
ngramlists.py
gargantext/views/api/ngramlists.py
+21
-6
NGrams_dyna_chart_and_table.js
static/lib/gargantext/NGrams_dyna_chart_and_table.js
+12
-1
No files found.
gargantext/views/api/ngramlists.py
View file @
ef3f6f95
...
...
@@ -361,6 +361,7 @@ class ListChange(APIView):
1) Checks current user authentication to prevent remote DB manipulation
2) Prepares self.list_objects from params
"""
if
not
request
.
user
.
is_authenticated
():
raise
Http404
()
# can't use return in initial() (although 401 maybe better than 404)
...
...
@@ -368,8 +369,20 @@ class ListChange(APIView):
# get validated params
self
.
params
=
get_parameters
(
request
)
(
self
.
base_list
,
self
.
change_list
)
=
ListChange
.
_validate
(
self
.
params
)
if
not
len
(
self
.
change_list
.
items
):
payload_ngrams
=
request
.
data
[
'ngrams'
]
# print("no change_list in params but we got:", payload_ngrams)
# change_list can be in payload too
change_ngram_ids
=
[
int
(
n
)
for
n
in
payload_ngrams
.
split
(
','
)]
if
(
not
len
(
change_ngram_ids
)):
raise
ValidationException
(
'The "ngrams" parameter requires one or more ngram_ids separated by comma'
)
else
:
self
.
change_list
=
UnweightedList
(
change_ngram_ids
)
def
put
(
self
,
request
):
"""
Adds one or more ngrams to a list.
...
...
@@ -406,6 +419,7 @@ class ListChange(APIView):
'count_removed'
:
len
(
self
.
base_list
.
items
)
-
len
(
new_list
.
items
),
},
200
)
@
staticmethod
def
_validate
(
params
):
"""
...
...
@@ -420,9 +434,9 @@ class ListChange(APIView):
if
'list'
not
in
params
:
raise
ValidationException
(
'The route /api/ngramlists/change requires a "list"
\
parameter, for instance /api/ngramlists/change?list_id=42'
)
if
'ngrams'
not
in
params
:
raise
ValidationException
(
'The route /api/ngramlists/change requires an "ngrams"
\
parameter, for instance /api/ngramlists/change?ngrams=1,2,3,4'
)
#
if 'ngrams' not in params:
#
raise ValidationException('The route /api/ngramlists/change requires an "ngrams"\
#
parameter, for instance /api/ngramlists/change?ngrams=1,2,3,4')
# 2 x retrieval => 2 x UnweightedLists
# ------------------------------------
...
...
@@ -430,17 +444,18 @@ class ListChange(APIView):
try
:
base_list_id
=
int
(
params
[
'list'
])
# UnweightedList retrieved by id
base_list
=
UnweightedList
(
base_list_id
)
except
:
raise
ValidationException
(
'The "list" parameter requires an existing list id.'
)
base_list
=
UnweightedList
(
base_list_id
)
change_ngram_ids
=
[]
try
:
change_ngram_ids
=
[
int
(
n
)
for
n
in
params
[
'ngrams'
]
.
split
(
','
)]
# UnweightedList created from items
change_list
=
UnweightedList
(
change_ngram_ids
)
except
:
raise
ValidationException
(
'The "ngrams" parameter requires one or more ngram_ids separated by comma'
)
# ngrams no longer mandatory inline, see payload check afterwards
pass
change_list
=
UnweightedList
(
change_ngram_ids
)
return
(
base_list
,
change_list
)
...
...
static/lib/gargantext/NGrams_dyna_chart_and_table.js
View file @
ef3f6f95
...
...
@@ -1818,14 +1818,25 @@ function SaveLocalChanges() {
// For list modifications (add/delete), all http-requests
function
CRUD
(
list_id
,
ngram_ids
,
http_method
,
callback
)
{
// ngramlists/change?node_id=42&ngram_ids=1,2
var
the_url
=
window
.
location
.
origin
+
"/api/ngramlists/change?list="
+
list_id
+
"&ngrams="
+
ngram_ids
.
join
(
","
);
// var the_url = window.location.origin+"/api/ngramlists/change?list="+list_id+"&ngrams="+ngram_ids.join(",");
var
the_url
=
window
.
location
.
origin
+
"/api/ngramlists/change?list="
+
list_id
;
// debug
// console.log(" ajax target: " + the_url + " (" + http_method + ")")
// 2016-10-05 pass PUT and DELETE ngrams in payload as if it was POSTs
// (to avoid too long urls that trigger Bad Gateway in production)
var
myNgramsData
=
new
FormData
();
myNgramsData
.
append
(
"ngrams"
,
ngram_ids
.
join
(
","
))
if
(
ngram_ids
.
length
>
0
)
{
$
.
ajax
({
method
:
http_method
,
async
:
true
,
contentType
:
false
,
processData
:
false
,
data
:
myNgramsData
,
url
:
the_url
,
// data: args, // currently all data explicitly in the url (like a GET)
beforeSend
:
function
(
xhr
)
{
...
...
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