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:
- 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]
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.
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):
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")

View file

@ -1,74 +1,77 @@
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) {
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 = '';
})
.then(function (data) {
isbn.classList.remove("is-invalid");
isbn.classList.add("is-valid");
feedback.style.display = "none";
feedback.textContent = "";
title.value = data.title;
title.classList.add('is-valid');
title.classList.add("is-valid");
authors.value = data.authors;
authors.classList.add('is-valid');
authors.classList.add("is-valid");
year.value = data.year;
year.classList.add('is-valid');
year.classList.add("is-valid");
price.value = data.price;
price.classList.add('is-valid');
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) {
for (var option of document.querySelector("#id_editor").children) {
if (editorValue === "" && option.firstChild.data.toLowerCase().indexOf("autre") !== -1) {
editorValue = option.value;
editorIsOther = true;
}
@ -79,11 +82,11 @@ document.addEventListener("DOMContentLoaded", function (event) {
}
}
editor.value = editorValue;
editor.classList.add('is-valid');
editor.classList.add("is-valid");
if (editorIsOther) {
otherEditor.value = data.editor;
otherEditor.classList.add('is-valid');
otherEditor.classList.add("is-valid");
}
enableFields();
@ -92,11 +95,12 @@ document.addEventListener("DOMContentLoaded", function (event) {
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';
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();
});

View file

@ -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);
});

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