Skip to content

Commit

Permalink
Release 5.8.2
Browse files Browse the repository at this point in the history
#### Changelog:
* Chore(deps): Upgrade backend dependencies.
* Refactoring(backend): Add python stubs for compiled modules.
  • Loading branch information
onegreyonewhite committed Oct 7, 2023
1 parent b9b1631 commit 8514470
Show file tree
Hide file tree
Showing 15 changed files with 541 additions and 148 deletions.
13 changes: 12 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@ include requirements-rpc.txt
include requirements-ldap.txt
include requirements-prod.txt
include requirements-stubs.txt
include vstutils/api/actions.pyi
include vstutils/api/base.pyi
include vstutils/api/decorators.pyi
include vstutils/api/views.pyi
include vstutils/api/routers.pyi
include vstutils/api/responses.pyi
include vstutils/api/decorators.pyi
include vstutils/auth.pyi
include vstutils/tasks.pyi
include vstutils/middleware.pyi
include vstutils/utils.pyi
include vstutils/environment.pyi
include vstutils/models/__init__.pyi
include vstutils/models/base.pyi
include vstutils/models/cent_notify.pyi
include vstutils/models/custom_model.pyi
include vstutils/models/decorators.pyi
include vstutils/models/fields.pyi
include vstutils/models/model.pyi
include vstutils/models/queryset.pyi
include vstutils/py.typed
recursive-include vstutils/*/templates *
recursive-include vstutils/templates *
Expand Down
54 changes: 24 additions & 30 deletions doc/locale/ru/LC_MESSAGES/backend.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: VST Utils 5.0.4\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-26 06:23+0000\n"
"POT-Creation-Date: 2023-10-07 05:31+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.12.1\n"
"Generated-By: Babel 2.13.0\n"

#: ../../backend.rst:2
msgid "Backend API manual"
Expand Down Expand Up @@ -534,7 +534,7 @@ msgstr ""
#: vstutils.api.filter_backends.DeepViewFilterBackend:25
#: vstutils.api.filter_backends.VSTFilterBackend:22
#: vstutils.api.filters.FkFilterHandler:15
#: vstutils.middleware.BaseMiddleware:37
#: vstutils.middleware.BaseMiddleware:38
#: vstutils.models.custom_model.FileModel:13 vstutils.tasks.TaskClass:4
#: vstutils.utils.BaseEnum:4 vstutils.utils.Lock:35
#: vstutils.utils.ObjectHandlers:31 vstutils.utils.SecurePickling:22
Expand Down Expand Up @@ -794,10 +794,9 @@ msgstr ""
"Поле, предоставляющее автодополнение на фронтенде. Использует указанный "
"список объектов."

#: of vstutils.api.actions.Action vstutils.api.base.CopyMixin.copy
#: of vstutils.api.actions.Action
#: vstutils.api.base.GenericViewSet.create_action_serializer
#: vstutils.api.base.GenericViewSet.get_query_serialized_data
#: vstutils.api.base.GenericViewSet.get_serializer
#: vstutils.api.decorators.nested_view vstutils.api.decorators.subaction
#: vstutils.api.endpoint.EndpointViewSet.get
#: vstutils.api.endpoint.EndpointViewSet.get_client
Expand Down Expand Up @@ -829,7 +828,6 @@ msgstr ""
#: vstutils.api.validators.UrlQueryStringValidator
#: vstutils.api.validators.resize_image
#: vstutils.api.validators.resize_image_from_to
#: vstutils.middleware.BaseMiddleware
#: vstutils.middleware.BaseMiddleware.get_response_handler
#: vstutils.middleware.BaseMiddleware.handler
#: vstutils.middleware.BaseMiddleware.request_handler
Expand Down Expand Up @@ -914,8 +912,9 @@ msgid ""
"Simple string field. Value must always be a valid ASCII-string. The field"
" is going to represent as Barcode (Code 128) in user interface."
msgstr ""
"Простое строковое поле. Значение всегда должно быть допустимой строкой ASCII. "
"В пользовательском интерфейсе оно будет отображено как штрихкод (код 128)."
"Простое строковое поле. Значение всегда должно быть допустимой строкой "
"ASCII. В пользовательском интерфейсе оно будет отображено как штрихкод "
"(код 128)."

#: of vstutils.api.fields.Barcode128Field:4 vstutils.api.fields.QrCodeField:4
msgid ""
Expand Down Expand Up @@ -2033,10 +2032,7 @@ msgstr "Необходимая высота"
msgid "Returns"
msgstr "Возвращает"

#: of vstutils.api.base.CopyMixin.copy
#: vstutils.api.base.GenericViewSet.create_action_serializer
#: vstutils.api.base.GenericViewSet.get_query_serialized_data
#: vstutils.api.base.GenericViewSet.get_serializer
#: of vstutils.api.base.GenericViewSet.create_action_serializer
#: vstutils.api.endpoint.EndpointViewSet.get
#: vstutils.api.endpoint.EndpointViewSet.get_client
#: vstutils.api.endpoint.EndpointViewSet.get_serializer
Expand Down Expand Up @@ -2169,12 +2165,6 @@ msgstr "Миксина для viewset'ов, добавляющая `copy` endpoi
msgid "Endpoint which copy instance with deps."
msgstr "Endpoint, который копирует экземпляр с его зависимостями."

#: of vstutils.api.base.CopyMixin.copy:5
#: vstutils.api.endpoint.EndpointViewSet.post:5
#: vstutils.api.endpoint.EndpointViewSet.put:5
msgid ":py:class:`vstutils.api.responses.BaseResponseClass`"
msgstr ":py:class:`vstutils.api.responses.BaseResponseClass`"

#: ../../docstring of vstutils.api.base.CopyMixin.copy_field_name:1
msgid "Name of field which will get a prefix."
msgstr "Имя поля, которое получит префикс."
Expand Down Expand Up @@ -2307,14 +2297,6 @@ msgstr ""
"флаг, который говорит о том нужно ли выбросить исключение при валидации в"
" сериализаторе или нет."

#: of vstutils.api.base.GenericViewSet.get_query_serialized_data:12
msgid ""
":py:data:`typing.Union`\\[:py:class:`dict`, "
":py:class:`collections.OrderedDict`]"
msgstr ""
":py:data:`typing.Union`\\[:py:class:`dict`, "
":py:class:`collections.OrderedDict`]"

#: of vstutils.api.base.GenericViewSet.get_serializer:1
#: vstutils.api.endpoint.EndpointViewSet.get_serializer:1
msgid ""
Expand All @@ -2333,10 +2315,6 @@ msgstr ""
"Позволяет использовать :class:`django.http.StreamingHttpResponse` в "
"качестве инициализации сериализатора."

#: of vstutils.api.base.GenericViewSet.get_serializer:10
msgid ":py:class:`rest_framework.serializers.BaseSerializer`"
msgstr ":py:class:`rest_framework.serializers.BaseSerializer`"

#: of vstutils.api.base.GenericViewSet.get_serializer_class:1
msgid "Provides to setup serializer class for each action."
msgstr "Позволяет задать класс сериализатора для каждого экшена."
Expand Down Expand Up @@ -3309,6 +3287,11 @@ msgstr ""
msgid "Execute transactional bulk request"
msgstr "Выполнить транзакционный bulk-запрос"

#: of vstutils.api.endpoint.EndpointViewSet.post:5
#: vstutils.api.endpoint.EndpointViewSet.put:5
msgid ":py:class:`vstutils.api.responses.BaseResponseClass`"
msgstr ":py:class:`vstutils.api.responses.BaseResponseClass`"

#: of vstutils.api.endpoint.EndpointViewSet.put:1
msgid "Execute non transaction bulk request"
msgstr "Выполнить нетранзакционный bulk-запрос"
Expand Down Expand Up @@ -4623,3 +4606,14 @@ msgid ""
msgstr ""
"Использует функцию :func:`django.utils.translation.get_language` для "
"получения кода языка и пытается получить перевод из списка доступных."

#~ msgid ""
#~ ":py:data:`typing.Union`\\[:py:class:`dict`, "
#~ ":py:class:`collections.OrderedDict`]"
#~ msgstr ""
#~ ":py:data:`typing.Union`\\[:py:class:`dict`, "
#~ ":py:class:`collections.OrderedDict`]"

#~ msgid ":py:class:`rest_framework.serializers.BaseSerializer`"
#~ msgstr ":py:class:`rest_framework.serializers.BaseSerializer`"

4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Main packages
configparserc~=2.0.0
Markdown~=3.4.4
Markdown~=3.5.0
django-environ~=0.11.2

# REST API packages
djangorestframework~=3.14.0
drf-yasg==1.21.7
django-filter==23.3
drf_orjson_renderer~=1.7.1
ormsgpack==1.2.6
ormsgpack~=1.3.0
pyyaml~=6.0.1

# web server
Expand Down
2 changes: 1 addition & 1 deletion vstutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# pylint: disable=django-not-available
__version__: str = '5.8.1'
__version__: str = '5.8.2'
48 changes: 20 additions & 28 deletions vstutils/api/actions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import typing as _t

from django.db import transaction
from django.http.response import FileResponse
from rest_framework import serializers, viewsets
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework import serializers
from rest_framework.decorators import action
from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList
from drf_yasg.utils import swagger_auto_schema
Expand Down Expand Up @@ -107,16 +103,16 @@ def profile(self, request, *args, **kwargs):

def __init__( # noqa: CFQ002
self,
detail: bool = True,
methods: _t.List[_t.Text] = None,
serializer_class: _t.Type[serializers.Serializer] = DataSerializer,
result_serializer_class: _t.Type[serializers.Serializer] = None,
query_serializer: _t.Type[serializers.Serializer] = None,
multi: bool = False,
title: _t.Text = None,
icons: _t.Union[_t.Text, _t.Iterable] = None,
is_list: bool = False,
hidden: bool = False,
detail=True,
methods=None,
serializer_class=DataSerializer,
result_serializer_class=None,
query_serializer=None,
multi=False,
title=None,
icons=None,
is_list=False,
hidden=False,
**kwargs,
):
# pylint: disable=too-many-arguments
Expand Down Expand Up @@ -158,7 +154,7 @@ def wrap_function(self, func):
if self.query_serializer:
swagger_kwargs['query_serializer'] = self.query_serializer
if self.icons:
swagger_kwargs['x-icons'] = self.icons.split(' ') if isinstance(self.icons, _t.Text) else list(self.icons)
swagger_kwargs['x-icons'] = self.icons.split(' ') if isinstance(self.icons, str) else list(self.icons)
if self.is_page:
swagger_kwargs['x-list'] = self.is_list

Expand All @@ -170,20 +166,20 @@ def wrap_function(self, func):
def __call__(self, method):

def action_method(
view: viewsets.GenericViewSet,
request: Request,
view,
request,
*args,
**kwargs,
) -> _t.Union[Response, FileResponse]:
):

result_serializer_class: _t.Type[serializers.Serializer] = self.result_serializer_class
result_serializer_class = self.result_serializer_class
identical = False
if result_serializer_class is None:
result_serializer_class = view.get_serializer_class()
identical = True

result = method(view, request, *args, **kwargs)
response_class = self.method_response_mapping[_t.cast(_t.Text, request.method)]
response_class = self.method_response_mapping[request.method]

if issubclass(result_serializer_class, serializers.Serializer):
if not (isinstance(result, (ReturnDict, ReturnList)) and identical):
Expand Down Expand Up @@ -343,20 +339,16 @@ def _get_transaction_context(self, request, *args, **kwargs):
def __call__(self, getter=None):
self.extra_actions['get'] = getter

def action_method(
view: viewsets.GenericViewSet,
request: Request,
*args, **kwargs,
) -> Response:
def action_method(view, request, *args, **kwargs):

get_instance_method = self.extra_actions.get('get')

with self._get_transaction_context(request):
if get_instance_method:
method_kwargs: _t.Dict[_t.Text, _t.Any] = {'query_data': {}}
method_kwargs = {'query_data': {}}
if request.method == "GET":
try:
method_kwargs['query_data'] = view.get_query_serialized_data(request) # type: ignore
method_kwargs['query_data'] = view.get_query_serialized_data(request)
except (AttributeError, AssertionError):
pass
instance = get_instance_method(view, request, **method_kwargs)
Expand Down
94 changes: 94 additions & 0 deletions vstutils/api/actions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import typing as _t
from .pagination import SimpleCountedListPagination as SimpleCountedListPagination
from .responses import BaseResponseClass as BaseResponseClass, HTTP_200_OK as HTTP_200_OK, HTTP_201_CREATED as HTTP_201_CREATED, HTTP_204_NO_CONTENT as HTTP_204_NO_CONTENT
from .serializers import DataSerializer as DataSerializer, EmptySerializer as EmptySerializer
from django.http.response import HttpResponseBase, FileResponse
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework import serializers, viewsets as viewsets
from rest_framework.decorators import ViewSetAction



class SimpleActionObject(_t.Protocol):
def setter(self, func: _t.Callable) -> _t.Union[ViewSetAction, 'SimpleActionObject']: ...
def deleter(self, func: _t.Callable) -> _t.Union[ViewSetAction, 'SimpleActionObject']: ...

class DummyAtomic:
def __init__(self, *args, **kwargs) -> None: ...
def __enter__(self): ...
def __exit__(self, exc_type, exc_val, exc_tb) -> None: ...

class Action:
method_response_mapping: _t.Dict[_t.Text, _t.Type[BaseResponseClass]]
detail: bool
methods: _t.Optional[_t.List[_t.Text]]
serializer_class: _t.Type[serializers.Serializer]
result_serializer_class: _t.Optional[_t.Type[serializers.Serializer]]
query_serializer: _t.Optional[_t.Type[serializers.Serializer]]
multi: bool
title: _t.Optional[_t.Text]
icons: _t.Optional[_t.Union[_t.Text, _t.Iterable]]
is_list: bool
hidden: bool
action_kwargs: _t.Dict[_t.Text, _t.Any]
def __init__(
self,
detail: bool = ...,
methods: _t.Optional[_t.List[_t.Text]] = ...,
serializer_class: _t.Type[serializers.Serializer] = ...,
result_serializer_class: _t.Optional[_t.Type[serializers.Serializer]] = ...,
query_serializer: _t.Optional[_t.Type[serializers.Serializer]] = ...,
multi: bool = ...,
title: _t.Optional[_t.Text] = ...,
icons: _t.Optional[_t.Union[_t.Text, _t.Iterable]] = ...,
is_list: bool = ...,
hidden: bool = ...,
**kwargs
) -> None: ...
@property
def is_page(self) -> bool: ...
def wrap_function(self, func: _t.Callable) -> ViewSetAction: ...
def __call__(self, method: _t.Callable) -> ViewSetAction:
def action_method(
view: viewsets.GenericViewSet,
request: Request,
*args,
**kwargs,
) -> _t.Union[Response, FileResponse]:
...

return self.wrap_function(action_method)

class EmptyAction(Action):
serializer_class: EmptySerializer

def __init__(
self,
detail: bool = ...,
methods: _t.Optional[_t.List[_t.Text]] = ...,
result_serializer_class: _t.Optional[_t.Type[serializers.Serializer]] = ...,
query_serializer: _t.Optional[_t.Type[serializers.Serializer]] = ...,
multi: bool = ...,
title: _t.Optional[_t.Text] = ...,
icons: _t.Optional[_t.Union[_t.Text, _t.Iterable]] = ...,
is_list: bool = ...,
hidden: bool = ...,
**kwargs
) -> None: ...

class SimpleAction(Action):
atomic: bool
extra_actions: _t.Dict[_t.Text, _t.Callable[..., HttpResponseBase]]
def __init__(self, atomic: bool = False, *args, **kwargs) -> None: ...
def _get_transaction_context(self, request, *args, **kwargs) -> _t.ContextManager: ...
def __call__(self, getter: _t.Optional[_t.Callable] = ...) -> _t.Union['ViewSetAction', 'SimpleActionObject']: # type: ignore[override]
action_method = super().__call__(getter)

def setter(setter_method):
return self(self.extra_actions.get('get'))

def deleter(deleter_method):
return self(self.extra_actions.get('get'))

return action_method
Loading

0 comments on commit 8514470

Please sign in to comment.