pre-commit

This commit is contained in:
Gabriel Augendre 2022-06-14 16:53:39 +02:00
parent 0f503847c5
commit bf76cd227a
18 changed files with 903 additions and 629 deletions

51
.eslintrc Normal file
View file

@ -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"
}
}

View file

@ -1,20 +1,18 @@
exclude: \.min\.(js|css)$|/generated/ exclude: (\.min\.(js|css)(\.map)?$|/vendor/)
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0 rev: v4.1.0
hooks: hooks:
- id: check-ast - id: check-ast
types: [python]
- id: check-json - id: check-json
types: [json]
- id: check-toml - id: check-toml
types: [toml]
- id: check-xml - id: check-xml
types: [xml]
- id: check-yaml - id: check-yaml
types: [yaml] args: [--allow-multiple-documents]
- id: end-of-file-fixer - id: end-of-file-fixer
- id: check-merge-conflict - id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
- id: pretty-format-json - id: pretty-format-json
args: args:
- --autofix - --autofix
@ -23,12 +21,57 @@ repos:
args: args:
- --markdown-linebreak-ext=md - --markdown-linebreak-ext=md
- repo: https://github.com/timothycrosley/isort - repo: https://github.com/timothycrosley/isort
rev: 5.8.0 rev: 5.10.1
hooks: hooks:
- id: isort - id: isort
types: [python] args:
- --profile=black
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 20.8b1 rev: 22.1.0
hooks: hooks:
- id: black - id: black
types: [python] 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

5
.prettierrc Normal file
View file

@ -0,0 +1,5 @@
{
"tabWidth": 4,
"printWidth": 120,
"endOfLine": "auto"
}

View file

@ -22,4 +22,3 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE. OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org> For more information, please refer to <https://unlicense.org>

View file

@ -93,7 +93,7 @@ class LevelAdmin(ExportMixin, admin.ModelAdmin):
def get_queryset(self, request): def get_queryset(self, request):
return ( return (
super(LevelAdmin, self) super()
.get_queryset(request) .get_queryset(request)
.prefetch_related(Prefetch("book_set", to_attr="prefetched_books")) .prefetch_related(Prefetch("book_set", to_attr="prefetched_books"))
) )
@ -230,9 +230,7 @@ class BookAdmin(ExportMixin, admin.ModelAdmin):
def get_queryset(self, request): def get_queryset(self, request):
return ( return (
super(BookAdmin, self) super().get_queryset(request).select_related("editor", "level", "teacher")
.get_queryset(request)
.select_related("editor", "level", "teacher")
) )
def update_with_decitre(self, request, queryset): def update_with_decitre(self, request, queryset):
@ -298,8 +296,4 @@ class SuppliesRequirementAdmin(ExportMixin, admin.ModelAdmin):
list_filter = ["done", "teacher", "level"] list_filter = ["done", "teacher", "level"]
def get_queryset(self, request): def get_queryset(self, request):
return ( return super().get_queryset(request).select_related("level", "teacher")
super(SuppliesRequirementAdmin, self)
.get_queryset(request)
.select_related("level", "teacher")
)

View file

