diff options
| author | Frederick Muriuki Muriithi | 2026-09-17 15:01:03 -0500 |
|---|---|---|
| committer | Frederick Muriuki Muriithi | 2026-09-17 15:04:52 -0500 |
| commit | 186649ef562c6a77d32201a393cdeecea8b5b529 (patch) | |
| tree | caa8d35ccece5cbee44e00e4c67eca739b5a0d8b | |
| parent | 3cc13543fb10790d96af61f28477f3403fbab284 (diff) | |
| download | gn-uploader-186649ef562c6a77d32201a393cdeecea8b5b529.tar.gz | |
Use 'Accept' header in ajax requests for content negotiation.
The endpoint can return either HTML or JSON depending on the 'Accept' header.
| -rw-r--r-- | uploader/genotypes/views.py | 19 | ||||
| -rw-r--r-- | uploader/static/js/files.js | 3 |
2 files changed, 17 insertions, 5 deletions
diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py index 648b38e..e475986 100644 --- a/uploader/genotypes/views.py +++ b/uploader/genotypes/views.py @@ -227,8 +227,17 @@ def create_dataset(species: dict, population: dict, **kwargs):# pylint: disable= dataset_by_id=genotype_dataset) def add_genotype_records(species: dict, population: dict, dataset: dict, **kwargs): """Add new Genotype records to the dataset.""" - return render_template("genotypes/add-genotypes-records-csv.html", - species=species, - population=population, - dataset=dataset, - activelink="add-genotypes-records") + if request.method == "GET": + return render_template("genotypes/add-genotypes-records-csv.html", + species=species, + population=population, + dataset=dataset, + activelink="add-genotypes-records") + + if "application/json" in request.headers.get("Accept"): + return make_response( + jsonify({ + "message": ("Upload successful. Follow the 'redirect-to' URI " + "to continue") + }), + 200) diff --git a/uploader/static/js/files.js b/uploader/static/js/files.js index f6c9c97..7532df3 100644 --- a/uploader/static/js/files.js +++ b/uploader/static/js/files.js @@ -286,6 +286,9 @@ var makeFormSubmitter = function (form, processForm, num_files) { "url": form.attr("action"), "type": "POST", "data": processForm(form[0], uploaded_files),// `uploaded_files` changes with each file added -- check this and fix. + "beforeSend": function(xhr) { + xhr.setRequestHeader("Accept", "application/json"); + }, "processData": false, "contentType": false, "success": (data, textstatus, jqxhr) => { |
