File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -369,10 +369,14 @@ def populate_tables(request):
369369
370370def get_citations (request ):
371371 resp = { 'message' : 'error' , 'citations' : None }
372- code = 400
373372 try :
374373 req = request .GET if request .method == 'GET' else request .POST
375- dois = [uri_to_iri (x ) for x in req .getlist ("doi" , [])]
374+ if request .method == 'GET' :
375+ dois = [uri_to_iri (x ) for x in req .getlist ("doi" , [])]
376+ else :
377+ body_unicode = request .body .decode ('utf-8' )
378+ body = json .loads (body_unicode )
379+ dois = body .get ("doi" , [])
376380 cites = Citation .objects .filter (doi__in = dois )
377381 resp ['citations' ] = {x .doi : x .cite for x in cites }
378382 code = 200
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ require([
6666
6767 A11y . Core ( ) ;
6868
69- var downloadToken = new Date ( ) . getTime ( ) ;
69+ let csrftoken = $ . getCookie ( 'csrftoken' )
7070
7171 $ ( '#citations-modal' ) . on ( 'show.bs.modal' , async function ( event ) {
7272 let button = $ ( event . relatedTarget ) ;
@@ -78,9 +78,22 @@ require([
7878 ` ) ;
7979 let dois_to_get = dois . filter ( ( d ) => ( DOI_CACHE [ d ] === null || DOI_CACHE [ d ] === undefined ) ) ;
8080 if ( dois_to_get . length > 0 ) {
81- let encoded_dois = dois_to_get . map ( d => `doi=${ encodeURIComponent ( d ) } ` ) ;
82- const resp = await fetch ( `${ BASE_URL } /citations?${ encoded_dois . join ( "&" ) } ` ) ;
81+ let resp = null ;
82+ if ( dois_to_get . join ( "," ) . length > 2048 ) {
83+ resp = await fetch ( `${ BASE_URL } /citations/` , {
84+ method : "POST" ,
85+ body : JSON . stringify ( {
86+ 'doi' : dois_to_get
87+ } ) ,
88+ headers : { "X-CSRFToken" : csrftoken } ,
89+ "content-type" : "application/json"
90+ } ) ;
91+ } else {
92+ let encoded_dois = dois_to_get . map ( d => `doi=${ encodeURIComponent ( d ) } ` ) ;
93+ resp = await fetch ( `${ BASE_URL } /citations/?${ encoded_dois . join ( "&" ) } ` ) ;
94+ }
8395 if ( ! resp . ok ) {
96+ cites_list . html ( "Failed to retrieve citations!" ) ;
8497 throw new Error ( "Failed to retrieve citations!" ) ;
8598 }
8699 let new_cites = await resp . json ( ) ;
You can’t perform that action at this time.
0 commit comments