Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for non-serializable component parameters #120

Merged
merged 57 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
48ef41d
fix use_location bug
Archmonger Jan 9, 2023
89a59d6
add missing migration
Archmonger Jan 10, 2023
2247a18
enable django mypy plugin
Archmonger Jan 10, 2023
f2b5a3a
Functional DB-backed component params
Archmonger Jan 10, 2023
0b11cf7
remove broken django stubs
Archmonger Jan 10, 2023
587cfa3
fix type hints
Archmonger Jan 10, 2023
e93253c
skip migrations
Archmonger Jan 10, 2023
8a84f1d
bump idom version
Archmonger Jan 10, 2023
3760dde
Use idom 0.43.0 hooks
Archmonger Jan 10, 2023
e686894
don't render component if args/kwargs are wrong
Archmonger Jan 10, 2023
4b7676c
docs and changelog
Archmonger Jan 10, 2023
0f57702
Add object in templatetag tests
Archmonger Jan 10, 2023
9432349
fix styling errors
Archmonger Jan 10, 2023
a87a7b5
type hints for user
Archmonger Jan 10, 2023
4f41975
validate function signature
Archmonger Jan 10, 2023
ec46469
use lowercase tuple
Archmonger Jan 11, 2023
5e75488
functioning eviction strategy
Archmonger Jan 11, 2023
7344a97
don't clean DB on startup if running django tests
Archmonger Jan 11, 2023
d2d4573
switch sys check to contextlib suppress
Archmonger Jan 11, 2023
ace4a34
view_to_component uses del_html_head_body_transform
Archmonger Jan 11, 2023
8cf2884
update docs
Archmonger Jan 11, 2023
d985e14
add serializable to dictionary
Archmonger Jan 11, 2023
3011e75
fix #35
Archmonger Jan 11, 2023
e9a1364
fix #29
Archmonger Jan 11, 2023
e0fcbd9
Make some utils public if they're harmless
Archmonger Jan 12, 2023
2adb676
Make DATE_FORMAT a global
Archmonger Jan 12, 2023
319dda2
validate params_query expiration within fetch queries
Archmonger Jan 12, 2023
00e3c85
refactor db_cleanup
Archmonger Jan 12, 2023
43f4a32
more deprivatization
Archmonger Jan 12, 2023
f79f936
document django_query_postprocessor
Archmonger Jan 12, 2023
83730cd
comment for _register_component
Archmonger Jan 12, 2023
5dd8d16
add postprocessor to dictionary
Archmonger Jan 12, 2023
9f6b757
docs revision
Archmonger Jan 14, 2023
5d56d23
misc docs updates
Archmonger Jan 14, 2023
827adf3
move hooks back into `django_idom.hooks`
Archmonger Jan 14, 2023
6a08531
Merge remote-tracking branch 'upstream/main' into database-backed-kwargs
Archmonger Jan 14, 2023
03f315b
v3.0.0
Archmonger Jan 14, 2023
8f83c1b
docs formatting
Archmonger Jan 14, 2023
be07851
better link for keys
Archmonger Jan 15, 2023
6209c07
subclass core's Connection
Archmonger Jan 15, 2023
04a2efc
Complete types list
Archmonger Jan 15, 2023
196c756
remove unused ignore
Archmonger Jan 15, 2023
ac415dd
tests for ComponentParams expiration
Archmonger Jan 16, 2023
6447885
use tuple for ComponentParamData
Archmonger Jan 16, 2023
1a9b06e
better type hints for ComponentParamData
Archmonger Jan 16, 2023
cb0bd4f
Better type hints for postprocessor_kwargs
Archmonger Jan 16, 2023
648d3a2
type hint fixes
Archmonger Jan 16, 2023
54b9840
type hint for ComponentPreloader
Archmonger Jan 16, 2023
976f10f
timezone might not always be available, so don't rely on it.
Archmonger Jan 20, 2023
3f6069c
more robust ComponentParams tests
Archmonger Jan 22, 2023
abc3439
always lazy load config
Archmonger Jan 22, 2023
d7809f9
remove defaults.py
Archmonger Jan 22, 2023
a2a2c8c
remove version bump
Archmonger Jan 28, 2023
468d52f
fix type hint issues
Archmonger Jan 28, 2023
0d9d4a9
change mypy to incremental
Archmonger Feb 1, 2023
a0194c0
format using new black version
Archmonger Feb 1, 2023
f5cc229
log when idom database is not ready at startup
Archmonger Feb 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,35 @@ Using the following categories, list your changes in this order:

