Skip to content
This repository was archived by the owner on Apr 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,33 @@ on:
workflow_dispatch:
pull_request:
types: [assigned, opened, synchronize, reopened]

permissions:
contents: write
pull-requests: write

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
django-version: ['3.2', '4.0', '4.1', '4.2', '5.0', '5.1']
fail-fast: false

exclude:
# Python 3.9
- python-version: '3.9'
django-version: '5.0'
- python-version: '3.9'
django-version: '5.1'

# Python 3.13
- python-version: '3.13'
django-version: '3.2'
- python-version: '3.13'
django-version: '4.0'

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -26,26 +42,13 @@ jobs:
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Determine Django compatibility
id: check-django
run: |
if [[ "${{ matrix.python-version }}" == "3.8" && "${{ matrix.django-version }}" > "4.1" ]]; then
echo "compatible=false" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.python-version }}" == "3.9" && "${{ matrix.django-version }}" > "4.2" ]]; then
echo "compatible=false" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.python-version }}" < "3.10" && "${{ matrix.django-version }}" == "5.0" ]]; then
echo "compatible=false" >> $GITHUB_OUTPUT
else
echo "compatible=true" >> $GITHUB_OUTPUT
fi
- name: Install dependencies
if: steps.check-django.outputs.compatible == 'true'
run: |
poetry install --sync --no-interaction --no-root
poetry install --sync --no-interaction --no-root
poetry run pip install "django==${{ matrix.django-version }}.*"
- name: Run tests
if: steps.check-django.outputs.compatible == 'true'
run: poetry run pytest .

merge:
runs-on: ubuntu-latest
needs: [test]
Expand All @@ -57,6 +60,7 @@ jobs:
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

release:
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
Expand All @@ -70,7 +74,7 @@ jobs:
virtualenvs-in-project: true
- name: Install python dependencies
run: |
poetry install --sync --no-interaction --no-root --with test
poetry install --sync --no-interaction --no-root --with test
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
- name: Publish
run: |
Expand Down
14 changes: 9 additions & 5 deletions ninja_put_patch_file_upload_middleware/middlewares.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from collections.abc import Callable
from typing import Any
from typing import Any, Union

from asgiref.sync import iscoroutinefunction, sync_to_async
from django.http import HttpRequest
from django.http import HttpRequest, HttpResponse
from django.utils.decorators import sync_and_async_middleware


@sync_and_async_middleware
def process_put_patch(get_response: Callable) -> Callable:
async def async_middleware(request: HttpRequest) -> Any:
def process_put_patch(
get_response: Union[
Callable[[HttpRequest], HttpResponse], Callable[[HttpRequest], Any]
],
) -> Union[Callable[[HttpRequest], Any], Callable[[HttpRequest], HttpResponse]]:
async def async_middleware(request: HttpRequest) -> Union[HttpResponse, Any]:
if (
request.method in ("PUT", "PATCH")
and request.content_type != "application/json"
Expand All @@ -22,7 +26,7 @@ async def async_middleware(request: HttpRequest) -> Any:

return await get_response(request)

def sync_middleware(request: HttpRequest) -> Any:
def sync_middleware(request: HttpRequest) -> Union[HttpResponse, Any]:
if (
request.method in ("PUT", "PATCH")
and request.content_type != "application/json"
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ homepage = "https://github.com/baseplate-admin/ninja_put_patch_file_upload_middl
repository = "https://github.com/baseplate-admin/ninja_put_patch_file_upload_middleware"
keywords = ["ninja", "django-ninja", "middlewares",'put','patch','file upload']
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Operating System :: OS Independent",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Operating System :: OS Independent",
]

[tool.poetry.dependencies]
Expand All @@ -29,9 +29,9 @@ django-ninja = "*"


[tool.poetry.group.dev.dependencies]
pytest = ">=7.2.2,<9.0.0"
pytest-django = "^4.8.0"
pytest-asyncio = ">=0.23.6,<0.25.0"
pytest = ">=7.2.2"
pytest-django = ">=4.8.0"
pytest-asyncio = ">=0.23.6"

[build-system]
requires = ["poetry-core"]
Expand Down
Loading