diff --git a/Pipfile b/Pipfile index d760197..7cbc64a 100644 --- a/Pipfile +++ b/Pipfile @@ -14,6 +14,7 @@ uuid = "*" django-anymail = {extras = ["mailgun"]} whitenoise = "*" django-import-export = "*" +"beautifulsoup4" = "*" [dev-packages] selenium = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 586bc3e..0f3ac9a 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "84c82ea544617a654420f88f0121bd55a61f6aa48bf9e0da6e74670dad53743c" + "sha256": "6a69113216b0e4cdef5dca808dac46d78b2c79edf087766d6608e8abcc721a9e" }, "pipfile-spec": 6, "requires": { @@ -16,6 +16,15 @@ ] }, "default": { + "beautifulsoup4": { + "hashes": [ + "sha256:11a9a27b7d3bddc6d86f59fb76afb70e921a25ac2d6cc55b40d072bd68435a76", + "sha256:7015e76bf32f1f574636c4288399a6de66ce08fb7b2457f628a8d70c0fbabb11", + "sha256:808b6ac932dccb0a4126558f7dfdcf41710dd44a4ef497a0bb59a77f9f078e89" + ], + "index": "pypi", + "version": "==4.6.0" + }, "certifi": { "hashes": [ "sha256:13e698f54293db9f89122b0581843a782ad0934a4fe0172d2a980ba77fc61bb7", @@ -99,10 +108,10 @@ }, "idna": { "hashes": [ - "sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f", - "sha256:8c7309c718f94b3a625cb648ace320157ad16ff131ae0af362c9f21b80ef6ec4" + "sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e", + "sha256:684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16" ], - "version": "==2.6" + "version": "==2.7" }, "jdcal": { "hashes": [ @@ -185,10 +194,10 @@ }, "requests": { "hashes": [ - "sha256:6a1b267aa90cac58ac3a765d067950e7dbbf75b1da07e895d1f594193a40a38b", - "sha256:9c443e7324ba5b85070c4a818ade28bfabedf16ea10206da1132edaa6dda237e" + "sha256:63b52e3c866428a224f97cab011de738c36aec0185aa91cfacd418b5d58911d1", + "sha256:ec22d826a36ed72a7358ff3fe56cbd4ba69dd7a6718ffd450ff0e9df7a47ce6a" ], - "version": "==2.18.4" + "version": "==2.19.1" }, "six": { "hashes": [ @@ -211,10 +220,10 @@ }, "urllib3": { "hashes": [ - "sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b", - "sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f" + "sha256:a68ac5e15e76e7e5dd2b8f94007233e01effe3e50e8daddf69acfd81cb686baf", + "sha256:b5725a0bd4ba422ab0e66e89e030c806576753ea3ee08554382c14e685d117b5" ], - "version": "==1.22" + "version": "==1.23" }, "uuid": { "hashes": [ diff --git a/manuels/static/manuels/fetch-isbn.js b/manuels/static/manuels/fetch-isbn.js index 4c38526..f7e03e5 100644 --- a/manuels/static/manuels/fetch-isbn.js +++ b/manuels/static/manuels/fetch-isbn.js @@ -1,7 +1,46 @@ document.addEventListener("DOMContentLoaded", function (event) { - console.log('document loaded'); + var isbnButton = document.querySelector('#id_isbn_button'); var isbn = document.querySelector('#id_isbn'); - isbn.addEventListener('change', function (event) { + isbnButton.addEventListener('click', function (event) { + $.get("/isbn_api/" + isbn.value, {}, function (data, status, xhr) { + if (data.error) { + isbn.classList.add('is-invalid'); + isbn.classList.remove('is-valid'); + document.querySelector('#id_isbn_invalid_feedback').style.display = 'block'; + document.querySelector('#id_isbn_error_text').textContent = data.error; + return; + } + isbn.classList.remove('is-invalid'); + isbn.classList.add('is-valid'); + document.querySelector('#id_isbn_invalid_feedback').style.display = 'none'; + + document.querySelector('#id_title').value = data.title; + document.querySelector('#id_authors').value = data.authors; + document.querySelector('#id_publication_year').value = data.year; + document.querySelector('#id_price').value = data.price; + + var editorValue = ""; + var editorIsOther = false; + for (var option of document.querySelector('#id_editor').children) { + if (editorValue === "" && option.firstChild.data.toLowerCase().indexOf('autre') !== -1) { + editorValue = option.value; + editorIsOther = true; + } + if (option.firstChild.data.toLowerCase() === data.editor.toLowerCase()) { + editorValue = option.value; + editorIsOther = false; + } + } + document.querySelector('#id_editor').value = editorValue; + + event = document.createEvent("HTMLEvents"); + event.initEvent("change", true, true); + event.eventName = "change"; + document.querySelector('#id_editor').dispatchEvent(event); + if (editorIsOther) { + document.querySelector('#id_other_editor').value = data.editor + } + }); }); }); diff --git a/manuels/templates/manuels/add_book.html b/manuels/templates/manuels/add_book.html index 3df2f2e..79ce66a 100644 --- a/manuels/templates/manuels/add_book.html +++ b/manuels/templates/manuels/add_book.html @@ -27,7 +27,27 @@
- {% bootstrap_field form.isbn %} +
+ {% bootstrap_label content=form.isbn.label label_for=id_isbn %} +
+ +
+ +
+
+
+ Erreur lors de la recherche. Veuillez saisir les informations du livre à la main.
+ Données techniques : +
+ + {{ form.isbn.help_text|safe }} + +
@@ -55,11 +75,11 @@
{% if form.add_another %} -
-
- {% bootstrap_field form.add_another %} +
+
+ {% bootstrap_field form.add_another %} +
-
{% endif %} {% endblock %} diff --git a/manuels/templates/manuels/base.html b/manuels/templates/manuels/base.html index d0123a2..68ca66d 100644 --- a/manuels/templates/manuels/base.html +++ b/manuels/templates/manuels/base.html @@ -43,8 +43,7 @@ {% block end_js %} {% endblock %} -