dmr-controller-group 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dmr_controller_group-0.0.1/.gitignore +269 -0
- dmr_controller_group-0.0.1/CONTRIBUTING.md +100 -0
- dmr_controller_group-0.0.1/LICENSE +20 -0
- dmr_controller_group-0.0.1/PKG-INFO +195 -0
- dmr_controller_group-0.0.1/README.md +184 -0
- dmr_controller_group-0.0.1/dmr_controller_group/__init__.py +12 -0
- dmr_controller_group-0.0.1/dmr_controller_group/__metadata__.py +11 -0
- dmr_controller_group-0.0.1/dmr_controller_group/_controllers.py +79 -0
- dmr_controller_group-0.0.1/dmr_controller_group/_routes.py +96 -0
- dmr_controller_group-0.0.1/dmr_controller_group/decorators.py +173 -0
- dmr_controller_group-0.0.1/dmr_controller_group/endpoints.py +87 -0
- dmr_controller_group-0.0.1/dmr_controller_group/exceptions.py +2 -0
- dmr_controller_group-0.0.1/dmr_controller_group/groups.py +137 -0
- dmr_controller_group-0.0.1/dmr_controller_group/py.typed +0 -0
- dmr_controller_group-0.0.1/docs/__init__.py +1 -0
- dmr_controller_group-0.0.1/docs/_static/custom.css +12 -0
- dmr_controller_group-0.0.1/docs/conf.py +99 -0
- dmr_controller_group-0.0.1/docs/index.rst +25 -0
- dmr_controller_group-0.0.1/docs/justfile +29 -0
- dmr_controller_group-0.0.1/docs/pages/api-reference.rst +30 -0
- dmr_controller_group-0.0.1/docs/pages/configuration.rst +135 -0
- dmr_controller_group-0.0.1/docs/pages/documentation-guidelines.rst +95 -0
- dmr_controller_group-0.0.1/docs/pages/installation.rst +38 -0
- dmr_controller_group-0.0.1/docs/pages/quickstart.rst +38 -0
- dmr_controller_group-0.0.1/docs/pages/routing.rst +51 -0
- dmr_controller_group-0.0.1/pyproject.toml +245 -0
- dmr_controller_group-0.0.1/tests/__init__.py +0 -0
- dmr_controller_group-0.0.1/tests/fixtures/__init__.py +0 -0
- dmr_controller_group-0.0.1/tests/fixtures/controllers.py +15 -0
- dmr_controller_group-0.0.1/tests/fixtures/models.py +9 -0
- dmr_controller_group-0.0.1/tests/helpers.py +9 -0
- dmr_controller_group-0.0.1/tests/integration/__init__.py +0 -0
- dmr_controller_group-0.0.1/tests/integration/conftest.py +26 -0
- dmr_controller_group-0.0.1/tests/integration/test_annotations.py +35 -0
- dmr_controller_group-0.0.1/tests/integration/test_configuration.py +57 -0
- dmr_controller_group-0.0.1/tests/integration/test_controllers.py +72 -0
- dmr_controller_group-0.0.1/tests/integration/test_decorators/__init__.py +0 -0
- dmr_controller_group-0.0.1/tests/integration/test_decorators/test_controllers.py +90 -0
- dmr_controller_group-0.0.1/tests/integration/test_decorators/test_methods.py +123 -0
- dmr_controller_group-0.0.1/tests/integration/test_errors.py +166 -0
- dmr_controller_group-0.0.1/tests/integration/test_generics.py +107 -0
- dmr_controller_group-0.0.1/tests/integration/test_inheritance.py +100 -0
- dmr_controller_group-0.0.1/tests/integration/test_options.py +50 -0
- dmr_controller_group-0.0.1/tests/integration/test_routing.py +119 -0
- dmr_controller_group-0.0.1/tests/settings.py +6 -0
- dmr_controller_group-0.0.1/tests/types.py +11 -0
- dmr_controller_group-0.0.1/tests/unit/__init__.py +0 -0
- dmr_controller_group-0.0.1/tests/unit/test_compilation.py +135 -0
- dmr_controller_group-0.0.1/tests/unit/test_decorators.py +99 -0
- dmr_controller_group-0.0.1/tests/unit/test_endpoints.py +37 -0
- dmr_controller_group-0.0.1/tests/unit/test_generics.py +58 -0
- dmr_controller_group-0.0.1/tests/unit/test_groups.py +103 -0
- dmr_controller_group-0.0.1/tests/unit/test_openapi.py +129 -0
- dmr_controller_group-0.0.1/tests/unit/test_routes.py +114 -0
- dmr_controller_group-0.0.1/tests/urls.py +4 -0
- dmr_controller_group-0.0.1/uv.lock +2313 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
#### joe made this: http://goel.io/joe
|
|
2
|
+
#### macos ####
|
|
3
|
+
# General
|
|
4
|
+
*.DS_Store
|
|
5
|
+
.AppleDouble
|
|
6
|
+
.LSOverride
|
|
7
|
+
|
|
8
|
+
# Icon must end with two \r
|
|
9
|
+
Icon
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Thumbnails
|
|
13
|
+
._*
|
|
14
|
+
|
|
15
|
+
# Files that might appear in the root of a volume
|
|
16
|
+
.DocumentRevisions-V100
|
|
17
|
+
.fseventsd
|
|
18
|
+
.Spotlight-V100
|
|
19
|
+
.TemporaryItems
|
|
20
|
+
.Trashes
|
|
21
|
+
.VolumeIcon.icns
|
|
22
|
+
.com.apple.timemachine.donotpresent
|
|
23
|
+
|
|
24
|
+
# Directories potentially created on remote AFP share
|
|
25
|
+
.AppleDB
|
|
26
|
+
.AppleDesktop
|
|
27
|
+
Network Trash Folder
|
|
28
|
+
Temporary Items
|
|
29
|
+
.apdisk
|
|
30
|
+
#### linux ####
|
|
31
|
+
*~
|
|
32
|
+
|
|
33
|
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
|
34
|
+
.fuse_hidden*
|
|
35
|
+
|
|
36
|
+
# KDE directory preferences
|
|
37
|
+
.directory
|
|
38
|
+
|
|
39
|
+
# Linux trash folder which might appear on any partition or disk
|
|
40
|
+
.Trash-*
|
|
41
|
+
|
|
42
|
+
# .nfs files are created when an open file is removed but is still being accessed
|
|
43
|
+
.nfs*
|
|
44
|
+
#### windows ####
|
|
45
|
+
# Windows thumbnail cache files
|
|
46
|
+
Thumbs.db
|
|
47
|
+
ehthumbs.db
|
|
48
|
+
ehthumbs_vista.db
|
|
49
|
+
|
|
50
|
+
# Dump file
|
|
51
|
+
*.stackdump
|
|
52
|
+
|
|
53
|
+
# Folder config file
|
|
54
|
+
Desktop.ini
|
|
55
|
+
|
|
56
|
+
# Recycle Bin used on file shares
|
|
57
|
+
$RECYCLE.BIN/
|
|
58
|
+
|
|
59
|
+
# Windows Installer files
|
|
60
|
+
*.cab
|
|
61
|
+
*.msi
|
|
62
|
+
*.msm
|
|
63
|
+
*.msp
|
|
64
|
+
|
|
65
|
+
# Windows shortcuts
|
|
66
|
+
*.lnk
|
|
67
|
+
#### python ####
|
|
68
|
+
# Byte-compiled / optimized / DLL files
|
|
69
|
+
__pycache__/
|
|
70
|
+
*.py[cod]
|
|
71
|
+
*$py.class
|
|
72
|
+
|
|
73
|
+
# C extensions
|
|
74
|
+
*.so
|
|
75
|
+
|
|
76
|
+
# Distribution / packaging
|
|
77
|
+
.Python
|
|
78
|
+
build/
|
|
79
|
+
develop-eggs/
|
|
80
|
+
dist/
|
|
81
|
+
downloads/
|
|
82
|
+
eggs/
|
|
83
|
+
.eggs/
|
|
84
|
+
lib/
|
|
85
|
+
lib64/
|
|
86
|
+
parts/
|
|
87
|
+
sdist/
|
|
88
|
+
var/
|
|
89
|
+
wheels/
|
|
90
|
+
*.egg-info/
|
|
91
|
+
.installed.cfg
|
|
92
|
+
*.egg
|
|
93
|
+
|
|
94
|
+
# PyInstaller
|
|
95
|
+
# Usually these files are written by a python script from a template
|
|
96
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
97
|
+
*.manifest
|
|
98
|
+
*.spec
|
|
99
|
+
|
|
100
|
+
# Installer logs
|
|
101
|
+
pip-log.txt
|
|
102
|
+
pip-delete-this-directory.txt
|
|
103
|
+
|
|
104
|
+
# Unit test / coverage / tracecov reports
|
|
105
|
+
htmlcov/
|
|
106
|
+
.tox/
|
|
107
|
+
.coverage
|
|
108
|
+
.coverage.*
|
|
109
|
+
.cache
|
|
110
|
+
nosetests.xml
|
|
111
|
+
coverage.xml
|
|
112
|
+
*.cover
|
|
113
|
+
.hypothesis/
|
|
114
|
+
.ruff_cache/
|
|
115
|
+
tracecov-report.md
|
|
116
|
+
tracecov-report.html
|
|
117
|
+
|
|
118
|
+
# Translations
|
|
119
|
+
!*.mo
|
|
120
|
+
*.pot
|
|
121
|
+
|
|
122
|
+
# Django stuff:
|
|
123
|
+
*.log
|
|
124
|
+
local_settings.py
|
|
125
|
+
|
|
126
|
+
# Flask stuff:
|
|
127
|
+
instance/
|
|
128
|
+
.webassets-cache
|
|
129
|
+
|
|
130
|
+
# Scrapy stuff:
|
|
131
|
+
.scrapy
|
|
132
|
+
|
|
133
|
+
# Sphinx documentation
|
|
134
|
+
docs/_build/
|
|
135
|
+
.auto_pytabs_cache/
|
|
136
|
+
|
|
137
|
+
# PyBuilder
|
|
138
|
+
target/
|
|
139
|
+
|
|
140
|
+
# Jupyter Notebook
|
|
141
|
+
.ipynb_checkpoints
|
|
142
|
+
|
|
143
|
+
# celery beat schedule file
|
|
144
|
+
celerybeat-schedule
|
|
145
|
+
|
|
146
|
+
# SageMath parsed files
|
|
147
|
+
*.sage.py
|
|
148
|
+
|
|
149
|
+
# Environments
|
|
150
|
+
.env
|
|
151
|
+
.venv
|
|
152
|
+
env/
|
|
153
|
+
venv/
|
|
154
|
+
ENV/
|
|
155
|
+
|
|
156
|
+
# Spyder project settings
|
|
157
|
+
.spyderproject
|
|
158
|
+
.spyproject
|
|
159
|
+
|
|
160
|
+
# Rope project settings
|
|
161
|
+
.ropeproject
|
|
162
|
+
|
|
163
|
+
# mkdocs documentation
|
|
164
|
+
/site
|
|
165
|
+
|
|
166
|
+
# mypy
|
|
167
|
+
.mypy_cache/
|
|
168
|
+
|
|
169
|
+
#### jetbrains ####
|
|
170
|
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
|
171
|
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
172
|
+
|
|
173
|
+
#### vscode ####
|
|
174
|
+
.vscode/
|
|
175
|
+
|
|
176
|
+
# User-specific stuff:
|
|
177
|
+
.idea/**/workspace.xml
|
|
178
|
+
.idea/**/tasks.xml
|
|
179
|
+
.idea/dictionaries
|
|
180
|
+
|
|
181
|
+
# Sensitive or high-churn files:
|
|
182
|
+
.idea/**/dataSources/
|
|
183
|
+
.idea/**/dataSources.ids
|
|
184
|
+
.idea/**/dataSources.xml
|
|
185
|
+
.idea/**/dataSources.local.xml
|
|
186
|
+
.idea/**/sqlDataSources.xml
|
|
187
|
+
.idea/**/dynamic.xml
|
|
188
|
+
.idea/**/uiDesigner.xml
|
|
189
|
+
|
|
190
|
+
# Gradle:
|
|
191
|
+
.idea/**/gradle.xml
|
|
192
|
+
.idea/**/libraries
|
|
193
|
+
|
|
194
|
+
# CMake
|
|
195
|
+
cmake-build-debug/
|
|
196
|
+
|
|
197
|
+
# Mongo Explorer plugin:
|
|
198
|
+
.idea/**/mongoSettings.xml
|
|
199
|
+
|
|
200
|
+
## File-based project format:
|
|
201
|
+
*.iws
|
|
202
|
+
|
|
203
|
+
## Plugin-specific files:
|
|
204
|
+
|
|
205
|
+
# IntelliJ
|
|
206
|
+
/out/
|
|
207
|
+
|
|
208
|
+
# mpeltonen/sbt-idea plugin
|
|
209
|
+
.idea_modules/
|
|
210
|
+
|
|
211
|
+
# JIRA plugin
|
|
212
|
+
atlassian-ide-plugin.xml
|
|
213
|
+
|
|
214
|
+
# Cursive Clojure plugin
|
|
215
|
+
.idea/replstate.xml
|
|
216
|
+
|
|
217
|
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
218
|
+
com_crashlytics_export_strings.xml
|
|
219
|
+
crashlytics.properties
|
|
220
|
+
crashlytics-build.properties
|
|
221
|
+
fabric.properties
|
|
222
|
+
|
|
223
|
+
# pyenv
|
|
224
|
+
.python-version
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
#####=== Custom ===#####
|
|
228
|
+
# File types:
|
|
229
|
+
*.sqlite3
|
|
230
|
+
*.db
|
|
231
|
+
|
|
232
|
+
# Configuration file with private data:
|
|
233
|
+
*.env
|
|
234
|
+
.env
|
|
235
|
+
|
|
236
|
+
# Artifacts:
|
|
237
|
+
.gitlab/.svn/
|
|
238
|
+
artifacts/
|
|
239
|
+
wheelhouse/
|
|
240
|
+
|
|
241
|
+
# mypy:
|
|
242
|
+
.mypy_cache/
|
|
243
|
+
|
|
244
|
+
# pytest and hypothesis
|
|
245
|
+
.pytest_cache/
|
|
246
|
+
.hypothesis/
|
|
247
|
+
|
|
248
|
+
# ipython:
|
|
249
|
+
.ipython/
|
|
250
|
+
.python_history
|
|
251
|
+
|
|
252
|
+
# ruff:
|
|
253
|
+
.ruff_cache/
|
|
254
|
+
|
|
255
|
+
# import-linter:
|
|
256
|
+
.import_linter_cache/
|
|
257
|
+
|
|
258
|
+
# safety:
|
|
259
|
+
.safety/
|
|
260
|
+
|
|
261
|
+
# PyCharm:
|
|
262
|
+
.idea/
|
|
263
|
+
|
|
264
|
+
# CodSpeed:
|
|
265
|
+
.codspeed/
|
|
266
|
+
|
|
267
|
+
# AI slop:
|
|
268
|
+
.claude/
|
|
269
|
+
.codex/
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Environment setup
|
|
4
|
+
|
|
5
|
+
1. Install uv, just, Git, and Bash.
|
|
6
|
+
2. Clone the repository and change into its directory. For a newly generated
|
|
7
|
+
project, run `git init`.
|
|
8
|
+
3. Run `just install` to install the project, all dependency groups and extras,
|
|
9
|
+
and Git hooks through prek. Development uses Python 3.14;
|
|
10
|
+
uv manages its version through `.python-version`.
|
|
11
|
+
|
|
12
|
+
Run `just install` again after changing dependencies. Commands set
|
|
13
|
+
`UV_NO_SYNC=1`, so the environment is not synchronized automatically.
|
|
14
|
+
|
|
15
|
+
`just --list` shows the available development commands, defined in `justfile`.
|
|
16
|
+
Git hook checks are configured in `.pre-commit-config.yml` and run through prek.
|
|
17
|
+
|
|
18
|
+
## Making changes
|
|
19
|
+
|
|
20
|
+
1. Create a separate branch from `main` and make your changes.
|
|
21
|
+
2. Run `just check` and review automatic fixes, including changes to `uv.lock`.
|
|
22
|
+
3. Run `just check-all` before opening a pull request.
|
|
23
|
+
|
|
24
|
+
Commit messages and pull request titles must follow
|
|
25
|
+
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), for example,
|
|
26
|
+
`fix: handle invalid API responses`. The pre-commit hook checks staged changes,
|
|
27
|
+
applies fixes, and stops if files change. Review the result and stage the updated files again.
|
|
28
|
+
|
|
29
|
+
### Checks
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
just check # Run all hooks on tracked files and apply fixes
|
|
33
|
+
just check mypy # Run one configured hook
|
|
34
|
+
just check pyright
|
|
35
|
+
just check deptry
|
|
36
|
+
just format # Apply Ruff fixes and formatting
|
|
37
|
+
just lint # Check code and formatting without fixes
|
|
38
|
+
just type-check # Run mypy and Pyright
|
|
39
|
+
just check-all # Check the environment, tests, docs, and all prek hooks
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Hooks check code with Ruff, types, documentation markup, spelling,
|
|
43
|
+
TOML/YAML syntax, dependency declarations, and lock file consistency.
|
|
44
|
+
|
|
45
|
+
Deptry analyzes the library using metadata from the installed environment.
|
|
46
|
+
Declare every directly imported runtime dependency, including dependencies from extras.
|
|
47
|
+
|
|
48
|
+
`just check-all` checks the lock file and installed environment, runs tests,
|
|
49
|
+
builds documentation with warnings treated as errors, runs doctests,
|
|
50
|
+
and then runs all prek hooks with automatic fixes.
|
|
51
|
+
`just build` builds a wheel in `dist/`.
|
|
52
|
+
|
|
53
|
+
### Tests and coverage
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
just test
|
|
57
|
+
just test tests/integration/test_routing.py
|
|
58
|
+
just test -k 'example or smoke'
|
|
59
|
+
just test --cov=dmr_controller_group --cov-report=term-missing --cov-report=xml
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Tests run in three processes. Coverage collection is enabled separately:
|
|
63
|
+
the last command measures library coverage, reports uncovered lines,
|
|
64
|
+
and creates `coverage.xml`. Git ignores `.coverage`, `coverage.xml`, and other reports.
|
|
65
|
+
|
|
66
|
+
Tests for declarations, controller compilation, and OpenAPI are in `tests/unit/`;
|
|
67
|
+
HTTP request tests are in `tests/integration/`. Shared models and base classes
|
|
68
|
+
live in `tests/fixtures/`, and fixture factory types live in `tests/types.py`.
|
|
69
|
+
The `mount_group` fixture is available only to integration tests.
|
|
70
|
+
|
|
71
|
+
### Development commands
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
just doctor # Check local development tools
|
|
75
|
+
just package # Check the lock file and installed dependencies
|
|
76
|
+
just build # Build a wheel
|
|
77
|
+
just docs # Clean and build HTML documentation
|
|
78
|
+
just docs html doctest # Build specific Sphinx targets
|
|
79
|
+
just docs-check # Run a strict build, doctests, and LLM artifact checks
|
|
80
|
+
just docs-linkcheck # Check external links
|
|
81
|
+
just docs-serve # Serve documentation on localhost:8000
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Updating dependencies and cleaning up
|
|
85
|
+
|
|
86
|
+
Edit Python dependencies in `pyproject.toml`, run `just install`,
|
|
87
|
+
and commit the updated `uv.lock`. `just lock` updates only the lock file.
|
|
88
|
+
`just upgrade` updates Python dependencies, synchronizes all groups and extras,
|
|
89
|
+
and updates hook versions in `.pre-commit-config.yml`.
|
|
90
|
+
Review the changes and run the checks again.
|
|
91
|
+
|
|
92
|
+
`just clean` removes build artifacts and caches. `just venv-remove`
|
|
93
|
+
(alias `destroy`) removes `.venv`; `just reinstall` removes the environment
|
|
94
|
+
and artifacts, then installs everything again. Use `just install` for routine synchronization.
|
|
95
|
+
|
|
96
|
+
## Documentation
|
|
97
|
+
|
|
98
|
+
Update documentation and docstrings when public behavior changes.
|
|
99
|
+
Follow the [documentation guidelines](docs/pages/documentation-guidelines.rst)
|
|
100
|
+
and run `just docs-check`. Run `just docs-linkcheck` after changing external links.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) 2026 Demin Vadim
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
20
|
+
OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dmr-controller-group
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Route decorators for django-modern-rest controller methods
|
|
5
|
+
Author-email: Demin Vadim <demin02vadim@gmail.com>
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: django-modern-rest<0.18,>=0.17
|
|
9
|
+
Requires-Dist: django<6.2,>=5
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# dmr-controller-group
|
|
13
|
+
|
|
14
|
+
<div align="left">
|
|
15
|
+
|
|
16
|
+
[](https://github.com/wemake-services/django-modern-rest)
|
|
17
|
+
[](https://pypi.org/project/django-modern-rest/)
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
An extension for [django-modern-rest](https://github.com/wemake-services/django-modern-rest)
|
|
22
|
+
that groups related endpoints in a single `ControllerGroup` class,
|
|
23
|
+
lets you name handlers freely, and defines HTTP methods and routes through decorators.
|
|
24
|
+
|
|
25
|
+
Calling `as_urls()` creates a separate `Controller` class for each unique path.
|
|
26
|
+
Handlers with the same path and different HTTP methods share a controller.
|
|
27
|
+
DMR's mechanisms remain unchanged: endpoint creation, validation, serialization,
|
|
28
|
+
authentication, throttling, dispatch, and OpenAPI generation are handled by DMR.
|
|
29
|
+
Handlers support standard DMR decorators: `modify`, `validate`, their `.lazy`
|
|
30
|
+
variants, and `endpoint_decorator`. Place the route decorator (`@get`, `@post`,
|
|
31
|
+
and others) above them. Use `base_controller_cls` to provide a custom abstract
|
|
32
|
+
`Controller` with shared settings, methods, and schema hooks.
|
|
33
|
+
|
|
34
|
+
Works for:
|
|
35
|
+
- CPython 3.11+
|
|
36
|
+
- Django >=5.0,<6.2
|
|
37
|
+
- django-modern-rest 0.17
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install dmr-controller-group
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
See the [installation guide](https://dmr-controller-group.readthedocs.io/en/latest/pages/installation.html) for uv and Poetry commands.
|
|
46
|
+
|
|
47
|
+
## Example
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import uuid
|
|
51
|
+
from http import HTTPStatus
|
|
52
|
+
|
|
53
|
+
from dmr import Body, Path, modify
|
|
54
|
+
from dmr.plugins.pydantic import PydanticSerializer
|
|
55
|
+
from dmr.routing import Router
|
|
56
|
+
from pydantic import BaseModel
|
|
57
|
+
|
|
58
|
+
from dmr_controller_group import ControllerGroup, delete, get, post
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class NewPost(BaseModel):
|
|
62
|
+
title: str
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class PostUid(BaseModel):
|
|
66
|
+
post_uid: uuid.UUID
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class Posts(ControllerGroup[PydanticSerializer]):
|
|
70
|
+
tags = ("Posts",)
|
|
71
|
+
|
|
72
|
+
@get(name="posts")
|
|
73
|
+
def listing(self) -> list[str]:
|
|
74
|
+
return ["First post"]
|
|
75
|
+
|
|
76
|
+
@post
|
|
77
|
+
def create(self, parsed_body: Body[NewPost]) -> NewPost:
|
|
78
|
+
return parsed_body
|
|
79
|
+
|
|
80
|
+
@post("<uuid:post_uid>/approve/", name="post-approve")
|
|
81
|
+
@modify(status_code=HTTPStatus.OK)
|
|
82
|
+
def approve(self, parsed_path: Path[PostUid]) -> str:
|
|
83
|
+
return f"Approved {parsed_path.post_uid}"
|
|
84
|
+
|
|
85
|
+
@post("<uuid:post_uid>/reject/", name="post-reject")
|
|
86
|
+
@modify(status_code=HTTPStatus.OK)
|
|
87
|
+
def reject(self, parsed_path: Path[PostUid]) -> str:
|
|
88
|
+
return f"Rejected {parsed_path.post_uid}"
|
|
89
|
+
|
|
90
|
+
@delete("<uuid:post_uid>/")
|
|
91
|
+
@modify(status_code=HTTPStatus.NO_CONTENT)
|
|
92
|
+
def destroy(self, parsed_path: Path[PostUid]) -> None:
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
router = Router("api/posts/", Posts.as_urls())
|
|
97
|
+
urlpatterns = [router.to_urlpatterns()]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Route decorators
|
|
101
|
+
|
|
102
|
+
The example above creates four controller classes: one with `get` and `post` for the empty path,
|
|
103
|
+
two with `post` for the approval and rejection paths, and one with `delete` for the object path.
|
|
104
|
+
|
|
105
|
+
The following route decorators are available:
|
|
106
|
+
|
|
107
|
+
- `@get` — declares a handler for `GET` requests.
|
|
108
|
+
- `@post` — declares a handler for `POST` requests.
|
|
109
|
+
- `@put` — declares a handler for `PUT` requests.
|
|
110
|
+
- `@patch` — declares a handler for `PATCH` requests.
|
|
111
|
+
- `@delete` — declares a handler for `DELETE` requests.
|
|
112
|
+
|
|
113
|
+
> [!TIP]
|
|
114
|
+
> All decorators default to `path=""`: you can write
|
|
115
|
+
> `@get()`, `@post()`, `@put()`, `@patch()`, and `@delete()`.
|
|
116
|
+
> With no arguments, parentheses are optional: `@get`, `@post`, `@put`, `@patch`,
|
|
117
|
+
> and `@delete` are equivalent to calls with an empty path. Use parentheses
|
|
118
|
+
> to pass `path` or `name`: `@get("details/")`, `@get(name="posts")`.
|
|
119
|
+
|
|
120
|
+
## Configuration and error handling
|
|
121
|
+
|
|
122
|
+
`ControllerGroup[Serializer]` uses the standard DMR `Controller`.
|
|
123
|
+
The serializer type parameter is inherited and can be specialized in subclasses.
|
|
124
|
+
A custom `base_controller_cls` takes priority and lets you omit the type parameter.
|
|
125
|
+
If neither a serializer nor a base controller is provided, `as_urls()` raises a configuration error.
|
|
126
|
+
|
|
127
|
+
> [!NOTE]
|
|
128
|
+
> You can override configurable `Controller` attributes directly on the group:
|
|
129
|
+
> `auth`, `throttling`, `parsers`, `renderers`, `responses`, `validate_responses`,
|
|
130
|
+
> `endpoint_cls`, OpenAPI settings, and others. They apply to every path in the group
|
|
131
|
+
> and take priority over values from `base_controller_cls`.
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from dmr import Controller
|
|
135
|
+
from dmr.plugins.pydantic import PydanticSerializer
|
|
136
|
+
from dmr.routing import Router
|
|
137
|
+
|
|
138
|
+
from dmr_controller_group import ControllerGroup, get
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class ProjectController(Controller[PydanticSerializer]):
|
|
142
|
+
is_abstract = True
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class CustomPosts(ControllerGroup):
|
|
146
|
+
base_controller_cls = ProjectController
|
|
147
|
+
tags = ("Posts",)
|
|
148
|
+
validate_responses = True
|
|
149
|
+
|
|
150
|
+
@get(name="posts")
|
|
151
|
+
def listing(self) -> list[str]:
|
|
152
|
+
return ["First post"]
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
router = Router("api/posts/", CustomPosts.as_urls())
|
|
156
|
+
urlpatterns = [router.to_urlpatterns()]
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`ProjectController` provides the DMR base and serializer, while `CustomPosts`
|
|
160
|
+
declares routes through `ControllerGroup`. The `base_controller_cls` attribute connects them.
|
|
161
|
+
|
|
162
|
+
> [!IMPORTANT]
|
|
163
|
+
> The base controller must be abstract, have a concrete serializer, and define no
|
|
164
|
+
> HTTP handlers. The `meta` method and DMR's OPTIONS mixins are allowed.
|
|
165
|
+
|
|
166
|
+
Generated controllers inherit from the group and the selected base controller,
|
|
167
|
+
including its settings, methods, and schema hooks. The group can define `handle_error`
|
|
168
|
+
(sync) and `handle_async_error` (async); otherwise, the base controller's hooks are used.
|
|
169
|
+
Declare custom base methods on the group for type checking when needed.
|
|
170
|
+
See [configuration and error handling](https://dmr-controller-group.readthedocs.io/en/latest/pages/configuration.html) for details.
|
|
171
|
+
|
|
172
|
+
## Routing and OpenAPI
|
|
173
|
+
|
|
174
|
+
Methods with route decorators can still be called through an instance and `super()`.
|
|
175
|
+
Paths are relative and use Django's `path()` syntax.
|
|
176
|
+
|
|
177
|
+
- Each path has one controller and one URL name; setting `name` on one handler is enough.
|
|
178
|
+
Duplicate path and HTTP method pairs are not allowed.
|
|
179
|
+
- Routes declared on the group precede inherited routes, in declaration order.
|
|
180
|
+
Repeat the route decorator when overriding a handler.
|
|
181
|
+
- `HEAD` and `OPTIONS` are not added automatically. Enable OPTIONS through the base controller.
|
|
182
|
+
|
|
183
|
+
> [!IMPORTANT]
|
|
184
|
+
> Handlers for the same path, including `meta`, must all use `def` or all use `async def`.
|
|
185
|
+
> A group can combine `def` and `async def` handlers for different paths.
|
|
186
|
+
|
|
187
|
+
Each `as_urls()` call creates independent controllers and URL patterns with stable class names.
|
|
188
|
+
See the [routing rules](https://dmr-controller-group.readthedocs.io/en/latest/pages/routing.html) for details.
|
|
189
|
+
|
|
190
|
+
## Documentation
|
|
191
|
+
|
|
192
|
+
[Full documentation](https://dmr-controller-group.readthedocs.io/en/latest/)
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
[MIT](LICENSE)
|