django-dict-form 0.1.0__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.
- django_dict_form-0.1.0/LICENSE +21 -0
- django_dict_form-0.1.0/PKG-INFO +148 -0
- django_dict_form-0.1.0/README.md +129 -0
- django_dict_form-0.1.0/django_dict_form/__init__.py +5 -0
- django_dict_form-0.1.0/django_dict_form/apps.py +6 -0
- django_dict_form-0.1.0/django_dict_form/form.py +40 -0
- django_dict_form-0.1.0/django_dict_form/models.py +17 -0
- django_dict_form-0.1.0/django_dict_form/urls.py +5 -0
- django_dict_form-0.1.0/django_dict_form.egg-info/PKG-INFO +148 -0
- django_dict_form-0.1.0/django_dict_form.egg-info/SOURCES.txt +15 -0
- django_dict_form-0.1.0/django_dict_form.egg-info/dependency_links.txt +1 -0
- django_dict_form-0.1.0/django_dict_form.egg-info/requires.txt +1 -0
- django_dict_form-0.1.0/django_dict_form.egg-info/top_level.txt +1 -0
- django_dict_form-0.1.0/pyproject.toml +47 -0
- django_dict_form-0.1.0/setup.cfg +4 -0
- django_dict_form-0.1.0/tests/test_dict_form_instance.py +158 -0
- django_dict_form-0.1.0/tests/tests.py +639 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gleb Uvarov
|
|
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,148 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-dict-form
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Is a lightweight extension for Django Forms that adds serialization
|
|
5
|
+
Author-email: Gleb Uvarov <ugs1996@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Dradisen/django_dict_form
|
|
8
|
+
Project-URL: Repository, https://github.com/Dradisen/django_dict_form
|
|
9
|
+
Project-URL: Issues, https://github.com/Dradisen/django_dict_form/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/Dradisen/django_dict_form#readme
|
|
11
|
+
Keywords: django,django-forms
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: django>=3.2
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# django-dict-form
|
|
21
|
+
|
|
22
|
+
Lightweight Django Forms extension. Adds `as_dict()` — serializes form definitions to Python dicts / JSON, making forms easier to integrate with REST APIs, SPA frontends (React/Vue), dynamic UI generators, and low-code systems.
|
|
23
|
+
|
|
24
|
+
Extends standard Django form rendering (`as_p`, `as_table`, `as_ul`) with machine-readable field metadata, validation rules, and widget configuration.
|
|
25
|
+
|
|
26
|
+
## When is this convenient?
|
|
27
|
+
|
|
28
|
+
Write adapters to UI/UX components once — forms auto-generate on frontend. Backend edits propagate automatically. No manual frontend form duplication.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- Serialize Django forms to Python dictionaries
|
|
33
|
+
- Useful for dynamic frontend rendering
|
|
34
|
+
- Simplifies API-driven form generation
|
|
35
|
+
- Lightweight and framework-friendly
|
|
36
|
+
- Compatible with standard Django Forms
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install django-dict-form
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from django_dict_form.form import DictForm
|
|
48
|
+
from django import forms
|
|
49
|
+
|
|
50
|
+
class ContactForm(DictForm):
|
|
51
|
+
name = forms.CharField(max_length=100)
|
|
52
|
+
email = forms.EmailField()
|
|
53
|
+
message = forms.CharField(widget=forms.Textarea)
|
|
54
|
+
|
|
55
|
+
form = ContactForm()
|
|
56
|
+
data = form.as_dict()
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Output:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"name": {
|
|
64
|
+
"label": null,
|
|
65
|
+
"required": true,
|
|
66
|
+
"disabled": false,
|
|
67
|
+
"help_text": "",
|
|
68
|
+
"initial": null,
|
|
69
|
+
"show_hidden_initial": false,
|
|
70
|
+
"label_suffix": null,
|
|
71
|
+
"widget": {
|
|
72
|
+
"name": "TextInput",
|
|
73
|
+
"type": "text",
|
|
74
|
+
"is_hidden": false,
|
|
75
|
+
"required": true,
|
|
76
|
+
"choices": [],
|
|
77
|
+
"attrs": {"maxlength": "100"}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Mixin Usage
|
|
84
|
+
|
|
85
|
+
Use `RenderableDictFormMixin` to add `as_dict()` to any existing form class:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from django_dict_form.form import RenderableDictFormMixin
|
|
89
|
+
from django import forms
|
|
90
|
+
|
|
91
|
+
class MyForm(forms.Form, RenderableDictFormMixin):
|
|
92
|
+
field = forms.CharField()
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## `as_dict()` Output Schema
|
|
96
|
+
|
|
97
|
+
Each field produces:
|
|
98
|
+
|
|
99
|
+
| Key | Type | Description |
|
|
100
|
+
|-----|------|-------------|
|
|
101
|
+
| `label` | `str \| null` | Field label |
|
|
102
|
+
| `label_suffix` | `str \| null` | Label suffix |
|
|
103
|
+
| `required` | `bool` | Whether field is required |
|
|
104
|
+
| `disabled` | `bool` | Whether field is disabled |
|
|
105
|
+
| `help_text` | `str` | Help text |
|
|
106
|
+
| `initial` | `any` | Default value |
|
|
107
|
+
| `show_hidden_initial` | `bool` | Show hidden initial widget |
|
|
108
|
+
| `widget` | `dict` | Widget metadata (see below) |
|
|
109
|
+
|
|
110
|
+
Widget dict:
|
|
111
|
+
|
|
112
|
+
| Key | Type | Description |
|
|
113
|
+
|-----|------|-------------|
|
|
114
|
+
| `name` | `str` | Widget class name (e.g. `TextInput`) |
|
|
115
|
+
| `type` | `str \| null` | HTML input type (e.g. `text`, `email`, `number`) |
|
|
116
|
+
| `is_hidden` | `bool` | Whether widget is hidden |
|
|
117
|
+
| `required` | `bool` | Widget-level required |
|
|
118
|
+
| `choices` | `list[{value, name}]` | Options for select widgets |
|
|
119
|
+
| `attrs` | `dict` | HTML attributes (e.g. `maxlength`, `min`, `max`) |
|
|
120
|
+
|
|
121
|
+
## Supported Fields
|
|
122
|
+
|
|
123
|
+
| Field | Widget | Notes |
|
|
124
|
+
|-------|--------|-------|
|
|
125
|
+
| `CharField` | `TextInput` | `maxlength`, `minlength` in attrs |
|
|
126
|
+
| `IntegerField` | `NumberInput` | `min`, `max` in attrs |
|
|
127
|
+
| `FloatField` | `NumberInput` | `step: any` in attrs |
|
|
128
|
+
| `EmailField` | `EmailInput` | `maxlength: 320` default |
|
|
129
|
+
| `URLField` | `URLInput` | |
|
|
130
|
+
| `BooleanField` | `CheckboxInput` | |
|
|
131
|
+
| `ChoiceField` | `Select` | choices serialized |
|
|
132
|
+
| `DateField` | `DateInput` | |
|
|
133
|
+
| `TimeField` | `TimeInput` | |
|
|
134
|
+
| `DateTimeField` | `DateTimeInput` | |
|
|
135
|
+
| `DurationField` | `TextInput` | |
|
|
136
|
+
| `RegexField` | `TextInput` | |
|
|
137
|
+
| `UUIDField` | `TextInput` | |
|
|
138
|
+
|
|
139
|
+
Custom widgets supported — pass any widget instance, choices and attrs extracted automatically.
|
|
140
|
+
|
|
141
|
+
## Requirements
|
|
142
|
+
|
|
143
|
+
- Python >= 3.11.15
|
|
144
|
+
- Django >= 3.2
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
MIT — [Gleb Uvarov](https://github.com/Dradisen)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# django-dict-form
|
|
2
|
+
|
|
3
|
+
Lightweight Django Forms extension. Adds `as_dict()` — serializes form definitions to Python dicts / JSON, making forms easier to integrate with REST APIs, SPA frontends (React/Vue), dynamic UI generators, and low-code systems.
|
|
4
|
+
|
|
5
|
+
Extends standard Django form rendering (`as_p`, `as_table`, `as_ul`) with machine-readable field metadata, validation rules, and widget configuration.
|
|
6
|
+
|
|
7
|
+
## When is this convenient?
|
|
8
|
+
|
|
9
|
+
Write adapters to UI/UX components once — forms auto-generate on frontend. Backend edits propagate automatically. No manual frontend form duplication.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Serialize Django forms to Python dictionaries
|
|
14
|
+
- Useful for dynamic frontend rendering
|
|
15
|
+
- Simplifies API-driven form generation
|
|
16
|
+
- Lightweight and framework-friendly
|
|
17
|
+
- Compatible with standard Django Forms
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install django-dict-form
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from django_dict_form.form import DictForm
|
|
29
|
+
from django import forms
|
|
30
|
+
|
|
31
|
+
class ContactForm(DictForm):
|
|
32
|
+
name = forms.CharField(max_length=100)
|
|
33
|
+
email = forms.EmailField()
|
|
34
|
+
message = forms.CharField(widget=forms.Textarea)
|
|
35
|
+
|
|
36
|
+
form = ContactForm()
|
|
37
|
+
data = form.as_dict()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Output:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"name": {
|
|
45
|
+
"label": null,
|
|
46
|
+
"required": true,
|
|
47
|
+
"disabled": false,
|
|
48
|
+
"help_text": "",
|
|
49
|
+
"initial": null,
|
|
50
|
+
"show_hidden_initial": false,
|
|
51
|
+
"label_suffix": null,
|
|
52
|
+
"widget": {
|
|
53
|
+
"name": "TextInput",
|
|
54
|
+
"type": "text",
|
|
55
|
+
"is_hidden": false,
|
|
56
|
+
"required": true,
|
|
57
|
+
"choices": [],
|
|
58
|
+
"attrs": {"maxlength": "100"}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Mixin Usage
|
|
65
|
+
|
|
66
|
+
Use `RenderableDictFormMixin` to add `as_dict()` to any existing form class:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from django_dict_form.form import RenderableDictFormMixin
|
|
70
|
+
from django import forms
|
|
71
|
+
|
|
72
|
+
class MyForm(forms.Form, RenderableDictFormMixin):
|
|
73
|
+
field = forms.CharField()
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## `as_dict()` Output Schema
|
|
77
|
+
|
|
78
|
+
Each field produces:
|
|
79
|
+
|
|
80
|
+
| Key | Type | Description |
|
|
81
|
+
|-----|------|-------------|
|
|
82
|
+
| `label` | `str \| null` | Field label |
|
|
83
|
+
| `label_suffix` | `str \| null` | Label suffix |
|
|
84
|
+
| `required` | `bool` | Whether field is required |
|
|
85
|
+
| `disabled` | `bool` | Whether field is disabled |
|
|
86
|
+
| `help_text` | `str` | Help text |
|
|
87
|
+
| `initial` | `any` | Default value |
|
|
88
|
+
| `show_hidden_initial` | `bool` | Show hidden initial widget |
|
|
89
|
+
| `widget` | `dict` | Widget metadata (see below) |
|
|
90
|
+
|
|
91
|
+
Widget dict:
|
|
92
|
+
|
|
93
|
+
| Key | Type | Description |
|
|
94
|
+
|-----|------|-------------|
|
|
95
|
+
| `name` | `str` | Widget class name (e.g. `TextInput`) |
|
|
96
|
+
| `type` | `str \| null` | HTML input type (e.g. `text`, `email`, `number`) |
|
|
97
|
+
| `is_hidden` | `bool` | Whether widget is hidden |
|
|
98
|
+
| `required` | `bool` | Widget-level required |
|
|
99
|
+
| `choices` | `list[{value, name}]` | Options for select widgets |
|
|
100
|
+
| `attrs` | `dict` | HTML attributes (e.g. `maxlength`, `min`, `max`) |
|
|
101
|
+
|
|
102
|
+
## Supported Fields
|
|
103
|
+
|
|
104
|
+
| Field | Widget | Notes |
|
|
105
|
+
|-------|--------|-------|
|
|
106
|
+
| `CharField` | `TextInput` | `maxlength`, `minlength` in attrs |
|
|
107
|
+
| `IntegerField` | `NumberInput` | `min`, `max` in attrs |
|
|
108
|
+
| `FloatField` | `NumberInput` | `step: any` in attrs |
|
|
109
|
+
| `EmailField` | `EmailInput` | `maxlength: 320` default |
|
|
110
|
+
| `URLField` | `URLInput` | |
|
|
111
|
+
| `BooleanField` | `CheckboxInput` | |
|
|
112
|
+
| `ChoiceField` | `Select` | choices serialized |
|
|
113
|
+
| `DateField` | `DateInput` | |
|
|
114
|
+
| `TimeField` | `TimeInput` | |
|
|
115
|
+
| `DateTimeField` | `DateTimeInput` | |
|
|
116
|
+
| `DurationField` | `TextInput` | |
|
|
117
|
+
| `RegexField` | `TextInput` | |
|
|
118
|
+
| `UUIDField` | `TextInput` | |
|
|
119
|
+
|
|
120
|
+
Custom widgets supported — pass any widget instance, choices and attrs extracted automatically.
|
|
121
|
+
|
|
122
|
+
## Requirements
|
|
123
|
+
|
|
124
|
+
- Python >= 3.11.15
|
|
125
|
+
- Django >= 3.2
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT — [Gleb Uvarov](https://github.com/Dradisen)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from django import forms
|
|
2
|
+
from django.forms import Widget
|
|
3
|
+
from typing import Iterable
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def extract_choices(choices: Iterable[tuple]) -> list[dict]:
|
|
7
|
+
return [{"value": str(key), "name": value} for key, value in choices]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _widget_as_dict(widget: Widget) -> dict:
|
|
11
|
+
return {
|
|
12
|
+
"name": widget.__class__.__name__,
|
|
13
|
+
"is_hidden": widget.is_hidden,
|
|
14
|
+
"required": widget.is_required,
|
|
15
|
+
"type": getattr(widget, "input_type", None),
|
|
16
|
+
"choices": extract_choices(getattr(widget, "choices", [])),
|
|
17
|
+
"attrs": getattr(widget, "attrs", None),
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class RenderableDictFormMixin:
|
|
22
|
+
fields: dict
|
|
23
|
+
|
|
24
|
+
def as_dict(self) -> dict[str, dict]:
|
|
25
|
+
return {
|
|
26
|
+
field_name: {
|
|
27
|
+
"label": field.label,
|
|
28
|
+
"label_suffix": field.label_suffix,
|
|
29
|
+
"required": field.required,
|
|
30
|
+
"disabled": field.disabled,
|
|
31
|
+
"help_text": field.help_text,
|
|
32
|
+
"initial": field.initial,
|
|
33
|
+
"show_hidden_initial": field.show_hidden_initial,
|
|
34
|
+
"widget": _widget_as_dict(field.widget),
|
|
35
|
+
}
|
|
36
|
+
for field_name, field in self.fields.items()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class DictForm(forms.Form, RenderableDictFormMixin): ...
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from django.forms import Widget
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
@dataclass
|
|
6
|
+
class MetaFieldJson:
|
|
7
|
+
widget: Widget
|
|
8
|
+
required: bool
|
|
9
|
+
disabled: bool
|
|
10
|
+
help_text: str
|
|
11
|
+
max_length: int|None
|
|
12
|
+
min_length: int|None
|
|
13
|
+
choices: list[dict]
|
|
14
|
+
label: str
|
|
15
|
+
type: str
|
|
16
|
+
name: str
|
|
17
|
+
attrs: dict
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-dict-form
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Is a lightweight extension for Django Forms that adds serialization
|
|
5
|
+
Author-email: Gleb Uvarov <ugs1996@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Dradisen/django_dict_form
|
|
8
|
+
Project-URL: Repository, https://github.com/Dradisen/django_dict_form
|
|
9
|
+
Project-URL: Issues, https://github.com/Dradisen/django_dict_form/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/Dradisen/django_dict_form#readme
|
|
11
|
+
Keywords: django,django-forms
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: django>=3.2
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# django-dict-form
|
|
21
|
+
|
|
22
|
+
Lightweight Django Forms extension. Adds `as_dict()` — serializes form definitions to Python dicts / JSON, making forms easier to integrate with REST APIs, SPA frontends (React/Vue), dynamic UI generators, and low-code systems.
|
|
23
|
+
|
|
24
|
+
Extends standard Django form rendering (`as_p`, `as_table`, `as_ul`) with machine-readable field metadata, validation rules, and widget configuration.
|
|
25
|
+
|
|
26
|
+
## When is this convenient?
|
|
27
|
+
|
|
28
|
+
Write adapters to UI/UX components once — forms auto-generate on frontend. Backend edits propagate automatically. No manual frontend form duplication.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- Serialize Django forms to Python dictionaries
|
|
33
|
+
- Useful for dynamic frontend rendering
|
|
34
|
+
- Simplifies API-driven form generation
|
|
35
|
+
- Lightweight and framework-friendly
|
|
36
|
+
- Compatible with standard Django Forms
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install django-dict-form
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from django_dict_form.form import DictForm
|
|
48
|
+
from django import forms
|
|
49
|
+
|
|
50
|
+
class ContactForm(DictForm):
|
|
51
|
+
name = forms.CharField(max_length=100)
|
|
52
|
+
email = forms.EmailField()
|
|
53
|
+
message = forms.CharField(widget=forms.Textarea)
|
|
54
|
+
|
|
55
|
+
form = ContactForm()
|
|
56
|
+
data = form.as_dict()
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Output:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"name": {
|
|
64
|
+
"label": null,
|
|
65
|
+
"required": true,
|
|
66
|
+
"disabled": false,
|
|
67
|
+
"help_text": "",
|
|
68
|
+
"initial": null,
|
|
69
|
+
"show_hidden_initial": false,
|
|
70
|
+
"label_suffix": null,
|
|
71
|
+
"widget": {
|
|
72
|
+
"name": "TextInput",
|
|
73
|
+
"type": "text",
|
|
74
|
+
"is_hidden": false,
|
|
75
|
+
"required": true,
|
|
76
|
+
"choices": [],
|
|
77
|
+
"attrs": {"maxlength": "100"}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Mixin Usage
|
|
84
|
+
|
|
85
|
+
Use `RenderableDictFormMixin` to add `as_dict()` to any existing form class:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from django_dict_form.form import RenderableDictFormMixin
|
|
89
|
+
from django import forms
|
|
90
|
+
|
|
91
|
+
class MyForm(forms.Form, RenderableDictFormMixin):
|
|
92
|
+
field = forms.CharField()
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## `as_dict()` Output Schema
|
|
96
|
+
|
|
97
|
+
Each field produces:
|
|
98
|
+
|
|
99
|
+
| Key | Type | Description |
|
|
100
|
+
|-----|------|-------------|
|
|
101
|
+
| `label` | `str \| null` | Field label |
|
|
102
|
+
| `label_suffix` | `str \| null` | Label suffix |
|
|
103
|
+
| `required` | `bool` | Whether field is required |
|
|
104
|
+
| `disabled` | `bool` | Whether field is disabled |
|
|
105
|
+
| `help_text` | `str` | Help text |
|
|
106
|
+
| `initial` | `any` | Default value |
|
|
107
|
+
| `show_hidden_initial` | `bool` | Show hidden initial widget |
|
|
108
|
+
| `widget` | `dict` | Widget metadata (see below) |
|
|
109
|
+
|
|
110
|
+
Widget dict:
|
|
111
|
+
|
|
112
|
+
| Key | Type | Description |
|
|
113
|
+
|-----|------|-------------|
|
|
114
|
+
| `name` | `str` | Widget class name (e.g. `TextInput`) |
|
|
115
|
+
| `type` | `str \| null` | HTML input type (e.g. `text`, `email`, `number`) |
|
|
116
|
+
| `is_hidden` | `bool` | Whether widget is hidden |
|
|
117
|
+
| `required` | `bool` | Widget-level required |
|
|
118
|
+
| `choices` | `list[{value, name}]` | Options for select widgets |
|
|
119
|
+
| `attrs` | `dict` | HTML attributes (e.g. `maxlength`, `min`, `max`) |
|
|
120
|
+
|
|
121
|
+
## Supported Fields
|
|
122
|
+
|
|
123
|
+
| Field | Widget | Notes |
|
|
124
|
+
|-------|--------|-------|
|
|
125
|
+
| `CharField` | `TextInput` | `maxlength`, `minlength` in attrs |
|
|
126
|
+
| `IntegerField` | `NumberInput` | `min`, `max` in attrs |
|
|
127
|
+
| `FloatField` | `NumberInput` | `step: any` in attrs |
|
|
128
|
+
| `EmailField` | `EmailInput` | `maxlength: 320` default |
|
|
129
|
+
| `URLField` | `URLInput` | |
|
|
130
|
+
| `BooleanField` | `CheckboxInput` | |
|
|
131
|
+
| `ChoiceField` | `Select` | choices serialized |
|
|
132
|
+
| `DateField` | `DateInput` | |
|
|
133
|
+
| `TimeField` | `TimeInput` | |
|
|
134
|
+
| `DateTimeField` | `DateTimeInput` | |
|
|
135
|
+
| `DurationField` | `TextInput` | |
|
|
136
|
+
| `RegexField` | `TextInput` | |
|
|
137
|
+
| `UUIDField` | `TextInput` | |
|
|
138
|
+
|
|
139
|
+
Custom widgets supported — pass any widget instance, choices and attrs extracted automatically.
|
|
140
|
+
|
|
141
|
+
## Requirements
|
|
142
|
+
|
|
143
|
+
- Python >= 3.11.15
|
|
144
|
+
- Django >= 3.2
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
MIT — [Gleb Uvarov](https://github.com/Dradisen)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
django_dict_form/__init__.py
|
|
5
|
+
django_dict_form/apps.py
|
|
6
|
+
django_dict_form/form.py
|
|
7
|
+
django_dict_form/models.py
|
|
8
|
+
django_dict_form/urls.py
|
|
9
|
+
django_dict_form.egg-info/PKG-INFO
|
|
10
|
+
django_dict_form.egg-info/SOURCES.txt
|
|
11
|
+
django_dict_form.egg-info/dependency_links.txt
|
|
12
|
+
django_dict_form.egg-info/requires.txt
|
|
13
|
+
django_dict_form.egg-info/top_level.txt
|
|
14
|
+
tests/test_dict_form_instance.py
|
|
15
|
+
tests/tests.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
django>=3.2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
django_dict_form
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "django-dict-form"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Is a lightweight extension for Django Forms that adds serialization"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"django>=3.2",
|
|
13
|
+
]
|
|
14
|
+
license = "MIT"
|
|
15
|
+
authors = [
|
|
16
|
+
{ name = "Gleb Uvarov", email = "ugs1996@gmail.com" }
|
|
17
|
+
]
|
|
18
|
+
keywords = [
|
|
19
|
+
"django",
|
|
20
|
+
"django-forms"
|
|
21
|
+
]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Operating System :: OS Independent"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/Dradisen/django_dict_form"
|
|
29
|
+
Repository = "https://github.com/Dradisen/django_dict_form"
|
|
30
|
+
Issues = "https://github.com/Dradisen/django_dict_form/issues"
|
|
31
|
+
Documentation = "https://github.com/Dradisen/django_dict_form#readme"
|
|
32
|
+
|
|
33
|
+
[tool.ruff]
|
|
34
|
+
line-length = 100
|
|
35
|
+
target-version = "py39"
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.packages.find]
|
|
38
|
+
where = ["."]
|
|
39
|
+
include = ["django_dict_form*"]
|
|
40
|
+
|
|
41
|
+
[tool.coverage.run]
|
|
42
|
+
branch = true
|
|
43
|
+
source = ["django_dict_form"]
|
|
44
|
+
|
|
45
|
+
[tool.coverage.report]
|
|
46
|
+
show_missing = true
|
|
47
|
+
skip_covered = true
|