-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
style: format code with Black, isort and Ruff Formatter #10
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message for a missing |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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." | ||
Comment on lines
+41
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Recommended Solution: |
||
) | ||
|
||
|
||
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." | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Recommended Solution: |
||
|
||
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." | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)), | ||
Comment on lines
+77
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unique Constraints on FieldsThe fields Recommendation: |
||
( | ||
"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, | ||
Comment on lines
+83
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cascade Delete in Foreign Key RelationshipsThe foreign key relationships in the Recommendation: |
||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
'default_related_name': 'borrowings', | ||
"default_related_name": "borrowings", | ||
}, | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
|
||
from typing import ClassVar, override | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The import |
||
|
||
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 | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding the Suggested Change: |
||
|
||
application = get_wsgi_application() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider improving the naming of
not_authorized_openapi_extra
andthrottle_openapi_extra
to more descriptive names that convey their purpose more clearly. For example,openapi_extra_unauthorized_response
andopenapi_extra_throttle_response
might provide immediate context about their usage in OpenAPI documentation enhancements.