Skip to content

Commit

Permalink
Releases/0.2.0 (#14)
Browse files Browse the repository at this point in the history
* feat: Latest Ninja V1 Support (by django-ninja-extra 0.20.0)

Updates:
    "django-ninja-extra >= 0.20.0"
    "django-ninja-jwt>=5.2.9"

* release: v0.2.0 (Ninja V1 Support, mainly Pydantic V2 Upgrade)

* fix: update related qa tools - mypy/black etc - to pass codestyle check

* fix: mypy check

---------

Co-authored-by: Hongbin Huang <[email protected]>
  • Loading branch information
freemindcore and Hongbin Huang authored Nov 22, 2023
1 parent 39b96b6 commit f4fd0ff
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
args: [--allow-missing-credentials]

- repo: https://github.com/psf/black
rev: 22.8.0
rev: 23.10.1
hooks:
- id: black

Expand Down
2 changes: 1 addition & 1 deletion easy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Django Easy API - Easy and Fast Django REST framework based on Django-ninja-extra"""

__version__ = "0.1.40"
__version__ = "0.2.0"

from easy.main import EasyAPI

Expand Down
2 changes: 1 addition & 1 deletion easy/controller/auto_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def create_api_controller(
},
)

return api_controller( # type: ignore
return api_controller(
f"/{app_name}/{model_name.lower()}",
tags=[f"{model_name} {controller_name_prefix}API"],
permissions=[permission_class],
Expand Down
4 changes: 2 additions & 2 deletions easy/controller/meta_conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Type, Union
from typing import Any, List, Optional, Type, Union

from django.db import models

Expand All @@ -24,7 +24,7 @@


class ModelOptions:
def __init__(self, options: Dict = None):
def __init__(self, options: Optional[object] = None):
"""
Configuration reader
"""
Expand Down
6 changes: 3 additions & 3 deletions easy/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import wraps
from types import FunctionType
from typing import Any, Callable
from typing import Any, Callable, Optional
from urllib.parse import urlparse

from django.conf import settings
Expand All @@ -11,7 +11,7 @@

def request_passes_test(
test_func: Callable[[Any], Any],
login_url: str = None,
login_url: Optional[str] = None,
redirect_field_name: str = REDIRECT_FIELD_NAME,
) -> Callable[[FunctionType], Callable[[HttpRequest, Any], Any]]:
"""
Expand Down Expand Up @@ -45,7 +45,7 @@ def _wrapped_view(request: HttpRequest, *args: Any, **kwargs: Any) -> Any:


def docs_permission_required(
view_func: FunctionType = None,
view_func: Optional[FunctionType] = None,
redirect_field_name: str = REDIRECT_FIELD_NAME,
login_url: str = "admin:login",
) -> Any:
Expand Down
2 changes: 1 addition & 1 deletion easy/domain/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def serialize_many_relationship(
return {}
out = {}
try:
for k, v in obj._prefetched_objects_cache.items(): # type: ignore
for k, v in obj._prefetched_objects_cache.items():
field_name = k if hasattr(obj, k) else k + "_set"
if v:
if self.get_model_join(obj):
Expand Down
5 changes: 3 additions & 2 deletions easy/exception.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.utils.translation import gettext_lazy as _
from ninja_extra import status
from ninja_extra.exceptions import APIException

Expand All @@ -8,7 +9,7 @@ class BaseAPIException(APIException):
"""

status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
default_detail = (
default_detail = _(
"There is an unexpected error, please try again later, if the problem "
"persists, please contact customer support team for further support."
)
Expand All @@ -20,4 +21,4 @@ class APIAuthException(BaseAPIException):
"""

status_code = status.HTTP_401_UNAUTHORIZED
default_detail = "Unauthorized"
default_detail = _("Unauthorized")
4 changes: 2 additions & 2 deletions easy/permissions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def has_permission(
"""
has_perm: bool = True
if hasattr(controller, "service"):
has_perm = controller.service.check_permission(request, controller) # type: ignore
has_perm = controller.service.check_permission(request, controller)
return has_perm

def has_object_permission(
Expand All @@ -32,7 +32,7 @@ def has_object_permission(
"""
has_perm: bool = True
if hasattr(controller, "service"):
has_perm = controller.service.check_object_permission( # type: ignore
has_perm = controller.service.check_object_permission(
request, controller, obj
)
return has_perm
8 changes: 4 additions & 4 deletions easy/testing/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from json import dumps as json_dumps
from typing import Any, Callable, Dict, List, Sequence, Type, Union, cast
from typing import Any, Callable, Dict, List, Optional, Sequence, Type, Union, cast
from unittest.mock import Mock
from urllib.parse import urlencode

Expand All @@ -22,7 +22,7 @@ def __init__(
) -> None:
if hasattr(router_or_app, "get_api_controller"):
api = api_cls(auth=auth)
controller_ninja_api_controller = router_or_app.get_api_controller() # type: ignore
controller_ninja_api_controller = router_or_app.get_api_controller()
assert controller_ninja_api_controller
controller_ninja_api_controller.set_api_instance(api)
self._urls_cache = list(controller_ninja_api_controller.urls_paths(""))
Expand All @@ -33,7 +33,7 @@ def request(
self,
method: str,
path: str,
data: Dict = {},
data: Optional[Dict] = None,
json: Any = None,
**request_params: Any,
) -> "NinjaResponse":
Expand All @@ -43,7 +43,7 @@ def request(
query = request_params.pop("query")
url_encode = urlencode(query)
path = f"{path}?{url_encode}"
func, request, kwargs = self._resolve(method, path, data, request_params)
func, request, kwargs = self._resolve(method, path, data, request_params) # type: ignore
return self._call(func, request, kwargs) # type: ignore

@property
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ test = [
"pytest-cov",
"pytest-django",
"pytest-asyncio",
"black",
"black==23.10.1",
"mypy==1.6.1",
"isort",
"injector == 0.19.0",
"injector>= 0.19.0",
"flake8",
"mypy==0.931",
"django-stubs",
"factory-boy==3.2.1",
"django_coverage_plugin",
"django-ninja-extra >= 0.16.0",
"django-ninja-jwt>=5.1.0",
"django-ninja-extra >= 0.20.0",
"django-ninja-jwt>=5.2.9",
"Django >= 3.1",
]
dev = [
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ warn_unused_ignores = True
disallow_untyped_defs = True
check_untyped_defs = True
no_implicit_reexport = True
no_implicit_optional = False

[mypy.plugins.django-stubs]
django_settings_module = "tests.easy_app"
Expand Down

0 comments on commit f4fd0ff

Please sign in to comment.