Skip to content

Commit

Permalink
Release 5.11.6
Browse files Browse the repository at this point in the history
### Changelog:
- Fix(backend): Provide empty content on 1XX, 204 and 304 responses in ``Action`` decorator.
- Fix(backend): Do not call ``.save()`` on instance when ``ModelSerializer`` is used in ``SimpleAction``.
- Fix(backend): Force empty response for 1XX, 204 and 304 ``HTTP_`` responses.
- Chore(backend): Add stubs for ``HTTP_`` responses: 102, 103, 421 and 425.
- Chore(backend): Update dependencies.
  • Loading branch information
onegreyonewhite committed Nov 7, 2024
1 parent 9c28ebd commit bf1b172
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 29 deletions.
6 changes: 3 additions & 3 deletions .gitlab/merge_request_templates/Chore.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Chore: description

### BREAKING CHANGES:
* What you should do for fix it in your projects?
- What you should do for fix it in your projects?

### Changelog:
* What was done?
- What was done?

Closes: group/project#issue
WIP: group/project#issue

### TODO:
* What should someone do?
- What should someone do?
6 changes: 3 additions & 3 deletions .gitlab/merge_request_templates/Docs.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Docs: description

### BREAKING CHANGES:
* What you should do for fix it in your projects?
- What you should do for fix it in your projects?

### Changelog:
* What was done?
- What was done?

Closes: group/project#issue
WIP: group/project#issue

### TODO:
* What should someone do?
- What should someone do?
6 changes: 3 additions & 3 deletions .gitlab/merge_request_templates/Feature.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Feature: description

### BREAKING CHANGES:
* What you should do for fix it in your projects?
- What you should do for fix it in your projects?

### Changelog:
* What was done?
- What was done?

Closes: group/project#issue
WIP: group/project#issue

### TODO:
* What should someone do?
- What should someone do?
6 changes: 3 additions & 3 deletions .gitlab/merge_request_templates/Fix.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# FIX: description

### BREAKING CHANGES:
* What you should do for fix it in your projects?
- What you should do for fix it in your projects?

### Changelog:
* What was done?
- What was done?

Closes: group/project#issue
WIP: group/project#issue

### TODO:
* What should someone do?
- What should someone do?
5 changes: 5 additions & 0 deletions .gitlab/merge_request_templates/Release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### BREAKING CHANGES:
-