## [Unreleased]

### Added

- The `idom` client will automatically configure itself to debug mode depending on `settings.py:DEBUG`.
- `use_connection` hook for returning the browser's active `Connection`

### Changed

- The `component` template tag now supports both positional and keyword arguments.
- The `component` template tag now supports non-serializable arguments.
- `IDOM_WS_MAX_RECONNECT_TIMEOUT` setting has been renamed to `IDOM_RECONNECT_MAX`.
- It is now mandatory to run `manage.py migrate` after installing IDOM.
- Bumped the minimum IDOM version to 0.43.0

### Removed

- `django_idom.hooks.use_websocket` has been removed. The similar replacement is `django_idom.hooks.use_connection`.
- `django_idom.types.IdomWebsocket` has been removed. The similar replacement is `django_idom.types.Connection`

### Fixed

- `view_to_component` will now retain any HTML that was defined in a `<head>` tag.
- React client is now set to `production` rather than `development`.
- `use_query` will now utilize `field.related_name` when postprocessing many-to-one relationships

### Security

- Fixed a potential method of component template tag argument spoofing.
- Exception information will no longer be displayed on the page, based on the value of `settings.py:DEBUG`.

## [2.2.1] - 2022-01-09

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def hello_world(recipient: str):

In your **Django app**'s HTML template, you can now embed your IDOM component using the `component` template tag. Within this tag, you will need to type in your dotted path to the component function as the first argument.

Additionally, you can pass in keyword arguments into your component function. For example, after reading the code below, pay attention to how the function definition for `hello_world` (_in the previous example_) accepts a `recipient` argument.
Additionally, you can pass in `args` and `kwargs` into your component function. For example, after reading the code below, pay attention to how the function definition for `hello_world` (_in the previous example_) accepts a `recipient` argument.

<!--html-header-end-->
<!--html-code-start-->
Expand Down
6 changes: 3 additions & 3 deletions docs/src/contribute/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If you plan to make code changes to this repository, you will need to install th

Once done, you should clone this repository:

```bash
```bash linenums="0"
Archmonger marked this conversation as resolved.
Show resolved Hide resolved
git clone https://github.com/idom-team/django-idom.git
cd django-idom
```
Expand All @@ -20,13 +20,13 @@ Then, by running the command below you can:
- Install an editable version of the Python code
- Download, build, and install Javascript dependencies

```bash
```bash linenums="0"
pip install -e . -r requirements.txt
```

Finally, to verify that everything is working properly, you can manually run the development webserver.

```bash
```bash linenums="0"
cd tests
python manage.py runserver
```
Expand Down
6 changes: 3 additions & 3 deletions docs/src/contribute/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ If you plan to make changes to this documentation, you will need to install the

Once done, you should clone this repository:

```bash
```bash linenums="0"
git clone https://github.com/idom-team/django-idom.git
cd django-idom
```
Expand All @@ -15,13 +15,13 @@ Then, by running the command below you can:
- Install an editable version of the documentation
- Self-host a test server for the documentation

```bash
```bash linenums="0"
pip install -r ./requirements/build-docs.txt --upgrade
```

Finally, to verify that everything is working properly, you can manually run the docs preview webserver.

```bash
```bash linenums="0"
mkdocs serve
```

Expand Down
6 changes: 3 additions & 3 deletions docs/src/contribute/running-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ If you plan to run tests, you will need to install the following dependencies fi

