Skip to content

Commit 1525c99

Browse files
committed
Bump to 0.58.0.
1 parent 08e405f commit 1525c99

File tree

8 files changed

+36
-28
lines changed

8 files changed

+36
-28
lines changed

django_unicorn/static/unicorn/js/unicorn.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

django_unicorn/typer.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def _parse_bool(value):
5858

5959

6060
def get_type_hints(obj) -> Dict:
61-
"""
62-
Get type hints from an object. These get cached in a local memory cache for quicker look-up later.
61+
"""Get type hints from an object. These get cached in a local memory cache for quicker look-up later.
62+
6363
Returns:
6464
An empty dictionary if no type hints can be retrieved.
6565
"""
@@ -86,9 +86,9 @@ def get_type_hints(obj) -> Dict:
8686

8787

8888
def cast_value(type_hint, value):
89-
"""
90-
Try to cast the value based on the type hint and
89+
"""Try to cast the value based on the type hint and
9190
`django_unicorn.call_method_parser.CASTERS`.
91+
9292
Additional features:
9393
- convert `int`/`float` epoch to `datetime` or `date`
9494
- instantiate the `type_hint` class with passed-in value
@@ -147,9 +147,7 @@ def cast_value(type_hint, value):
147147

148148

149149
def cast_attribute_value(obj, name, value):
150-
"""
151-
Try to cast the value of an object's attribute based on the type hint.
152-
"""
150+
"""Try to cast the value of an object's attribute based on the type hint."""
153151

154152
type_hints = get_type_hints(obj)
155153
type_hint = type_hints.get(name)
@@ -169,8 +167,8 @@ def cast_attribute_value(obj, name, value):
169167

170168

171169
def get_method_arguments(func) -> List[str]:
172-
"""
173-
Gets the arguments for a method.
170+
"""Gets the arguments for a method.
171+
174172
Returns:
175173
A list of strings, one for each argument.
176174
"""
@@ -185,10 +183,8 @@ def get_method_arguments(func) -> List[str]:
185183

186184

187185
def is_queryset(obj, type_hint, value):
188-
"""
189-
Determines whether an obj is a `QuerySet` or not based on the current instance of the
190-
component or the type hint.
191-
"""
186+
"""Determines whether an obj is a `QuerySet` or not based on the current instance of the
187+
component or the type hint."""
192188

193189
return (
194190
(isinstance(obj, QuerySet) or (type_hint and get_origin(type_hint) is QuerySetType))
@@ -198,9 +194,7 @@ def is_queryset(obj, type_hint, value):
198194

199195

200196
def _construct_model(model_type, model_data: Dict):
201-
"""
202-
Construct a model based on the type and dictionary data.
203-
"""
197+
"""Construct a model based on the type and dictionary data."""
204198

205199
if not model_data:
206200
return None
@@ -223,18 +217,15 @@ def _construct_model(model_type, model_data: Dict):
223217

224218

225219
def create_queryset(obj, type_hint, value) -> QuerySet:
226-
"""
227-
Create a queryset based on the `value`. If needed, the queryset will be created based on the `QuerySetType`.
220+
"""Create a queryset based on the `value`. If needed, the queryset will be created based on the `QuerySetType`.
228221
229222
For example, all of these ways fields are equivalent:
230223
231-
```
232224
class TestComponent(UnicornView):
233225
queryset_with_empty_list: QuerySetType[SomeModel] = []
234226
queryset_with_none: QuerySetType[SomeModel] = None
235227
queryset_with_empty_queryset: QuerySetType[SomeModel] = SomeModel.objects.none()
236228
queryset_with_no_typehint = SomeModel.objects.none()
237-
```
238229
239230
Params:
240231
obj: Object.

docs/source/actions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ A reference to the last return value from an action method.
316316
</div>
317317
```
318318

319+
### $parent
320+
321+
A reference to the parent of the current component.
322+
319323
## Special methods
320324

321325
### $refresh

docs/source/changelog.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
# Changelog
22

3-
## 0.58.0-dev
3+
## 0.58.0
4+
5+
This release could not have been made possible without the generous support of https://github.com/winrid and https://github.com/om-proptech. Thank you for sponsoring me and believing in `django-unicorn`! It also includes critical improvements to nested components from https://github.com/imankulov.
46

57
- Handle a list of `ValidationError` or just a string instead of requiring a the `dict` version.
8+
- Better support for type annotations for component fields.
9+
- Improved nested component support by [imankulov](https://github.com/imankulov).
10+
- Add [`force_render`](views.md#force_render) and [`$parent`](actions.md#parent).
11+
12+
**Breaking changes**
13+
14+
Child components will not *by default* render the parent component anymore. If this is required for your child component, specify `self.parent.force_render = True` in any action that requires the parent to re-render. This change will reduce network bandwidth and isolates the amount of re-rendering required for nested components.
615

716
## 0.57.1
817

@@ -242,7 +251,7 @@
242251

243252
- Security fix: for CVE-2021-42053 to prevent XSS attacks (reported by [Jeffallan](https://github.com/Jeffallan)).
244253

245-
** Breaking changes **
254+
**Breaking changes**
246255

247256
- responses will be HTML encoded going forward (to explicitly opt-in to previous behavior use [safe](views.md#safe))
248257

@@ -305,7 +314,7 @@
305314
- Look in all `INSTALLED_APPS` for components instead of only in a `unicorn` app [210](https://github.com/adamghill/django-unicorn/issues/210)
306315
- Support `settings.APPS_DIR` which is the default for `django-cookiecutter` instead of just `settings.BASE_DIR` [214](https://github.com/adamghill/django-unicorn/issues/214)
307316

308-
** Breaking changes **
317+
**Breaking changes**
309318

310319
- Require an application name when running the `startunicorn` management command for where the component should be created
311320

docs/source/views.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ class HelloWorldView(UnicornView):
189189
print("AJAX request that re-renders the component", self.request)
190190
```
191191

192+
### force_render
193+
194+
Forces the component to render. This is not normally needed for the current component, but is sometimes needed for a parent component.
195+
192196
## Custom methods
193197

194198
Defined component instance methods with no arguments (other than `self`) are available in the Django template context and can be called like a property.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.57.1",
2+
"version": "0.58.0",
33
"name": "django-unicorn",
44
"scripts": {
55
"build": "npx rollup -c",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-unicorn"
3-
version = "0.57.1"
3+
version = "0.58.0"
44
description = "A magical full-stack framework for Django."
55
authors = ["Adam Hill <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)