Skip to content

Commit

Permalink
Bump to 0.58.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamghill committed Dec 24, 2023
1 parent 08e405f commit 1525c99
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion django_unicorn/static/unicorn/js/unicorn.min.js

Large diffs are not rendered by default.

31 changes: 11 additions & 20 deletions django_unicorn/typer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def _parse_bool(value):


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


def cast_value(type_hint, value):
"""
Try to cast the value based on the type hint and
"""Try to cast the value based on the type hint and
`django_unicorn.call_method_parser.CASTERS`.
Additional features:
- convert `int`/`float` epoch to `datetime` or `date`
- instantiate the `type_hint` class with passed-in value
Expand Down Expand Up @@ -147,9 +147,7 @@ def cast_value(type_hint, value):


def cast_attribute_value(obj, name, value):
"""
Try to cast the value of an object's attribute based on the type hint.
"""
"""Try to cast the value of an object's attribute based on the type hint."""

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


def get_method_arguments(func) -> List[str]:
"""
Gets the arguments for a method.
"""Gets the arguments for a method.
Returns:
A list of strings, one for each argument.
"""
Expand All @@ -185,10 +183,8 @@ def get_method_arguments(func) -> List[str]:


def is_queryset(obj, type_hint, value):
"""
Determines whether an obj is a `QuerySet` or not based on the current instance of the
component or the type hint.
"""
"""Determines whether an obj is a `QuerySet` or not based on the current instance of the
component or the type hint."""

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


def _construct_model(model_type, model_data: Dict):
"""
Construct a model based on the type and dictionary data.
"""
"""Construct a model based on the type and dictionary data."""

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


def create_queryset(obj, type_hint, value) -> QuerySet:
"""
Create a queryset based on the `value`. If needed, the queryset will be created based on the `QuerySetType`.
"""Create a queryset based on the `value`. If needed, the queryset will be created based on the `QuerySetType`.
For example, all of these ways fields are equivalent:
```
class TestComponent(UnicornView):
queryset_with_empty_list: QuerySetType[SomeModel] = []
queryset_with_none: QuerySetType[SomeModel] = None
queryset_with_empty_queryset: QuerySetType[SomeModel] = SomeModel.objects.none()
queryset_with_no_typehint = SomeModel.objects.none()
```
Params:
obj: Object.
Expand Down
4 changes: 4 additions & 0 deletions docs/source/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ A reference to the last return value from an action method.
</div>
```

### $parent

A reference to the parent of the current component.

## Special methods

### $refresh
Expand Down
15 changes: 12 additions & 3 deletions docs/source/changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# Changelog

## 0.58.0-dev
## 0.58.0

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.

- Handle a list of `ValidationError` or just a string instead of requiring a the `dict` version.
- Better support for type annotations for component fields.
- Improved nested component support by [imankulov](https://github.com/imankulov).
- Add [`force_render`](views.md#force_render) and [`$parent`](actions.md#parent).

**Breaking changes**

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.

## 0.57.1

Expand Down Expand Up @@ -242,7 +251,7 @@

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

** Breaking changes **
**Breaking changes**

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

Expand Down Expand Up @@ -305,7 +314,7 @@
- Look in all `INSTALLED_APPS` for components instead of only in a `unicorn` app [210](https://github.com/adamghill/django-unicorn/issues/210)
- 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)

** Breaking changes **
**Breaking changes**

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

Expand Down
4 changes: 4 additions & 0 deletions docs/source/views.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ class HelloWorldView(UnicornView):
print("AJAX request that re-renders the component", self.request)
```

### force_render

Forces the component to render. This is not normally needed for the current component, but is sometimes needed for a parent component.

## Custom methods

Defined component instance methods with no arguments (other than `self`) are available in the Django template context and can be called like a property.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.57.1",
"version": "0.58.0",
"name": "django-unicorn",
"scripts": {
"build": "npx rollup -c",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-unicorn"
version = "0.57.1"
version = "0.58.0"
description = "A magical full-stack framework for Django."
authors = ["Adam Hill <unicorn@adamghill.com>"]
license = "MIT"
Expand Down

0 comments on commit 1525c99

Please sign in to comment.