### Changelog:
-
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
'wiki': ('https://en.wikipedia.org/wiki/%s', None),
'django_docs': (django_version_docs + 'ref/%s', None),
'django_topics': (django_version_docs + 'topics/%s', None),
'celery_docs': ('http://docs.celeryproject.org/en/latest/%s', None),
'celery_docs': ('https://docs.celeryproject.org/en/latest/%s', None),
}


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vstconsulting/vstutils",
"version": "5.10.0",
"version": "5.11.0",
"type": "module",
"author": "VST Consulting",
"license": "Apache-2.0",
Expand Down
4 changes: 2 additions & 2 deletions requirements-prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# PyMySQL>=0.9.2,<=0.9.3; python_version<'3.0'
# mysql-connector-python==8.0.15; python_version>'3.4'
# Advanced cache support
redis[hiredis]~=5.1.0
redis[hiredis]~=5.2.0
tarantool~=1.2.0
pywebpush~=2.0.0
pywebpush~=2.0.1
2 changes: 1 addition & 1 deletion requirements-rtd.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-rrequirements.txt
-rrequirements-doc.txt
-rrequirements-rpc.txt
django~=5.0.8
django~=5.1.3
httpx>=0.27.0
typing-extensions
sphinx-intl~=2.2.0
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Packages needed for test
coverage~=7.6.1
coverage~=7.6.4
fakeldap~=0.6.6
tblib==3.0.0
beautifulsoup4~=4.12.3
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
r'vstutils/static/spa/.*\.css$'
],
install_requires=[
"django~=" + (os.environ.get('DJANGO_DEP', "") or "5.1.1"),
"django~=" + (os.environ.get('DJANGO_DEP', "") or "5.1.3"),
]
+ requirements,
extras_require={
Expand All @@ -57,7 +57,7 @@
'doc': load_requirements('requirements-doc.txt'),
'prod': load_requirements('requirements-prod.txt'),
'stubs': load_requirements('requirements-stubs.txt'),
'pil': ['Pillow~=10.4.0'],
'pil': ['Pillow~=11.0.0'],
'boto3': [
i.replace('libcloud', 'libcloud,s3')
for i in requirements
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.11.5'
__version__: str = '5.11.6'
7 changes: 4 additions & 3 deletions vstutils/api/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from drf_yasg.utils import swagger_auto_schema

from .. import exceptions as vstexceptions
from .responses import HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT
from .responses import HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT, NO_CONTENT_STATUS_CODES
from .serializers import EmptySerializer, DataSerializer
from .pagination import SimpleCountedListPagination

Expand Down Expand Up @@ -214,7 +214,8 @@ def action_method(

if self.is_list and (paginator := view.paginator):
result = paginator.get_paginated_response(result).data
return response_class(result)

return response_class(None if response_class.status_code in NO_CONTENT_STATUS_CODES else result)

action_method.__name__ = self.action_kwargs.get('name', method.__name__)
action_method.__doc__ = method.__doc__
Expand Down Expand Up @@ -392,7 +393,7 @@ def action_method(view, request, *args, **kwargs):
serializer.save()
if 'set' in self.extra_actions:
self.extra_actions['set'](view, instance, request, serializer, *args, **kwargs)
else:
elif not isinstance(serializer, serializers.ModelSerializer):
instance.save()
elif request.method == "DELETE":
if 'del' in self.extra_actions:
Expand Down
28 changes: 24 additions & 4 deletions vstutils/api/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@


__globals = globals()
NO_CONTENT_STATUS_CODES = {
status.HTTP_100_CONTINUE,
status.HTTP_101_SWITCHING_PROTOCOLS,
status.HTTP_102_PROCESSING,
status.HTTP_103_EARLY_HINTS,
status.HTTP_204_NO_CONTENT,
status.HTTP_304_NOT_MODIFIED,
# This statuses might be also included in the future:
# status.HTTP_301_MOVED_PERMANENTLY,
# status.HTTP_302_FOUND,
# status.HTTP_303_SEE_OTHER,
# status.HTTP_307_TEMPORARY_REDIRECT,
# status.HTTP_308_PERMANENT_REDIRECT,
}


def __status_name_filter(name):
Expand All @@ -13,13 +27,13 @@ class BaseResponseClass(response.Response):
API response class with default status code.
:var status_code: HTTP status code.
:vartype status_code: int
:type status_code: int
:ivar timings: Response timings.
:vartype timings: int,None
:type timings: int,None
:param timings: Response timings.
:vartype timings: int,None
:type timings: int,None
"""

def __init__(self, *args, **kwargs):
Expand All @@ -29,13 +43,19 @@ def __init__(self, *args, **kwargs):
self.data = {'detail': self.data}


class NoResponse(BaseResponseClass):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.data = None


for __status_name in filter(__status_name_filter, dir(status)):
__status_code = getattr(status, __status_name)
__response_name = f'Response{__status_code}'
__http_response_name = __status_name
__globals[__response_name] = type(
__response_name,
(BaseResponseClass,),
(NoResponse if __status_code in NO_CONTENT_STATUS_CODES else BaseResponseClass,),
{"status_code": __status_code}
)
__globals[__http_response_name] = __globals[__response_name]
37 changes: 36 additions & 1 deletion vstutils/api/responses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
# for name, code in st: print(template.format(name=name, code=code), end='')

from rest_framework import response, status
from typing import Any, Dict, Text, SupportsFloat, Optional
from typing import Any, Dict, Text, SupportsFloat, Optional, Set


NO_CONTENT_STATUS_CODES: Set[int]


class BaseResponseClass(response.Response):
Expand All @@ -32,6 +35,22 @@ class Response101(HTTP_101_SWITCHING_PROTOCOLS):
...


class HTTP_102_PROCESSING(BaseResponseClass):
status_code = status.HTTP_102_PROCESSING


class Response102(HTTP_102_PROCESSING):
...


class HTTP_103_EARLY_HINTS(BaseResponseClass):
status_code = status.HTTP_103_EARLY_HINTS


class Response103(HTTP_103_EARLY_HINTS):
...


class HTTP_200_OK(BaseResponseClass):
status_code = status.HTTP_200_OK

Expand Down Expand Up @@ -336,6 +355,14 @@ class Response418(HTTP_418_IM_A_TEAPOT):
...


class HTTP_421_MISDIRECTED_REQUEST(BaseResponseClass):
status_code = status.HTTP_421_MISDIRECTED_REQUEST


class Response421(HTTP_421_MISDIRECTED_REQUEST):
...


class HTTP_422_UNPROCESSABLE_ENTITY(BaseResponseClass):
status_code = status.HTTP_422_UNPROCESSABLE_ENTITY

Expand All @@ -360,6 +387,14 @@ class Response424(HTTP_424_FAILED_DEPENDENCY):
...


class HTTP_425_TOO_EARLY(BaseResponseClass):
status_code = status.HTTP_425_TOO_EARLY


class Response425(HTTP_425_TOO_EARLY):
...


class HTTP_426_UPGRADE_REQUIRED(BaseResponseClass):
status_code = status.HTTP_426_UPGRADE_REQUIRED

Expand Down

0 comments on commit bf1b172

Please sign in to comment.