winidjango 2.0.49__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.
Potentially problematic release.
This version of winidjango might be problematic. Click here for more details.
- winidjango-2.0.49/LICENSE +21 -0
- winidjango-2.0.49/PKG-INFO +286 -0
- winidjango-2.0.49/README.md +261 -0
- winidjango-2.0.49/pyproject.toml +116 -0
- winidjango-2.0.49/winidjango/__init__.py +38 -0
- winidjango-2.0.49/winidjango/dev/__init__.py +1 -0
- winidjango-2.0.49/winidjango/dev/builders/__init__.py +1 -0
- winidjango-2.0.49/winidjango/dev/cli/__init__.py +1 -0
- winidjango-2.0.49/winidjango/dev/cli/shared_subcommands.py +8 -0
- winidjango-2.0.49/winidjango/dev/cli/subcommands.py +6 -0
- winidjango-2.0.49/winidjango/dev/configs/__init__.py +1 -0
- winidjango-2.0.49/winidjango/dev/configs/configs.py +18 -0
- winidjango-2.0.49/winidjango/dev/tests/__init__.py +1 -0
- winidjango-2.0.49/winidjango/dev/tests/fixtures/__init__.py +1 -0
- winidjango-2.0.49/winidjango/main.py +9 -0
- winidjango-2.0.49/winidjango/py.typed +0 -0
- winidjango-2.0.49/winidjango/resources/__init__.py +1 -0
- winidjango-2.0.49/winidjango/src/__init__.py +14 -0
- winidjango-2.0.49/winidjango/src/commands/__init__.py +8 -0
- winidjango-2.0.49/winidjango/src/commands/base/__init__.py +7 -0
- winidjango-2.0.49/winidjango/src/commands/base/base.py +184 -0
- winidjango-2.0.49/winidjango/src/commands/import_data.py +117 -0
- winidjango-2.0.49/winidjango/src/db/__init__.py +7 -0
- winidjango-2.0.49/winidjango/src/db/bulk.py +620 -0
- winidjango-2.0.49/winidjango/src/db/fields.py +65 -0
- winidjango-2.0.49/winidjango/src/db/models.py +158 -0
- winidjango-2.0.49/winidjango/src/db/sql.py +45 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Winipedia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: winidjango
|
|
3
|
+
Version: 2.0.49
|
|
4
|
+
Summary: A utils package for django
|
|
5
|
+
Keywords:
|
|
6
|
+
Author: Winipedia
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Typing :: Typed
|
|
14
|
+
Requires-Dist: django
|
|
15
|
+
Requires-Dist: django-stubs-ext
|
|
16
|
+
Requires-Dist: winiutils
|
|
17
|
+
Maintainer: Winipedia
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Project-URL: Changelog, https://github.com/Winipedia/winidjango/releases
|
|
20
|
+
Project-URL: Documentation, https://Winipedia.github.io/winidjango
|
|
21
|
+
Project-URL: Homepage, https://github.com/Winipedia/winidjango
|
|
22
|
+
Project-URL: Issues, https://github.com/Winipedia/winidjango/issues
|
|
23
|
+
Project-URL: Source, https://github.com/Winipedia/winidjango
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# winidjango
|
|
27
|
+
|
|
28
|
+
<!-- tooling -->
|
|
29
|
+
[](https://github.com/Winipedia/pyrig)
|
|
30
|
+
[](https://github.com/astral-sh/uv)
|
|
31
|
+
[](https://podman.io/)
|
|
32
|
+
[](https://pre-commit.com/)
|
|
33
|
+
[](https://www.mkdocs.org/)
|
|
34
|
+
<!-- code-quality -->
|
|
35
|
+
[](https://github.com/astral-sh/ruff)
|
|
36
|
+
[](https://github.com/astral-sh/ty)
|
|
37
|
+
[](https://github.com/PyCQA/bandit)
|
|
38
|
+
[](https://pytest.org/)
|
|
39
|
+
[](https://codecov.io/gh/Winipedia/winidjango)
|
|
40
|
+
[](https://github.com/rvben/rumdl)
|
|
41
|
+
<!-- package-info -->
|
|
42
|
+
[](https://pypi.org/project/winidjango)
|
|
43
|
+
[](https://www.python.org/)
|
|
44
|
+
[](https://github.com/Winipedia/winidjango/blob/main/LICENSE)
|
|
45
|
+
<!-- ci/cd -->
|
|
46
|
+
[](https://github.com/Winipedia/winidjango/actions/workflows/health_check.yaml)
|
|
47
|
+
[](https://github.com/Winipedia/winidjango/actions/workflows/release.yaml)
|
|
48
|
+
<!-- documentation -->
|
|
49
|
+
[](https://Winipedia.github.io/winidjango)
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
> A utils package for django
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Table of Contents
|
|
58
|
+
|
|
59
|
+
- [Features](#features)
|
|
60
|
+
- [Installation](#installation)
|
|
61
|
+
- [Quick Start](#quick-start)
|
|
62
|
+
- [Documentation](#documentation)
|
|
63
|
+
- [Requirements](#requirements)
|
|
64
|
+
- [Development](#development)
|
|
65
|
+
- [Testing](#testing)
|
|
66
|
+
- [Contributing](#contributing)
|
|
67
|
+
- [License](#license)
|
|
68
|
+
|
|
69
|
+
## Features
|
|
70
|
+
|
|
71
|
+
### 🚀 High-Performance Bulk Operations
|
|
72
|
+
|
|
73
|
+
- **Multithreaded Processing**:
|
|
74
|
+
Parallel execution of database operations for maximum speed
|
|
75
|
+
- **Automatic Chunking**:
|
|
76
|
+
Configurable batch sizes (default: 1000) for memory-efficient processing
|
|
77
|
+
- **Transaction Safety**:
|
|
78
|
+
Atomic operations with intelligent transaction management
|
|
79
|
+
- **Dependency Resolution**:
|
|
80
|
+
Automatic topological sorting for foreign key relationships
|
|
81
|
+
|
|
82
|
+
### 🛠️ Database Utilities
|
|
83
|
+
|
|
84
|
+
- **Bulk Create/Update/Delete**: Process thousands of records efficiently
|
|
85
|
+
- **Deletion Simulation**:
|
|
86
|
+
Preview cascade effects before executing destructive operations
|
|
87
|
+
- **Bulk Comparison**:
|
|
88
|
+
Detect differences between datasets with field-level hashing
|
|
89
|
+
- **Raw SQL Execution**: Safe parameter binding with automatic cursor management
|
|
90
|
+
|
|
91
|
+
### 📦 Model Utilities
|
|
92
|
+
|
|
93
|
+
- **BaseModel**:
|
|
94
|
+
Abstract base with `created_at`, `updated_at`, and type-safe `meta` property
|
|
95
|
+
- **Topological Sorting**: Automatic dependency ordering for model operations
|
|
96
|
+
- **Field Introspection**: Type-safe utilities for working with model fields
|
|
97
|
+
|
|
98
|
+
### 🎯 Management Command Framework
|
|
99
|
+
|
|
100
|
+
- **ABCBaseCommand**: Template method pattern with automatic logging
|
|
101
|
+
- **ImportDataBaseCommand**: Structured data import with Polars integration
|
|
102
|
+
- **Built-in Arguments**:
|
|
103
|
+
Standard options for dry-run, batch size, threading, and more
|
|
104
|
+
- **Type Safety**: Full type hints with abstract method enforcement
|
|
105
|
+
|
|
106
|
+
## Installation
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pip install winidjango
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Or using `uv`:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
uv add winidjango
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Quick Start
|
|
119
|
+
|
|
120
|
+
### Bulk Operations
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from winidjango.src.db.bulk import bulk_create_in_steps
|
|
124
|
+
|
|
125
|
+
# Create 10,000 records in batches of 1000
|
|
126
|
+
authors = [Author(name=f"Author {i}") for i in range(10000)]
|
|
127
|
+
created = bulk_create_in_steps(Author, authors, step=1000)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Automatic Dependency Resolution
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from winidjango.src.db.bulk import bulk_create_bulks_in_steps
|
|
134
|
+
|
|
135
|
+
# Create related models in correct order automatically
|
|
136
|
+
results = bulk_create_bulks_in_steps({
|
|
137
|
+
Author: authors,
|
|
138
|
+
Book: books, # Created after Author
|
|
139
|
+
Review: reviews, # Created after Book
|
|
140
|
+
})
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Deletion Simulation
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from winidjango.src.db.bulk import simulate_bulk_deletion
|
|
147
|
+
|
|
148
|
+
# Preview what would be deleted
|
|
149
|
+
deletion_preview = simulate_bulk_deletion(Author, authors_to_delete)
|
|
150
|
+
print(f"Would delete {len(deletion_preview[Author])} authors")
|
|
151
|
+
print(f"Would cascade delete {len(deletion_preview[Book])} books")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Custom Management Command
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from winidjango.src.commands.base.base import ABCBaseCommand
|
|
158
|
+
from argparse import ArgumentParser
|
|
159
|
+
|
|
160
|
+
class MyCommand(ABCBaseCommand):
|
|
161
|
+
def add_command_arguments(self, parser: ArgumentParser) -> None:
|
|
162
|
+
parser.add_argument('--input-file', type=str, required=True)
|
|
163
|
+
|
|
164
|
+
def handle_command(self) -> None:
|
|
165
|
+
input_file = self.get_option('input_file')
|
|
166
|
+
dry_run = self.get_option('dry_run') # Built-in
|
|
167
|
+
|
|
168
|
+
if dry_run:
|
|
169
|
+
self.stdout.write('Dry run mode')
|
|
170
|
+
|
|
171
|
+
# Your logic here
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Data Import Command
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from winidjango.src.commands.import_data import ImportDataBaseCommand
|
|
178
|
+
import polars as pl
|
|
179
|
+
|
|
180
|
+
class ImportUsersCommand(ImportDataBaseCommand):
|
|
181
|
+
def handle_import(self) -> pl.DataFrame:
|
|
182
|
+
return pl.read_csv("users.csv")
|
|
183
|
+
|
|
184
|
+
def get_cleaning_df_cls(self) -> type[CleaningDF]:
|
|
185
|
+
return MyCleaningDF
|
|
186
|
+
|
|
187
|
+
def get_bulks_by_model(
|
|
188
|
+
self, df: pl.DataFrame
|
|
189
|
+
) -> dict[type[Model], Iterable[Model]]:
|
|
190
|
+
users = [User(name=row["name"]) for row in df.iter_rows(named=True)]
|
|
191
|
+
return {User: users}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Documentation
|
|
195
|
+
|
|
196
|
+
Comprehensive documentation is available in the [`docs/`](docs/) directory:
|
|
197
|
+
|
|
198
|
+
- **[Database Utilities](docs/db.md)**
|
|
199
|
+
- Bulk operations, model utilities, and SQL helpers
|
|
200
|
+
- **[Management Commands](docs/commands.md)** - Command framework and data import patterns
|
|
201
|
+
- **[API Reference](docs/index.md)** - Complete API documentation
|
|
202
|
+
|
|
203
|
+
## Requirements
|
|
204
|
+
|
|
205
|
+
- **Python**: 3.12+
|
|
206
|
+
- **Django**: Compatible with modern Django versions
|
|
207
|
+
- **Dependencies**:
|
|
208
|
+
- `django`
|
|
209
|
+
- `django-stubs-ext`
|
|
210
|
+
- `winiutils`
|
|
211
|
+
|
|
212
|
+
## Development
|
|
213
|
+
|
|
214
|
+
### Setup
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# Clone the repository
|
|
218
|
+
git clone https://github.com/Winipedia/winidjango.git
|
|
219
|
+
cd winidjango
|
|
220
|
+
|
|
221
|
+
# Install dependencies
|
|
222
|
+
uv sync
|
|
223
|
+
|
|
224
|
+
# Install pre-commit hooks
|
|
225
|
+
pre-commit install
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Code Quality
|
|
229
|
+
|
|
230
|
+
This project uses:
|
|
231
|
+
|
|
232
|
+
- **mypy**: Strict type checking
|
|
233
|
+
- **ruff**: Linting and formatting
|
|
234
|
+
- **bandit**: Security analysis
|
|
235
|
+
- **pytest**: Testing framework
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# Run type checking
|
|
239
|
+
mypy .
|
|
240
|
+
|
|
241
|
+
# Run linting
|
|
242
|
+
ruff check .
|
|
243
|
+
|
|
244
|
+
# Run security checks
|
|
245
|
+
bandit -r winidjango
|
|
246
|
+
|
|
247
|
+
# Format code
|
|
248
|
+
ruff format .
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Testing
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
# Run all tests
|
|
255
|
+
pytest
|
|
256
|
+
|
|
257
|
+
# Run with coverage
|
|
258
|
+
pytest --cov=winidjango
|
|
259
|
+
|
|
260
|
+
# Run specific test file
|
|
261
|
+
pytest tests/test_winidjango/test_src/test_db/test_bulk.py
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Contributing
|
|
265
|
+
|
|
266
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
267
|
+
For major changes, please open an issue first
|
|
268
|
+
to discuss what you would like to change.
|
|
269
|
+
|
|
270
|
+
1. Fork the repository
|
|
271
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
272
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
273
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
274
|
+
5. Open a Pull Request
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
This project is licensed under the MIT License,
|
|
279
|
+
see the [LICENSE](LICENSE) file for details.
|
|
280
|
+
|
|
281
|
+
## Acknowledgments
|
|
282
|
+
|
|
283
|
+
- Built with [pyrig](https://github.com/Winipedia/pyrig) - Python project scaffolding tool
|
|
284
|
+
- Integrates with [winiutils](https://github.com/Winipedia/winiutils) - General Python utilities
|
|
285
|
+
|
|
286
|
+
---
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# winidjango
|
|
2
|
+
|
|
3
|
+
<!-- tooling -->
|
|
4
|
+
[](https://github.com/Winipedia/pyrig)
|
|
5
|
+
[](https://github.com/astral-sh/uv)
|
|
6
|
+
[](https://podman.io/)
|
|
7
|
+
[](https://pre-commit.com/)
|
|
8
|
+
[](https://www.mkdocs.org/)
|
|
9
|
+
<!-- code-quality -->
|
|
10
|
+
[](https://github.com/astral-sh/ruff)
|
|
11
|
+
[](https://github.com/astral-sh/ty)
|
|
12
|
+
[](https://github.com/PyCQA/bandit)
|
|
13
|
+
[](https://pytest.org/)
|
|
14
|
+
[](https://codecov.io/gh/Winipedia/winidjango)
|
|
15
|
+
[](https://github.com/rvben/rumdl)
|
|
16
|
+
<!-- package-info -->
|
|
17
|
+
[](https://pypi.org/project/winidjango)
|
|
18
|
+
[](https://www.python.org/)
|
|
19
|
+
[](https://github.com/Winipedia/winidjango/blob/main/LICENSE)
|
|
20
|
+
<!-- ci/cd -->
|
|
21
|
+
[](https://github.com/Winipedia/winidjango/actions/workflows/health_check.yaml)
|
|
22
|
+
[](https://github.com/Winipedia/winidjango/actions/workflows/release.yaml)
|
|
23
|
+
<!-- documentation -->
|
|
24
|
+
[](https://Winipedia.github.io/winidjango)
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
> A utils package for django
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Table of Contents
|
|
33
|
+
|
|
34
|
+
- [Features](#features)
|
|
35
|
+
- [Installation](#installation)
|
|
36
|
+
- [Quick Start](#quick-start)
|
|
37
|
+
- [Documentation](#documentation)
|
|
38
|
+
- [Requirements](#requirements)
|
|
39
|
+
- [Development](#development)
|
|
40
|
+
- [Testing](#testing)
|
|
41
|
+
- [Contributing](#contributing)
|
|
42
|
+
- [License](#license)
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
### 🚀 High-Performance Bulk Operations
|
|
47
|
+
|
|
48
|
+
- **Multithreaded Processing**:
|
|
49
|
+
Parallel execution of database operations for maximum speed
|
|
50
|
+
- **Automatic Chunking**:
|
|
51
|
+
Configurable batch sizes (default: 1000) for memory-efficient processing
|
|
52
|
+
- **Transaction Safety**:
|
|
53
|
+
Atomic operations with intelligent transaction management
|
|
54
|
+
- **Dependency Resolution**:
|
|
55
|
+
Automatic topological sorting for foreign key relationships
|
|
56
|
+
|
|
57
|
+
### 🛠️ Database Utilities
|
|
58
|
+
|
|
59
|
+
- **Bulk Create/Update/Delete**: Process thousands of records efficiently
|
|
60
|
+
- **Deletion Simulation**:
|
|
61
|
+
Preview cascade effects before executing destructive operations
|
|
62
|
+
- **Bulk Comparison**:
|
|
63
|
+
Detect differences between datasets with field-level hashing
|
|
64
|
+
- **Raw SQL Execution**: Safe parameter binding with automatic cursor management
|
|
65
|
+
|
|
66
|
+
### 📦 Model Utilities
|
|
67
|
+
|
|
68
|
+
- **BaseModel**:
|
|
69
|
+
Abstract base with `created_at`, `updated_at`, and type-safe `meta` property
|
|
70
|
+
- **Topological Sorting**: Automatic dependency ordering for model operations
|
|
71
|
+
- **Field Introspection**: Type-safe utilities for working with model fields
|
|
72
|
+
|
|
73
|
+
### 🎯 Management Command Framework
|
|
74
|
+
|
|
75
|
+
- **ABCBaseCommand**: Template method pattern with automatic logging
|
|
76
|
+
- **ImportDataBaseCommand**: Structured data import with Polars integration
|
|
77
|
+
- **Built-in Arguments**:
|
|
78
|
+
Standard options for dry-run, batch size, threading, and more
|
|
79
|
+
- **Type Safety**: Full type hints with abstract method enforcement
|
|
80
|
+
|
|
81
|
+
## Installation
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install winidjango
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Or using `uv`:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
uv add winidjango
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Quick Start
|
|
94
|
+
|
|
95
|
+
### Bulk Operations
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from winidjango.src.db.bulk import bulk_create_in_steps
|
|
99
|
+
|
|
100
|
+
# Create 10,000 records in batches of 1000
|
|
101
|
+
authors = [Author(name=f"Author {i}") for i in range(10000)]
|
|
102
|
+
created = bulk_create_in_steps(Author, authors, step=1000)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Automatic Dependency Resolution
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from winidjango.src.db.bulk import bulk_create_bulks_in_steps
|
|
109
|
+
|
|
110
|
+
# Create related models in correct order automatically
|
|
111
|
+
results = bulk_create_bulks_in_steps({
|
|
112
|
+
Author: authors,
|
|
113
|
+
Book: books, # Created after Author
|
|
114
|
+
Review: reviews, # Created after Book
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Deletion Simulation
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from winidjango.src.db.bulk import simulate_bulk_deletion
|
|
122
|
+
|
|
123
|
+
# Preview what would be deleted
|
|
124
|
+
deletion_preview = simulate_bulk_deletion(Author, authors_to_delete)
|
|
125
|
+
print(f"Would delete {len(deletion_preview[Author])} authors")
|
|
126
|
+
print(f"Would cascade delete {len(deletion_preview[Book])} books")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Custom Management Command
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from winidjango.src.commands.base.base import ABCBaseCommand
|
|
133
|
+
from argparse import ArgumentParser
|
|
134
|
+
|
|
135
|
+
class MyCommand(ABCBaseCommand):
|
|
136
|
+
def add_command_arguments(self, parser: ArgumentParser) -> None:
|
|
137
|
+
parser.add_argument('--input-file', type=str, required=True)
|
|
138
|
+
|
|
139
|
+
def handle_command(self) -> None:
|
|
140
|
+
input_file = self.get_option('input_file')
|
|
141
|
+
dry_run = self.get_option('dry_run') # Built-in
|
|
142
|
+
|
|
143
|
+
if dry_run:
|
|
144
|
+
self.stdout.write('Dry run mode')
|
|
145
|
+
|
|
146
|
+
# Your logic here
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Data Import Command
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from winidjango.src.commands.import_data import ImportDataBaseCommand
|
|
153
|
+
import polars as pl
|
|
154
|
+
|
|
155
|
+
class ImportUsersCommand(ImportDataBaseCommand):
|
|
156
|
+
def handle_import(self) -> pl.DataFrame:
|
|
157
|
+
return pl.read_csv("users.csv")
|
|
158
|
+
|
|
159
|
+
def get_cleaning_df_cls(self) -> type[CleaningDF]:
|
|
160
|
+
return MyCleaningDF
|
|
161
|
+
|
|
162
|
+
def get_bulks_by_model(
|
|
163
|
+
self, df: pl.DataFrame
|
|
164
|
+
) -> dict[type[Model], Iterable[Model]]:
|
|
165
|
+
users = [User(name=row["name"]) for row in df.iter_rows(named=True)]
|
|
166
|
+
return {User: users}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Documentation
|
|
170
|
+
|
|
171
|
+
Comprehensive documentation is available in the [`docs/`](docs/) directory:
|
|
172
|
+
|
|
173
|
+
- **[Database Utilities](docs/db.md)**
|
|
174
|
+
- Bulk operations, model utilities, and SQL helpers
|
|
175
|
+
- **[Management Commands](docs/commands.md)** - Command framework and data import patterns
|
|
176
|
+
- **[API Reference](docs/index.md)** - Complete API documentation
|
|
177
|
+
|
|
178
|
+
## Requirements
|
|
179
|
+
|
|
180
|
+
- **Python**: 3.12+
|
|
181
|
+
- **Django**: Compatible with modern Django versions
|
|
182
|
+
- **Dependencies**:
|
|
183
|
+
- `django`
|
|
184
|
+
- `django-stubs-ext`
|
|
185
|
+
- `winiutils`
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
### Setup
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Clone the repository
|
|
193
|
+
git clone https://github.com/Winipedia/winidjango.git
|
|
194
|
+
cd winidjango
|
|
195
|
+
|
|
196
|
+
# Install dependencies
|
|
197
|
+
uv sync
|
|
198
|
+
|
|
199
|
+
# Install pre-commit hooks
|
|
200
|
+
pre-commit install
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Code Quality
|
|
204
|
+
|
|
205
|
+
This project uses:
|
|
206
|
+
|
|
207
|
+
- **mypy**: Strict type checking
|
|
208
|
+
- **ruff**: Linting and formatting
|
|
209
|
+
- **bandit**: Security analysis
|
|
210
|
+
- **pytest**: Testing framework
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# Run type checking
|
|
214
|
+
mypy .
|
|
215
|
+
|
|
216
|
+
# Run linting
|
|
217
|
+
ruff check .
|
|
218
|
+
|
|
219
|
+
# Run security checks
|
|
220
|
+
bandit -r winidjango
|
|
221
|
+
|
|
222
|
+
# Format code
|
|
223
|
+
ruff format .
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Testing
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# Run all tests
|
|
230
|
+
pytest
|
|
231
|
+
|
|
232
|
+
# Run with coverage
|
|
233
|
+
pytest --cov=winidjango
|
|
234
|
+
|
|
235
|
+
# Run specific test file
|
|
236
|
+
pytest tests/test_winidjango/test_src/test_db/test_bulk.py
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Contributing
|
|
240
|
+
|
|
241
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
242
|
+
For major changes, please open an issue first
|
|
243
|
+
to discuss what you would like to change.
|
|
244
|
+
|
|
245
|
+
1. Fork the repository
|
|
246
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
247
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
248
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
249
|
+
5. Open a Pull Request
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
This project is licensed under the MIT License,
|
|
254
|
+
see the [LICENSE](LICENSE) file for details.
|
|
255
|
+
|
|
256
|
+
## Acknowledgments
|
|
257
|
+
|
|
258
|
+
- Built with [pyrig](https://github.com/Winipedia/pyrig) - Python project scaffolding tool
|
|
259
|
+
- Integrates with [winiutils](https://github.com/Winipedia/winiutils) - General Python utilities
|
|
260
|
+
|
|
261
|
+
---
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "winidjango"
|
|
3
|
+
version = "2.0.49"
|
|
4
|
+
description = "A utils package for django"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Winipedia"},
|
|
7
|
+
]
|
|
8
|
+
license = "MIT"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"django",
|
|
13
|
+
"django-stubs-ext",
|
|
14
|
+
"winiutils",
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
]
|
|
23
|
+
license-files = [
|
|
24
|
+
"LICENSE",
|
|
25
|
+
]
|
|
26
|
+
maintainers = [
|
|
27
|
+
{name = "Winipedia"},
|
|
28
|
+
]
|
|
29
|
+
keywords = []
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
winidjango = "pyrig.dev.cli.cli:main"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/Winipedia/winidjango"
|
|
36
|
+
Documentation = "https://Winipedia.github.io/winidjango"
|
|
37
|
+
Source = "https://github.com/Winipedia/winidjango"
|
|
38
|
+
Issues = "https://github.com/Winipedia/winidjango/issues"
|
|
39
|
+
Changelog = "https://github.com/Winipedia/winidjango/releases"
|
|
40
|
+
|
|
41
|
+
[dependency-groups]
|
|
42
|
+
dev = [
|
|
43
|
+
"django-stubs",
|
|
44
|
+
"pyrig-dev",
|
|
45
|
+
"pytest-django",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[build-system]
|
|
49
|
+
requires = [
|
|
50
|
+
"uv_build",
|
|
51
|
+
]
|
|
52
|
+
build-backend = "uv_build"
|
|
53
|
+
|
|
54
|
+
[tool.uv.build-backend]
|
|
55
|
+
module-name = "winidjango"
|
|
56
|
+
module-root = ""
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
exclude = [
|
|
60
|
+
".*",
|
|
61
|
+
"**/migrations/*.py",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint]
|
|
65
|
+
select = [
|
|
66
|
+
"ALL",
|
|
67
|
+
]
|
|
68
|
+
ignore = [
|
|
69
|
+
"D203",
|
|
70
|
+
"D213",
|
|
71
|
+
"COM812",
|
|
72
|
+
"ANN401",
|
|
73
|
+
]
|
|
74
|
+
fixable = [
|
|
75
|
+
"ALL",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint.per-file-ignores]
|
|
79
|
+
"tests/**/*.py" = [
|
|
80
|
+
"S101",
|
|
81
|
+
]
|
|
82
|
+
"**/tests/**/*.py" = [
|
|
83
|
+
"S101",
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
[tool.ruff.lint.pydocstyle]
|
|
87
|
+
convention = "google"
|
|
88
|
+
|
|
89
|
+
[tool.mypy]
|
|
90
|
+
strict = true
|
|
91
|
+
warn_unreachable = true
|
|
92
|
+
show_error_codes = true
|
|
93
|
+
files = "."
|
|
94
|
+
|
|
95
|
+
[tool.pytest.ini_options]
|
|
96
|
+
testpaths = [
|
|
97
|
+
"tests",
|
|
98
|
+
]
|
|
99
|
+
addopts = "--cov=winidjango --cov-report=term-missing --cov-fail-under=90"
|
|
100
|
+
|
|
101
|
+
[tool.bandit]
|
|
102
|
+
exclude_dirs = [
|
|
103
|
+
".*",
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
[tool.bandit.assert_used]
|
|
107
|
+
skips = [
|
|
108
|
+
"*/tests/*.py",
|
|
109
|
+
"*test_*.py",
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
[tool.ty.terminal]
|
|
113
|
+
error-on-warning = true
|
|
114
|
+
|
|
115
|
+
[tool.rumdl]
|
|
116
|
+
respect_gitignore = true
|