Once done, you should clone this repository:

```bash
```bash linenums="0"
git clone https://github.com/idom-team/django-idom.git
cd django-idom
pip install -r ./requirements/test-run.txt --upgrade
```

Then, by running the command below you can run the full test suite:

```
```bash linenums="0"
nox -s test
```

Or, if you want to run the tests in the foreground:

```
```bash linenums="0"
nox -s test -- --headed
```
3 changes: 3 additions & 0 deletions docs/src/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ idom
asgi
postfixed
postprocessing
serializable
postprocessor
preprocessor
3 changes: 1 addition & 2 deletions docs/src/features/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ Convert any Django view into a IDOM component by using this decorator. Compatibl

- Requires manual intervention to change request methods beyond `GET`.
- IDOM events cannot conveniently be attached to converted view HTML.
- Does not currently load any HTML contained with a `<head>` tag
- Has no option to automatically intercept local anchor link (such as `#!html <a href='example/'></a>`) click events
- Has no option to automatically intercept local anchor link (such as `#!html <a href='example/'></a>`) click events.

_Please note these limitations do not exist when using `compatibility` mode._

Expand Down
8 changes: 1 addition & 7 deletions docs/src/features/decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@

## Auth Required

You can limit access to a component to users with a specific `auth_attribute` by using this decorator.
You can limit access to a component to users with a specific `auth_attribute` by using this decorator (with or without parentheses).

By default, this decorator checks if the user is logged in, and his/her account has not been deactivated.

