Skip to content

Commit 4c2794e

Browse files
committed
Initial commit
0 parents  commit 4c2794e

12 files changed

+387
-0
lines changed

.github/dependabot.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
target-branch: "main"
8+
9+
- package-ecosystem: "pip"
10+
directory: "/"
11+
schedule:
12+
interval: "daily"
13+
target-branch: "main"

.github/workflows/workflow.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
pull_request:
6+
release:
7+
types: [published]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
run-linter:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Run linter
21+
uses: chartboost/ruff-action@v1
22+
23+
publish-to-pypi:
24+
needs: run-linter
25+
runs-on: ubuntu-latest
26+
27+
environment: release
28+
29+
permissions:
30+
id-token: write
31+
32+
strategy:
33+
matrix:
34+
python-version: [3.11]
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
40+
- name: Set up Python ${{ matrix.python-version }}
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: ${{ matrix.python-version }}
44+
45+
- name: Install dependencies
46+
run: |
47+
python -m pip install --upgrade pip
48+
pip install build
49+
50+
- name: Build package
51+
run: python -m build
52+
53+
- name: Publish package
54+
uses: pypa/gh-action-pypi-publish@release/v1.8

.gitignore

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Custom
2+
.DS_Store
3+
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
share/python-wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
32+
# PyInstaller
33+
# Usually these files are written by a python script from a template
34+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
35+
*.manifest
36+
*.spec
37+
38+
# Installer logs
39+
pip-log.txt
40+
pip-delete-this-directory.txt
41+
42+
# Unit test / coverage reports
43+
htmlcov/
44+
.tox/
45+
.nox/
46+
.coverage
47+
.coverage.*
48+
.cache
49+
nosetests.xml
50+
coverage.xml
51+
*.cover
52+
*.py,cover
53+
.hypothesis/
54+
.pytest_cache/
55+
cover/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Django stuff:
62+
*.log
63+
local_settings.py
64+
db.sqlite3
65+
db.sqlite3-journal
66+
67+
# Flask stuff:
68+
instance/
69+
.webassets-cache
70+
71+
# Scrapy stuff:
72+
.scrapy
73+
74+
# Sphinx documentation
75+
docs/_build/
76+
77+
# PyBuilder
78+
.pybuilder/
79+
target/
80+
81+
# Jupyter Notebook
82+
.ipynb_checkpoints
83+
84+
# IPython
85+
profile_default/
86+
ipython_config.py
87+
88+
# pyenv
89+
# For a library or package, you might want to ignore these files since the code is
90+
# intended to run in multiple environments; otherwise, check them in:
91+
# .python-version
92+
93+
# pipenv
94+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
96+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
97+
# install all needed dependencies.
98+
#Pipfile.lock
99+
100+
# poetry
101+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102+
# This is especially recommended for binary packages to ensure reproducibility, and is more
103+
# commonly ignored for libraries.
104+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105+
#poetry.lock
106+
107+
# pdm
108+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109+
#pdm.lock
110+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111+
# in version control.
112+
# https://pdm.fming.dev/#use-with-ide
113+
.pdm.toml
114+
115+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116+
__pypackages__/
117+
118+
# Celery stuff
119+
celerybeat-schedule
120+
celerybeat.pid
121+
122+
# SageMath parsed files
123+
*.sage.py
124+
125+
# Environments
126+
.env
127+
.venv
128+
env/
129+
venv/
130+
ENV/
131+
env.bak/
132+
venv.bak/
133+
134+
# Spyder project settings
135+
.spyderproject
136+
.spyproject
137+
138+
# Rope project settings
139+
.ropeproject
140+
141+
# mkdocs documentation
142+
/site
143+
144+
# mypy
145+
.mypy_cache/
146+
.dmypy.json
147+
dmypy.json
148+
149+
# Pyre type checker
150+
.pyre/
151+
152+
# pytype static type analyzer
153+
.pytype/
154+
155+
# Cython debug symbols
156+
cython_debug/
157+
158+
# PyCharm
159+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161+
# and can be added to the global gitignore or merged into this file. For a more nuclear
162+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163+
#.idea/

