From bf76cd227a9e990422f10583f5c94c61d1d8deb3 Mon Sep 17 00:00:00 2001
From: Gabriel Augendre
Date: Tue, 14 Jun 2022 16:53:39 +0200
Subject: [PATCH] pre-commit
---
.eslintrc | 51 ++
.pre-commit-config.yaml | 67 +-
.prettierrc | 5 +
LICENSE | 1 -
README.md | 2 +-
manuels/admin.py | 12 +-
manuels/static/manuels/fetch-isbn.js | 164 ++--
manuels/static/manuels/no_book.js | 91 +-
manuels/templates/404.html | 2 +-
manuels/templates/manuels/add_book.html | 18 +-
manuels/templates/manuels/add_supplies.html | 8 +-
manuels/templates/manuels/base.html | 154 ++--
.../templates/manuels/confirm_teacher.html | 2 +-
.../manuels/emails_confirmation.html | 8 +-
manuels/templates/manuels/emails_link.html | 14 +-
.../manuels/list_books_supplies.html | 148 ++--
poetry.lock | 777 +++++++++++-------
pyproject.toml | 8 +-
18 files changed, 903 insertions(+), 629 deletions(-)
create mode 100644 .eslintrc
create mode 100644 .prettierrc
diff --git a/.eslintrc b/.eslintrc
new file mode 100644
index 0000000..516cec4
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,51 @@
+{
+ "env": {
+ "browser": true,
+ "es6": true,
+ "jquery": true
+ },
+ "extends": [
+ "eslint:recommended"
+ ],
+ "ignorePatterns": ["dist/", "node_modules/"],
+ "rules": {
+ "block-scoped-var": "error",
+ "consistent-return": "error",
+ "curly": "error",
+ "default-case": "error",
+ "default-param-last": ["error"],
+ "dot-notation": "error",
+ "eqeqeq": "error",
+ "guard-for-in": "error",
+ "max-classes-per-file": "error",
+ "no-alert": "error",
+ "no-caller": "error",
+ "no-else-return": "error",
+ "no-empty-function": "error",
+ "no-floating-decimal": "error",
+ "no-implicit-coercion": "error",
+ "no-multi-spaces": "error",
+ "no-multi-str": "error",
+ "no-param-reassign": "error",
+ "no-return-assign": "error",
+ "no-return-await": "error",
+ "no-self-compare": "error",
+ "no-throw-literal": "error",
+ "no-useless-concat": "error",
+ "radix": ["error", "as-needed"],
+ "require-await": "error",
+ "yoda": "error",
+ "no-shadow": "off",
+ "prefer-destructuring": ["error", { "array": false, "object": true }],
+ "padding-line-between-statements": [
+ "error",
+ { "blankLine": "always", "prev": "import", "next": "export" },
+ { "blankLine": "always", "prev": "export", "next": "export" },
+ { "blankLine": "always", "prev": "*", "next": "return" }
+ ]
+ },
+ "parserOptions": {
+ "ecmaVersion": 6,
+ "sourceType": "module"
+ }
+}
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index ee3b073..f188b71 100755
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,20 +1,18 @@
-exclude: \.min\.(js|css)$|/generated/
+exclude: (\.min\.(js|css)(\.map)?$|/vendor/)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v3.4.0
+ rev: v4.1.0
hooks:
- id: check-ast
- types: [python]
- id: check-json
- types: [json]
- id: check-toml
- types: [toml]
- id: check-xml
- types: [xml]
- id: check-yaml
- types: [yaml]
+ args: [--allow-multiple-documents]
- id: end-of-file-fixer
- id: check-merge-conflict
+ - id: debug-statements
+ - id: detect-private-key
- id: pretty-format-json
args:
- --autofix
@@ -23,12 +21,57 @@ repos:
args:
- --markdown-linebreak-ext=md
- repo: https://github.com/timothycrosley/isort
- rev: 5.8.0
+ rev: 5.10.1
hooks:
- id: isort
- types: [python]
+ args:
+ - --profile=black
- repo: https://github.com/psf/black
- rev: 20.8b1
+ rev: 22.1.0
hooks:
- - id: black
- types: [python]
+ - id: black
+ args:
+ - --target-version=py310
+ - repo: https://github.com/asottile/pyupgrade
+ rev: v2.31.0
+ hooks:
+ - id: pyupgrade
+ args:
+ - --py310-plus
+ - repo: https://github.com/adamchainz/django-upgrade
+ rev: 1.4.0
+ hooks:
+ - id: django-upgrade
+ args: [--target-version, "4.0"]
+ - repo: https://github.com/rtts/djhtml
+ rev: v1.5.0
+ hooks:
+ - id: djhtml
+ - repo: https://github.com/flakeheaven/flakeheaven
+ rev: 0.11.0
+ hooks:
+ - id: flakeheaven
+ additional_dependencies:
+ - flake8-annotations-complexity
+ - flake8-builtins
+ - flake8-bugbear
+ - flake8-comprehensions
+ - flake8-eradicate
+ - flake8-noqa
+ - flake8-pytest-style
+ - flake8-pyi
+ - wemake-python-styleguide
+ - repo: https://github.com/pre-commit/mirrors-prettier
+ rev: v2.5.1
+ hooks:
+ - id: prettier
+ types_or: [javascript, css]
+ - repo: https://github.com/pre-commit/mirrors-eslint
+ rev: v8.9.0
+ hooks:
+ - id: eslint
+ args: [--fix]
+ types_or: [javascript, css]
+ additional_dependencies:
+ - eslint@^7.29.0
+ - eslint-config-prettier@^8.3.0
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..d6245f5
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,5 @@
+{
+ "tabWidth": 4,
+ "printWidth": 120,
+ "endOfLine": "auto"
+}
diff --git a/LICENSE b/LICENSE
index 1e9858b..fdddb29 100644
--- a/LICENSE
+++ b/LICENSE
@@ -22,4 +22,3 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to
-
diff --git a/README.md b/README.md
index 7b31b72..8e1db80 100644
--- a/README.md
+++ b/README.md
@@ -21,4 +21,4 @@ You may need to upgrade Python since Heroku tends to deprecate old patch version
In this case, edit `runtime.txt`.
# Reuse
-If you do reuse my work, please consider linking back to this repository 🙂
\ No newline at end of file
+If you do reuse my work, please consider linking back to this repository 🙂
diff --git a/manuels/admin.py b/manuels/admin.py
index b926226..6b572da 100644
--- a/manuels/admin.py
+++ b/manuels/admin.py
@@ -93,7 +93,7 @@ class LevelAdmin(ExportMixin, admin.ModelAdmin):
def get_queryset(self, request):
return (
- super(LevelAdmin, self)
+ super()
.get_queryset(request)
.prefetch_related(Prefetch("book_set", to_attr="prefetched_books"))
)
@@ -230,9 +230,7 @@ class BookAdmin(ExportMixin, admin.ModelAdmin):
def get_queryset(self, request):
return (
- super(BookAdmin, self)
- .get_queryset(request)
- .select_related("editor", "level", "teacher")
+ super().get_queryset(request).select_related("editor", "level", "teacher")
)
def update_with_decitre(self, request, queryset):
@@ -298,8 +296,4 @@ class SuppliesRequirementAdmin(ExportMixin, admin.ModelAdmin):
list_filter = ["done", "teacher", "level"]
def get_queryset(self, request):
- return (
- super(SuppliesRequirementAdmin, self)
- .get_queryset(request)
- .select_related("level", "teacher")
- )
+ return super().get_queryset(request).select_related("level", "teacher")
diff --git a/manuels/static/manuels/fetch-isbn.js b/manuels/static/manuels/fetch-isbn.js
index f7e8ce0..7dd0e8a 100644
--- a/manuels/static/manuels/fetch-isbn.js
+++ b/manuels/static/manuels/fetch-isbn.js
@@ -1,104 +1,108 @@
-document.addEventListener("DOMContentLoaded", function (event) {
+document.addEventListener("DOMContentLoaded", function () {
$(function () {
$('[data-toggle="tooltip"]').tooltip();
});
- var isbnButton = document.querySelector('#id_isbn_button');
- var isbn = document.querySelector('#id_isbn');
- var title = document.querySelector('#id_title');
- var authors = document.querySelector('#id_authors');
- var year = document.querySelector('#id_publication_year');
- var price = document.querySelector('#id_price');
- var editor = document.querySelector('#id_editor');
- var otherEditor = document.querySelector('#id_other_editor');
- var spinner = document.querySelector('#id_isbn_spinner');
- var feedback = document.querySelector('#id_isbn_invalid_feedback');
+ var isbnButton = document.querySelector("#id_isbn_button");
+ var isbn = document.querySelector("#id_isbn");
+ var title = document.querySelector("#id_title");
+ var authors = document.querySelector("#id_authors");
+ var year = document.querySelector("#id_publication_year");
+ var price = document.querySelector("#id_price");
+ var editor = document.querySelector("#id_editor");
+ var otherEditor = document.querySelector("#id_other_editor");
+ var spinner = document.querySelector("#id_isbn_spinner");
+ var feedback = document.querySelector("#id_isbn_invalid_feedback");
function enableFields() {
- isbn.removeAttribute('disabled');
- isbnButton.removeAttribute('disabled');
- document.querySelector('#id_title').removeAttribute('disabled');
- authors.removeAttribute('disabled');
- year.removeAttribute('disabled');
- price.removeAttribute('disabled');
- editor.removeAttribute('disabled');
- otherEditor.removeAttribute('disabled');
- spinner.setAttribute('hidden', 'hidden');
+ isbn.removeAttribute("disabled");
+ isbnButton.removeAttribute("disabled");
+ document.querySelector("#id_title").removeAttribute("disabled");
+ authors.removeAttribute("disabled");
+ year.removeAttribute("disabled");
+ price.removeAttribute("disabled");
+ editor.removeAttribute("disabled");
+ otherEditor.removeAttribute("disabled");
+ spinner.setAttribute("hidden", "hidden");
}
function disableFields() {
- isbn.setAttribute('disabled', 'disabled');
- isbnButton.setAttribute('disabled', 'disabled');
- title.setAttribute('disabled', 'disabled');
- authors.setAttribute('disabled', 'disabled');
- year.setAttribute('disabled', 'disabled');
- price.setAttribute('disabled', 'disabled');
- editor.setAttribute('disabled', 'disabled');
- otherEditor.setAttribute('disabled', 'disabled');
- spinner.removeAttribute('hidden');
+ isbn.setAttribute("disabled", "disabled");
+ isbnButton.setAttribute("disabled", "disabled");
+ title.setAttribute("disabled", "disabled");
+ authors.setAttribute("disabled", "disabled");
+ year.setAttribute("disabled", "disabled");
+ price.setAttribute("disabled", "disabled");
+ editor.setAttribute("disabled", "disabled");
+ otherEditor.setAttribute("disabled", "disabled");
+ spinner.removeAttribute("hidden");
}
- isbnButton.addEventListener('click', function (event) {
+ isbnButton.addEventListener("click", function () {
if (!isbn.value) {
return;
}
disableFields();
- fetch("/isbn_api/" + isbn.value).then(function (data) {
- if (!data.ok) {
- throw Error("Erreur dans la récupération des données");
- }
- return data.json();
- }).then(function (data) {
- isbn.classList.remove('is-invalid');
- isbn.classList.add('is-valid');
- feedback.style.display = 'none';
- feedback.textContent = '';
+ fetch("/isbn_api/" + isbn.value)
+ .then(function (data) {
+ if (!data.ok) {
+ throw Error("Erreur dans la récupération des données");
+ }
- title.value = data.title;
- title.classList.add('is-valid');
- authors.value = data.authors;
- authors.classList.add('is-valid');
- year.value = data.year;
- year.classList.add('is-valid');
- price.value = data.price;
- price.classList.add('is-valid');
+ return data.json();
+ })
+ .then(function (data) {
+ isbn.classList.remove("is-invalid");
+ isbn.classList.add("is-valid");
+ feedback.style.display = "none";
+ feedback.textContent = "";
- var editorValue = "";
- var editorIsOther = false;
- if (data.editor) {
- 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;
+ title.value = data.title;
+ title.classList.add("is-valid");
+ authors.value = data.authors;
+ authors.classList.add("is-valid");
+ year.value = data.year;
+ year.classList.add("is-valid");
+ price.value = data.price;
+ price.classList.add("is-valid");
+
+ var editorValue = "";
+ var editorIsOther = false;
+ if (data.editor) {
+ 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;
+ }
}
}
- }
- editor.value = editorValue;
- editor.classList.add('is-valid');
+ editor.value = editorValue;
+ editor.classList.add("is-valid");
- if (editorIsOther) {
- otherEditor.value = data.editor;
- otherEditor.classList.add('is-valid');
- }
- enableFields();
+ if (editorIsOther) {
+ otherEditor.value = data.editor;
+ otherEditor.classList.add("is-valid");
+ }
+ enableFields();
- // The event propagation must be done after the fields have been re-enabled
- // because a change event can't be propagated to a field that's disabled.
- var event = document.createEvent("HTMLEvents");
- event.initEvent("change", true, true);
- event.eventName = "change";
- document.querySelector('#id_editor').dispatchEvent(event);
- }).catch(function(error) {
- isbn.classList.add('is-invalid');
- isbn.classList.remove('is-valid');
- feedback.style.display = 'block';
- feedback.textContent = error;
- enableFields();
- });
+ // The event propagation must be done after the fields have been re-enabled
+ // because a change event can't be propagated to a field that's disabled.
+ var event = document.createEvent("HTMLEvents");
+ event.initEvent("change", true, true);
+ event.eventName = "change";
+ document.querySelector("#id_editor").dispatchEvent(event);
+ })
+ .catch(function (error) {
+ isbn.classList.add("is-invalid");
+ isbn.classList.remove("is-valid");
+ feedback.style.display = "block";
+ feedback.textContent = error;
+ enableFields();
+ });
});
});
diff --git a/manuels/static/manuels/no_book.js b/manuels/static/manuels/no_book.js
index 9bf1925..1154bfb 100644
--- a/manuels/static/manuels/no_book.js
+++ b/manuels/static/manuels/no_book.js
@@ -1,79 +1,78 @@
-document.addEventListener("DOMContentLoaded", function (event) {
+document.addEventListener("DOMContentLoaded", function () {
var selectors = [
{
id: "#id_no_book",
- value: "PAS DE LIVRE POUR CETTE CLASSE"
+ value: "PAS DE LIVRE POUR CETTE CLASSE",
},
{
id: "#id_see_later",
- value: "VOIR À LA RENTRÉE"
+ value: "VOIR À LA RENTRÉE",
},
];
- selectors.forEach(function (selector, index, array) {
+ selectors.forEach(function (selector) {
var _selector = document.querySelector(selector.id);
- if (_selector === null) return;
+ if (_selector === null) {
+ return;
+ }
var data = {
- title: document.querySelector('#id_title').value,
- authors: document.querySelector('#id_authors').value,
- publicationYear: document.querySelector('#id_publication_year').value,
- isbn: document.querySelector('#id_isbn').value,
- price: document.querySelector('#id_price').value,
- editor: document.querySelector('#id_editor').value,
- previouslyAcquired: document.querySelector('#id_previously_acquired').value,
+ title: document.querySelector("#id_title").value,
+ authors: document.querySelector("#id_authors").value,
+ publicationYear: document.querySelector("#id_publication_year").value,
+ isbn: document.querySelector("#id_isbn").value,
+ price: document.querySelector("#id_price").value,
+ editor: document.querySelector("#id_editor").value,
+ previouslyAcquired: document.querySelector("#id_previously_acquired").value,
};
- _selector.addEventListener('change', function (event) {
+ _selector.addEventListener("change", function () {
if (_selector.checked) {
data = {
- title: document.querySelector('#id_title').value,
- authors: document.querySelector('#id_authors').value,
- publicationYear: document.querySelector('#id_publication_year').value,
- isbn: document.querySelector('#id_isbn').value,
- price: document.querySelector('#id_price').value,
- editor: document.querySelector('#id_editor').value,
- previouslyAcquired: document.querySelector('#id_previously_acquired').value,
+ title: document.querySelector("#id_title").value,
+ authors: document.querySelector("#id_authors").value,
+ publicationYear: document.querySelector("#id_publication_year").value,
+ isbn: document.querySelector("#id_isbn").value,
+ price: document.querySelector("#id_price").value,
+ editor: document.querySelector("#id_editor").value,
+ previouslyAcquired: document.querySelector("#id_previously_acquired").value,
};
- document.querySelector('#id_title').value = selector.value;
- document.querySelector('#id_authors').value = "N/A";
- document.querySelector('#id_publication_year').value = 1900;
- document.querySelector('#id_isbn').value = "0000000000";
- document.querySelector('#id_price').value = 0;
- document.querySelector('#id_previously_acquired').value = "False";
+ document.querySelector("#id_title").value = selector.value;
+ document.querySelector("#id_authors").value = "N/A";
+ document.querySelector("#id_publication_year").value = 1900;
+ document.querySelector("#id_isbn").value = "0000000000";
+ document.querySelector("#id_price").value = 0;
+ document.querySelector("#id_previously_acquired").value = "False";
var editorValue = null;
- for (var option of document.querySelector('#id_editor').children) {
+ for (var option of document.querySelector("#id_editor").children) {
if (editorValue === null && option.value !== "") {
editorValue = option.value;
}
- if (option.firstChild.data.toLowerCase().indexOf('autre') !== -1) {
+ if (option.firstChild.data.toLowerCase().indexOf("autre") !== -1) {
editorValue = option.value;
}
}
- document.querySelector('#id_editor').value = editorValue;
+ document.querySelector("#id_editor").value = editorValue;
} else {
- document.querySelector('#id_title').value = data.title;
- document.querySelector('#id_authors').value = data.authors;
- document.querySelector('#id_editor').value = data.editor;
- document.querySelector('#id_publication_year').value = data.publicationYear;
- document.querySelector('#id_isbn').value = data.isbn;
- document.querySelector('#id_price').value = data.price;
- document.querySelector('#id_previously_acquired').value = data.previouslyAcquired;
+ document.querySelector("#id_title").value = data.title;
+ document.querySelector("#id_authors").value = data.authors;
+ document.querySelector("#id_editor").value = data.editor;
+ document.querySelector("#id_publication_year").value = data.publicationYear;
+ document.querySelector("#id_isbn").value = data.isbn;
+ document.querySelector("#id_price").value = data.price;
+ document.querySelector("#id_previously_acquired").value = data.previouslyAcquired;
}
});
});
-
function toggleOtherEditorDisplay() {
- var editor = document.querySelector('#id_editor');
- var otherEditor = document.querySelector('#id_other_editor').parentElement;
+ var editor = document.querySelector("#id_editor");
+ var otherEditor = document.querySelector("#id_other_editor").parentElement;
- if (editor.options[editor.selectedIndex].text.toLowerCase().indexOf('autre') !== -1) {
- otherEditor.style.display = 'block';
- }
- else {
- otherEditor.style.display = 'none';
+ if (editor.options[editor.selectedIndex].text.toLowerCase().indexOf("autre") !== -1) {
+ otherEditor.style.display = "block";
+ } else {
+ otherEditor.style.display = "none";
}
}
toggleOtherEditorDisplay();
- document.querySelector('#id_editor').addEventListener('change', toggleOtherEditorDisplay);
-
+ document.querySelector("#id_editor").addEventListener("change", toggleOtherEditorDisplay);
});
diff --git a/manuels/templates/404.html b/manuels/templates/404.html
index 8aaf925..d243806 100644
--- a/manuels/templates/404.html
+++ b/manuels/templates/404.html
@@ -19,7 +19,7 @@
Vous avez peut-être déjà rencontré ce type d'erreur (peut-être même sur ce site) sans
forcément comprendre ce qu'il signifie.
Voici donc un extrait de la page Wikipedia
- traitant spécifiquement de l'erreur 404
+ traitant spécifiquement de l'erreur 404
diff --git a/manuels/templates/manuels/add_book.html b/manuels/templates/manuels/add_book.html
index c324c50..a1febf8 100644
--- a/manuels/templates/manuels/add_book.html
+++ b/manuels/templates/manuels/add_book.html
@@ -31,7 +31,7 @@