From 8bf7d01939404af22fd22e4774cb1a1a00a61558 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:01:49 +0000 Subject: [PATCH] style: format code with Black, isort and Ruff Formatter This commit fixes the style issues introduced in a2f0e0e according to the output from Black, isort and Ruff Formatter. Details: None --- django_ninja_crudl/crudl.py | 5 +- django_ninja_crudl/errors/schemas.py | 16 +- .../app/migrations/0001_initial.py | 141 +++++++++++++----- tests/test_django/app/models.py | 2 +- tests/test_django/wsgi.py | 2 +- 5 files changed, 123 insertions(+), 43 deletions(-) diff --git a/django_ninja_crudl/crudl.py b/django_ninja_crudl/crudl.py index 4522b48..014b39e 100644 --- a/django_ninja_crudl/crudl.py +++ b/django_ninja_crudl/crudl.py @@ -5,6 +5,8 @@ from typing import TYPE_CHECKING, Any, ClassVar, Literal, cast from uuid import UUID +from django2pydantic import Infer, ModelFields +from django2pydantic.schema import Schema from django.core.exceptions import ValidationError from django.db import IntegrityError, models, transaction from django.db.models import ( @@ -30,8 +32,6 @@ ) from pydantic import BaseModel -from django2pydantic import Infer, ModelFields -from django2pydantic.schema import Schema from django_ninja_crudl.base import CrudlBaseMixin from django_ninja_crudl.errors.openapi_extras import ( not_authorized_openapi_extra, @@ -126,7 +126,6 @@ def __new__(cls, name: str, bases: tuple[type, ...], dct: dict[str, Any]) -> typ model_class: type[Model] = meta.model_class - api_meta = getattr(model_class, "CrudlApiMeta", meta) if api_meta is None: msg = f"CrudlApiMeta is required for model '{name}' or in the model itself." diff --git a/django_ninja_crudl/errors/schemas.py b/django_ninja_crudl/errors/schemas.py index f9ea43b..061f1bb 100644 --- a/django_ninja_crudl/errors/schemas.py +++ b/django_ninja_crudl/errors/schemas.py @@ -38,15 +38,21 @@ class ResourceNotFound404Schema(ErrorSchema): """The default resource not found schema.""" code: str = "ResourceNotFound" - message: str = "The requested resource was not found or you do not have permission to access it." - user_friendly_message: str = "The requested resource was not found or you do not have permission to access it." + message: str = ( + "The requested resource was not found or you do not have permission to access it." + ) + user_friendly_message: str = ( + "The requested resource was not found or you do not have permission to access it." + ) class Conflict409Schema(ErrorSchema): """The default conflict schema.""" code: str = "Conflict" - message: str = "The request could not be completed due to a conflict with the current state of the resource." + message: str = ( + "The request could not be completed due to a conflict with the current state of the resource." + ) class UnprocessableEntity422Schema(ErrorSchema): @@ -73,7 +79,9 @@ class ServiceUnavailable503Schema(ErrorSchema): """The default service unavailable schema.""" code: str = "ServiceUnavailable" - message: str = "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server." + message: str = ( + "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server." + ) user_friendly_message: str = ( "The server is currently unavailable. Please try again later." ) diff --git a/tests/test_django/app/migrations/0001_initial.py b/tests/test_django/app/migrations/0001_initial.py index fa9d136..e78e6dc 100644 --- a/tests/test_django/app/migrations/0001_initial.py +++ b/tests/test_django/app/migrations/0001_initial.py @@ -6,7 +6,6 @@ class Migration(migrations.Migration): - initial = True dependencies = [ @@ -15,66 +14,140 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='Author', + name="Author", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), - ('birth_date', models.DateField()), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), + ("birth_date", models.DateField()), ], ), migrations.CreateModel( - name='Library', + name="Library", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), - ('address', models.TextField()), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), + ("address", models.TextField()), ], ), migrations.CreateModel( - name='Publisher', + name="Publisher", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), - ('address', models.TextField(help_text="Publisher's official address")), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), + ("address", models.TextField(help_text="Publisher's official address")), ], ), migrations.CreateModel( - name='Book', + name="Book", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=200)), - ('isbn', models.CharField(max_length=13, unique=True)), - ('publication_date', models.DateField()), - ('authors', models.ManyToManyField(to='app.author')), - ('publisher', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.publisher')), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=200)), + ("isbn", models.CharField(max_length=13, unique=True)), + ("publication_date", models.DateField()), + ("authors", models.ManyToManyField(to="app.author")), + ( + "publisher", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="app.publisher" + ), + ), ], options={ - 'default_related_name': 'books', + "default_related_name": "books", }, ), migrations.CreateModel( - name='BookCopy', + name="BookCopy", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('inventory_number', models.CharField(max_length=20, unique=True)), - ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.book')), - ('library', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.library')), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("inventory_number", models.CharField(max_length=20, unique=True)), + ( + "book", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="app.book" + ), + ), + ( + "library", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="app.library" + ), + ), ], options={ - 'default_related_name': 'book_copies', + "default_related_name": "book_copies", }, ), migrations.CreateModel( - name='Borrowing', + name="Borrowing", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('borrow_date', models.DateField()), - ('return_date', models.DateField(blank=True, null=True)), - ('book_copy', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.bookcopy')), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("borrow_date", models.DateField()), + ("return_date", models.DateField(blank=True, null=True)), + ( + "book_copy", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="app.bookcopy" + ), + ), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), ], options={ - 'default_related_name': 'borrowings', + "default_related_name": "borrowings", }, ), ] diff --git a/tests/test_django/app/models.py b/tests/test_django/app/models.py index 60a13c6..a3464b2 100644 --- a/tests/test_django/app/models.py +++ b/tests/test_django/app/models.py @@ -2,10 +2,10 @@ from typing import ClassVar, override +from django2pydantic import Infer, ModelFields from django.contrib.auth.models import User from django.db import models -from django2pydantic import Infer, ModelFields from django_ninja_crudl.crudl import CrudlApiBaseMeta diff --git a/tests/test_django/wsgi.py b/tests/test_django/wsgi.py index be05e6b..a3bfd6b 100644 --- a/tests/test_django/wsgi.py +++ b/tests/test_django/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_django.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_django.settings") application = get_wsgi_application()