This decorator is commonly used to selectively render a component only if a user [`is_staff`](https://docs.djangoproject.com/en/dev/ref/contrib/auth/#django.contrib.auth.models.User.is_staff) or [`is_superuser`](https://docs.djangoproject.com/en/dev/ref/contrib/auth/#django.contrib.auth.models.User.is_superuser).

This decorator can be used with or without parentheses.

=== "components.py"

```python
from django_idom.decorators import auth_required
from django_idom.hooks import use_websocket
from idom import component, html

@component
Expand Down Expand Up @@ -70,7 +67,6 @@ This decorator can be used with or without parentheses.

```python
from django_idom.decorators import auth_required
from django_idom.hooks import use_websocket
from idom import component, html

@component
Expand All @@ -87,7 +83,6 @@ This decorator can be used with or without parentheses.

```python
from django_idom.decorators import auth_required
from django_idom.hooks import use_websocket
from idom import component, html


Expand Down Expand Up @@ -120,7 +115,6 @@ This decorator can be used with or without parentheses.

```python
from django_idom.decorators import auth_required
from django_idom.hooks import use_websocket
from idom import component, html

@component
Expand Down
66 changes: 33 additions & 33 deletions docs/src/features/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,20 +399,22 @@ The function you provide into this hook will have no return value.

{% include-markdown "../../includes/orm.md" start="<!--orm-excp-start-->" end="<!--orm-excp-end-->" %}

## Use Websocket
## Use Origin

This is a shortcut that returns the Websocket's `origin`.

You can fetch the Django Channels [websocket](https://channels.readthedocs.io/en/stable/topics/consumers.html#asyncjsonwebsocketconsumer) at any time by using `use_websocket`.
You can expect this hook to provide strings such as `http://example.com`.

=== "components.py"

```python
from idom import component, html
from django_idom.hooks import use_websocket
from django_idom.hooks import use_origin

@component
def my_component():
my_websocket = use_websocket()
return html.div(my_websocket)
my_origin = use_origin()
return html.div(my_origin)
```

??? example "See Interface"
Expand All @@ -425,22 +427,22 @@ You can fetch the Django Channels [websocket](https://channels.readthedocs.io/en

| Type | Description |
| --- | --- |
| `IdomWebsocket` | The component's websocket. |
| `str | None` | A string containing the browser's current origin, obtained from websocket headers (if available). |

## Use Scope
## Use Connection

This is a shortcut that returns the Websocket's [`scope`](https://channels.readthedocs.io/en/stable/topics/consumers.html#scope).
You can fetch the Django Channels [websocket](https://channels.readthedocs.io/en/stable/topics/consumers.html#asyncjsonwebsocketconsumer) at any time by using `use_connection`.

=== "components.py"

```python
from idom import component, html
from django_idom.hooks import use_scope
from django_idom.hooks import use_connection

@component
def my_component():
my_scope = use_scope()
return html.div(my_scope)
my_connection = use_connection()
return html.div(my_connection)
```

??? example "See Interface"
Expand All @@ -453,24 +455,22 @@ This is a shortcut that returns the Websocket's [`scope`](https://channels.readt

| Type | Description |
| --- | --- |
| `dict[str, Any]` | The websocket's `scope`. |
| `Connection` | The component's websocket. |

## Use Location

This is a shortcut that returns the Websocket's `path`.
## Use Scope

You can expect this hook to provide strings such as `/idom/my_path`.
This is a shortcut that returns the Websocket's [`scope`](https://channels.readthedocs.io/en/stable/topics/consumers.html#scope).

=== "components.py"

```python
from idom import component, html
from django_idom.hooks import use_location
from django_idom.hooks import use_scope

@component
def my_component():
my_location = use_location()
return html.div(my_location)
my_scope = use_scope()
return html.div(my_scope)
```

??? example "See Interface"
Expand All @@ -483,30 +483,24 @@ You can expect this hook to provide strings such as `/idom/my_path`.

| Type | Description |
| --- | --- |
| `Location` | A object containing the current URL's `pathname` and `search` query. |
| `MutableMapping[str, Any]` | The websocket's `scope`. |

??? info "This hook's behavior will be changed in a future update"

This hook will be updated to return the browser's currently active path. This change will come in alongside IDOM URL routing support.

Check out [idom-team/idom-router#2](https://github.com/idom-team/idom-router/issues/2) for more information.

## Use Origin
## Use Location

This is a shortcut that returns the Websocket's `origin`.
This is a shortcut that returns the Websocket's `path`.

You can expect this hook to provide strings such as `http://example.com`.
You can expect this hook to provide strings such as `/idom/my_path`.

=== "components.py"

```python
from idom import component, html
from django_idom.hooks import use_origin
from django_idom.hooks import use_location

@component
def my_component():
my_origin = use_origin()
return html.div(my_origin)
my_location = use_location()
return html.div(my_location)
```

??? example "See Interface"
Expand All @@ -519,4 +513,10 @@ You can expect this hook to provide strings such as `http://example.com`.

| Type | Description |
| --- | --- |
| `str | None` | A string containing the browser's current origin, obtained from websocket headers (if available). |
| `Location` | A object containing the current URL's `pathname` and `search` query. |

??? info "This hook's behavior will be changed in a future update"

This hook will be updated to return the browser's currently active path. This change will come in alongside IDOM URL routing support.

Check out [idom-team/idom-router#2](https://github.com/idom-team/idom-router/issues/2) for more information.
11 changes: 6 additions & 5 deletions docs/src/features/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
<!--settings-start-->

```python
# If "idom" cache is not configured, then we will use "default" instead
# If "idom" cache is not configured, then "default" will be used
# IDOM expects a multiprocessing-safe and thread-safe cache backend.
CACHES = {
"idom": {"BACKEND": ...},
}

# Maximum seconds between two reconnection attempts that would cause the client give up.
# 0 will disable reconnection.
IDOM_WS_MAX_RECONNECT_TIMEOUT = 604800
# Maximum seconds between reconnection attempts before giving up.
# Use `0` to prevent component reconnection.
IDOM_RECONNECT_MAX = 259200
rmorshea marked this conversation as resolved.
Show resolved Hide resolved

# The URL for IDOM to serve websockets
# The URL for IDOM to serve the component rendering websocket
IDOM_WEBSOCKET_URL = "idom/"

# Dotted path to the default postprocessor function, or `None`
Expand Down
Loading