@ -1,74 +1,77 @@
document.addEventListener("DOMContentLoaded", function (event) { document.addEventListener("DOMContentLoaded", function () {
$(function () { $(function () {
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
}); });
var isbnButton = document.querySelector('#id_isbn_button'); var isbnButton = document.querySelector("#id_isbn_button");
var isbn = document.querySelector('#id_isbn'); var isbn = document.querySelector("#id_isbn");
var title = document.querySelector('#id_title'); var title = document.querySelector("#id_title");
var authors = document.querySelector('#id_authors'); var authors = document.querySelector("#id_authors");
var year = document.querySelector('#id_publication_year'); var year = document.querySelector("#id_publication_year");
var price = document.querySelector('#id_price'); var price = document.querySelector("#id_price");
var editor = document.querySelector('#id_editor'); var editor = document.querySelector("#id_editor");
var otherEditor = document.querySelector('#id_other_editor'); var otherEditor = document.querySelector("#id_other_editor");
var spinner = document.querySelector('#id_isbn_spinner'); var spinner = document.querySelector("#id_isbn_spinner");
var feedback = document.querySelector('#id_isbn_invalid_feedback'); var feedback = document.querySelector("#id_isbn_invalid_feedback");
function enableFields() { function enableFields() {
isbn.removeAttribute('disabled'); isbn.removeAttribute("disabled");
isbnButton.removeAttribute('disabled'); isbnButton.removeAttribute("disabled");
document.querySelector('#id_title').removeAttribute('disabled'); document.querySelector("#id_title").removeAttribute("disabled");
authors.removeAttribute('disabled'); authors.removeAttribute("disabled");
year.removeAttribute('disabled'); year.removeAttribute("disabled");
price.removeAttribute('disabled'); price.removeAttribute("disabled");
editor.removeAttribute('disabled'); editor.removeAttribute("disabled");
otherEditor.removeAttribute('disabled'); otherEditor.removeAttribute("disabled");
spinner.setAttribute('hidden', 'hidden'); spinner.setAttribute("hidden", "hidden");
} }
function disableFields() { function disableFields() {
isbn.setAttribute('disabled', 'disabled'); isbn.setAttribute("disabled", "disabled");
isbnButton.setAttribute('disabled', 'disabled'); isbnButton.setAttribute("disabled", "disabled");
title.setAttribute('disabled', 'disabled'); title.setAttribute("disabled", "disabled");
authors.setAttribute('disabled', 'disabled'); authors.setAttribute("disabled", "disabled");
year.setAttribute('disabled', 'disabled'); year.setAttribute("disabled", "disabled");
price.setAttribute('disabled', 'disabled'); price.setAttribute("disabled", "disabled");
editor.setAttribute('disabled', 'disabled'); editor.setAttribute("disabled", "disabled");
otherEditor.setAttribute('disabled', 'disabled'); otherEditor.setAttribute("disabled", "disabled");
spinner.removeAttribute('hidden'); spinner.removeAttribute("hidden");
} }
isbnButton.addEventListener('click', function (event) { isbnButton.addEventListener("click", function () {
if (!isbn.value) { if (!isbn.value) {
return; return;
} }
disableFields(); disableFields();
fetch("/isbn_api/" + isbn.value).then(function (data) { fetch("/isbn_api/" + isbn.value)
.then(function (data) {
if (!data.ok) { if (!data.ok) {
throw Error("Erreur dans la récupération des données"); throw Error("Erreur dans la récupération des données");
} }
return data.json(); return data.json();
}).then(function (data) { })
isbn.classList.remove('is-invalid'); .then(function (data) {
isbn.classList.add('is-valid'); isbn.classList.remove("is-invalid");
feedback.style.display = 'none'; isbn.classList.add("is-valid");
feedback.textContent = ''; feedback.style.display = "none";
feedback.textContent = "";
title.value = data.title; title.value = data.title;
title.classList.add('is-valid'); title.classList.add("is-valid");
authors.value = data.authors; authors.value = data.authors;
authors.classList.add('is-valid'); authors.classList.add("is-valid");
year.value = data.year; year.value = data.year;
year.classList.add('is-valid'); year.classList.add("is-valid");
price.value = data.price; price.value = data.price;
price.classList.add('is-valid'); price.classList.add("is-valid");
var editorValue = ""; var editorValue = "";
var editorIsOther = false; var editorIsOther = false;
if (data.editor) { if (data.editor) {
for (var option of document.querySelector('#id_editor').children) { for (var option of document.querySelector("#id_editor").children) {
if (editorValue === "" && option.firstChild.data.toLowerCase().indexOf('autre') !== -1) { if (editorValue === "" && option.firstChild.data.toLowerCase().indexOf("autre") !== -1) {
editorValue = option.value; editorValue = option.value;
editorIsOther = true; editorIsOther = true;
} }
@ -79,11 +82,11 @@ document.addEventListener("DOMContentLoaded", function (event) {
} }
} }
editor.value = editorValue; editor.value = editorValue;
editor.classList.add('is-valid'); editor.classList.add("is-valid");
if (editorIsOther) { if (editorIsOther) {
otherEditor.value = data.editor; otherEditor.value = data.editor;
otherEditor.classList.add('is-valid'); otherEditor.classList.add("is-valid");
} }
enableFields(); enableFields();
@ -92,11 +95,12 @@ document.addEventListener("DOMContentLoaded", function (event) {
var event = document.createEvent("HTMLEvents"); var event = document.createEvent("HTMLEvents");
event.initEvent("change", true, true); event.initEvent("change", true, true);
event.eventName = "change"; event.eventName = "change";
document.querySelector('#id_editor').dispatchEvent(event); document.querySelector("#id_editor").dispatchEvent(event);
}).catch(function(error) { })
isbn.classList.add('is-invalid'); .catch(function (error) {
isbn.classList.remove('is-valid'); isbn.classList.add("is-invalid");
feedback.style.display = 'block'; isbn.classList.remove("is-valid");
feedback.style.display = "block";
feedback.textContent = error; feedback.textContent = error;
enableFields(); enableFields();
}); });

View file

@ -1,79 +1,78 @@
document.addEventListener("DOMContentLoaded", function (event) { document.addEventListener("DOMContentLoaded", function () {
var selectors = [ var selectors = [
{ {
id: "#id_no_book", id: "#id_no_book",
value: "PAS DE LIVRE POUR CETTE CLASSE" value: "PAS DE LIVRE POUR CETTE CLASSE",
}, },
{ {
id: "#id_see_later", 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); var _selector = document.querySelector(selector.id);
if (_selector === null) return; if (_selector === null) {
return;
}
var data = { var data = {
title: document.querySelector('#id_title').value, title: document.querySelector("#id_title").value,
authors: document.querySelector('#id_authors').value, authors: document.querySelector("#id_authors").value,
publicationYear: document.querySelector('#id_publication_year').value, publicationYear: document.querySelector("#id_publication_year").value,
isbn: document.querySelector('#id_isbn').value, isbn: document.querySelector("#id_isbn").value,
price: document.querySelector('#id_price').value, price: document.querySelector("#id_price").value,
editor: document.querySelector('#id_editor').value, editor: document.querySelector("#id_editor").value,
previouslyAcquired: document.querySelector('#id_previously_acquired').value, previouslyAcquired: document.querySelector("#id_previously_acquired").value,
}; };
_selector.addEventListener('change', function (event) { _selector.addEventListener("change", function () {
if (_selector.checked) { if (_selector.checked) {
data = { data = {
title: document.querySelector('#id_title').value, title: document.querySelector("#id_title").value,
authors: document.querySelector('#id_authors').value, authors: document.querySelector("#id_authors").value,
publicationYear: document.querySelector('#id_publication_year').value, publicationYear: document.querySelector("#id_publication_year").value,
isbn: document.querySelector('#id_isbn').value, isbn: document.querySelector("#id_isbn").value,
price: document.querySelector('#id_price').value, price: document.querySelector("#id_price").value,
editor: document.querySelector('#id_editor').value, editor: document.querySelector("#id_editor").value,
previouslyAcquired: document.querySelector('#id_previously_acquired').value, previouslyAcquired: document.querySelector("#id_previously_acquired").value,
}; };
document.querySelector('#id_title').value = selector.value; document.querySelector("#id_title").value = selector.value;
document.querySelector('#id_authors').value = "N/A"; document.querySelector("#id_authors").value = "N/A";
document.querySelector('#id_publication_year').value = 1900; document.querySelector("#id_publication_year").value = 1900;
document.querySelector('#id_isbn').value = "0000000000"; document.querySelector("#id_isbn").value = "0000000000";
document.querySelector('#id_price').value = 0; document.querySelector("#id_price").value = 0;
document.querySelector('#id_previously_acquired').value = "False"; document.querySelector("#id_previously_acquired").value = "False";
var editorValue = null; 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 !== "") { if (editorValue === null && option.value !== "") {
editorValue = option.value; editorValue = option.value;
} }
if (option.firstChild.data.toLowerCase().indexOf('autre') !== -1) { if (option.firstChild.data.toLowerCase().indexOf("autre") !== -1) {
editorValue = option.value; editorValue = option.value;
} }
} }
document.querySelector('#id_editor').value = editorValue; document.querySelector("#id_editor").value = editorValue;
} else { } else {
document.querySelector('#id_title').value = data.title; document.querySelector("#id_title").value = data.title;
document.querySelector('#id_authors').value = data.authors; document.querySelector("#id_authors").value = data.authors;
document.querySelector('#id_editor').value = data.editor; document.querySelector("#id_editor").value = data.editor;
document.querySelector('#id_publication_year').value = data.publicationYear; document.querySelector("#id_publication_year").value = data.publicationYear;
document.querySelector('#id_isbn').value = data.isbn; document.querySelector("#id_isbn").value = data.isbn;
document.querySelector('#id_price').value = data.price; document.querySelector("#id_price").value = data.price;
document.querySelector('#id_previously_acquired').value = data.previouslyAcquired; document.querySelector("#id_previously_acquired").value = data.previouslyAcquired;
} }
}); });
}); });
function toggleOtherEditorDisplay() { function toggleOtherEditorDisplay() {
var editor = document.querySelector('#id_editor'); var editor = document.querySelector("#id_editor");
var otherEditor = document.querySelector('#id_other_editor').parentElement; var otherEditor = document.querySelector("#id_other_editor").parentElement;
if (editor.options[editor.selectedIndex].text.toLowerCase().indexOf('autre') !== -1) { if (editor.options[editor.selectedIndex].text.toLowerCase().indexOf("autre") !== -1) {
otherEditor.style.display = 'block'; otherEditor.style.display = "block";
} } else {
else { otherEditor.style.display = "none";
otherEditor.style.display = 'none';
} }
} }
toggleOtherEditorDisplay(); toggleOtherEditorDisplay();
document.querySelector('#id_editor').addEventListener('change', toggleOtherEditorDisplay); document.querySelector("#id_editor").addEventListener("change", toggleOtherEditorDisplay);
}); });

777
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,7 @@ authors = ["Gabriel Augendre <gabriel@augendre.info>"]
license = "MIT" license = "MIT"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.9" python = "^3.10"
Django = "^3.2.4" Django = "^3.2.4"
django-bootstrap4 = "^3.0.1" django-bootstrap4 = "^3.0.1"
gunicorn = "^20.1.0" gunicorn = "^20.1.0"
@ -32,12 +32,6 @@ vcrpy = "^4.1.1"
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api" build-backend = "poetry.core.masonry.api"
[tool.black]
target-version = ['py38']
[tool.isort]
profile = "black"
[tool.pytest.ini_options] [tool.pytest.ini_options]
addopts = "--html=pytest_result/pytest.html --color=yes" addopts = "--html=pytest_result/pytest.html --color=yes"
minversion = "6.0" minversion = "6.0"