.pre-commit-config.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
default_language_version:
2+
python: python3.11
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.5.0
7+
hooks:
8+
- id: check-toml
9+
- id: check-yaml
10+
- id: requirements-txt-fixer
11+
12+
- repo: https://github.com/astral-sh/ruff-pre-commit
13+
rev: v0.4.8
14+
hooks:
15+
- id: ruff
16+
args: [--fix]
17+
- id: ruff-format
18+
19+
- repo: https://github.com/astral-sh/uv-pre-commit
20+
rev: 0.2.11
21+
hooks:
22+
- id: pip-compile
23+
args: [requirements.in, -o, requirements.txt]

CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Contributing
2+
This project welcomes contributions from the community. Contributions are accepted using GitHub pull requests.

LICENSE

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright © 2024 Stefano Fusai
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# drf-multi-serializers
2+
3+
A simple package to handle multiple serializers for the same ViewSet in Django Rest Framework.
4+
5+
## Installation
6+
7+
```bash
8+
pip install drf-multi-serializers
9+
```
10+
11+
## Usage
12+
13+
Simply import the `MultiSerializerMixin` and use it in your ViewSet:
14+
15+
```python
16+
from drf_multi_serializers.mixins import MultiSerializerMixin
17+
18+
class MyViewSet(MultiSerializerMixin, viewsets.ModelViewSet):
19+
...
20+
serializer_classes = {
21+
"create": MyCreateSerializer,
22+
"list": MyListSerializer,
23+
"metadata": MyMetadataSerializer, # create ViewSets require either serializer_class or metadata serializer for OPTION requests
24+
"partial_update": MyUpdateSerializer,
25+
"retrieve": MyRetrieveSerializer,
26+
"update": MyUpdateSerializer,
27+
}
28+
...
29+
```
30+
31+
## Contributing
32+
33+
Contributions are welcome! To get started, please refer to our [contribution guidelines](https://github.com/stefanofusai/drf-multi-serializers/blob/main/CONTRIBUTING.md).
34+
35+
## Issues
36+
37+
If you encounter any problems while using this package, please open a new issue [here](https://github.com/stefanofusai/drf-multi-serializers/issues).

pyproject.toml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[build-system]
2+
requires = ["setuptools >= 61.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "drf-multi-serializers"
7+
version = "1.0.0"
8+
authors = [{ "name" = "Stefano Fusai", "email" = "[email protected]" }]
9+
description = "A simple package to handle multiple serializers for the same ViewSet in Django Rest Framework"
10+
readme = "README.md"
11+
requires-python = ">=3.11"
12+
dependencies = ["djangorestframework"]
13+
14+
[project.urls]
15+
Homepage = "https://github.com/stefanofusai/drf-multi-serializers"
16+
Repository = "https://github.com/stefanofusai/drf-multi-serializers"
17+
18+
[tool.mypy]
19+
python_version = "3.11"
20+
strict = true
21+
22+
[tool.ruff.lint]
23+
select = [
24+
"B",
25+
"C4",
26+
"D",
27+
"DTZ",
28+
"D1",
29+
"E",
30+
"ERA",
31+
"F",
32+
"FLY",
33+
"G",
34+
"I",
35+
"ICN",
36+
"INT",
37+
"ISC",
38+
"LOG",
39+
"N",
40+
"NPY",
41+
"PD",
42+
"PERF",
43+
"PIE",
44+
"PL",
45+
"PT",
46+
"PTH",
47+
"PYI",
48+
"Q",
49+
"RET",
50+
"RSE",
51+
"RUF",
52+
"S",
53+
"SIM",
54+
"SLF",
55+
"T10",
56+
"T20",
57+
"TD",
58+
"TID",
59+
"TRY",
60+
"UP",
61+
"W",
62+
]
63+
ignore = ["D100", "D104", "D203", "D213"]

requirements.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
djangorestframework

requirements.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile requirements.in -o requirements.txt
3+
asgiref==3.8.1
4+
# via django
5+
django==5.0.6
6+
# via djangorestframework
7+
djangorestframework==3.15.1
8+
# via -r requirements.in
9+
sqlparse==0.5.0
10+
# via django

src/drf_multi_serializers/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)