Skip to content

Commit 741de48

Browse files
authored
Support ReactPy Router v1.0.0 (#252)
- Adds support for ReactPy Router v1.0.0 - Docs cleanup - Tests cleanup - Remove deprecated code
1 parent 50c26e4 commit 741de48

40 files changed

+332
-507
lines changed

Diff for: CHANGELOG.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,21 @@ Don't forget to remove deprecated code on each major release!
3636

3737
## [Unreleased]
3838

39-
- Nothing (yet)!
39+
### Changed
40+
41+
- Now using ReactPy-Router v1 for URL routing, which comes with a slightly different API than before.
42+
- Removed dependency on `aiofile`.
43+
44+
### Removed
45+
46+
- Removed the following **deprecated** features:
47+
- The `compatibility` argument on `reactpy_django.components.view_to_component`
48+
- `reactpy_django.components.view_to_component` **usage as a decorator**
49+
- `reactpy_django.decorators.auth_required`
50+
- `reactpy_django.REACTPY_WEBSOCKET_PATH`
51+
- `settings.py:REACTPY_WEBSOCKET_URL`
4052

41-
## [4.0.0]
53+
## [4.0.0] - 2024-06-22
4254

4355
### Added
4456

@@ -112,8 +124,8 @@ Don't forget to remove deprecated code on each major release!
112124
- New Django `User` related features!
113125
- `reactpy_django.hooks.use_user` can be used to access the current user.
114126
- `reactpy_django.hooks.use_user_data` provides a simplified interface for storing user key-value data.
115-
- `reactpy_django.decorators.user_passes_test` is inspired by the [equivalent Django decorator](http://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.decorators.user_passes_test), but ours works with ReactPy components.
116-
- `settings.py:REACTPY_AUTO_RELOGIN` will cause component WebSocket connections to automatically [re-login](https://channels.readthedocs.io/en/latest/topics/authentication.html#how-to-log-a-user-in-out) users that are already authenticated. This is useful to continuously update `last_login` timestamps and refresh the [Django login session](https://docs.djangoproject.com/en/dev/topics/http/sessions/).
127+
- `reactpy_django.decorators.user_passes_test` is inspired by the [equivalent Django decorator](http://docs.djangoproject.com/en/stable/topics/auth/default/#django.contrib.auth.decorators.user_passes_test), but ours works with ReactPy components.
128+
- `settings.py:REACTPY_AUTO_RELOGIN` will cause component WebSocket connections to automatically [re-login](https://channels.readthedocs.io/en/latest/topics/authentication.html#how-to-log-a-user-in-out) users that are already authenticated. This is useful to continuously update `last_login` timestamps and refresh the [Django login session](https://docs.djangoproject.com/en/stable/topics/http/sessions/).
117129

118130
### Changed
119131

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def hello_world(recipient: str):
8383

8484
<!--py-code-end-->
8585

86-
## [`my_app/templates/my_template.html`](https://docs.djangoproject.com/en/dev/topics/templates/)
86+
## [`my_app/templates/my_template.html`](https://docs.djangoproject.com/en/stable/topics/templates/)
8787

8888
<!--html-header-start-->
8989

Diff for: docs/mkdocs.yml

-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ plugins:
8989
- spellcheck:
9090
known_words: dictionary.txt
9191
allow_unicode: no
92-
ignore_code: yes
93-
# - section-index
9492

9593
extra:
9694
generator: false

Diff for: docs/src/dictionary.txt

+33-31
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
1+
asgi
2+
async
3+
backend
4+
backends
5+
backhaul
6+
broadcasted
7+
changelog
18
django
2-
sanic
3-
plotly
9+
frontend
10+
frontends
11+
hello_world
12+
html
13+
iframe
14+
jupyter
15+
keyworded
16+
middleware
17+
misconfiguration
18+
misconfigurations
19+
my_template
420
nox
5-
WebSocket
6-
WebSockets
7-
changelog
8-
async
21+
plotly
22+
postfixed
23+
postprocessing
24+
postprocessor
925
pre
1026
prefetch
1127
prefetching
1228
preloader
13-
whitespace
29+
preprocessor
30+
py
31+
pyodide
32+
pyscript
33+
reactpy
1434
refetch
1535
refetched
1636
refetching
17-
html
18-
jupyter
19-
iframe
20-
keyworded
37+
sanic
38+
serializable
2139
stylesheet
2240
stylesheets
23-
unstyled
24-
py
25-
reactpy
26-
asgi
27-
postfixed
28-
postprocessing
29-
serializable
30-
postprocessor
31-
preprocessor
32-
middleware
33-
backends
34-
backend
35-
frontend
36-
frontends
37-
misconfiguration
38-
misconfigurations
39-
backhaul
4041
sublicense
41-
broadcasted
42-
hello_world
43-
my_template
42+
unstyled
43+
WebSocket
44+
WebSockets
45+
whitespace

Diff for: docs/src/learn/add-reactpy-to-a-django-project.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ If you want to add some interactivity to your existing **Django project**, you d
88

99
!!! abstract "Note"
1010

11-
These docs assumes you have already created [a **Django project**](https://docs.djangoproject.com/en/dev/intro/tutorial01/), which involves creating and installing at least one **Django app**.
11+
These docs assumes you have already created [a **Django project**](https://docs.djangoproject.com/en/stable/intro/tutorial01/), which involves creating and installing at least one **Django app**.
1212

1313
If do not have a **Django project**, check out this [9 minute YouTube tutorial](https://www.youtube.com/watch?v=ZsJRXS_vrw0) created by _IDG TECHtalk_.
1414

@@ -24,7 +24,7 @@ pip install reactpy-django
2424

2525
## Step 2: Configure `settings.py`
2626

27-
Add `#!python "reactpy_django"` to [`INSTALLED_APPS`](https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-INSTALLED_APPS) in your [`settings.py`](https://docs.djangoproject.com/en/dev/topics/settings/) file.
27+
Add `#!python "reactpy_django"` to [`INSTALLED_APPS`](https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-INSTALLED_APPS) in your [`settings.py`](https://docs.djangoproject.com/en/stable/topics/settings/) file.
2828

2929
=== "settings.py"
3030

@@ -36,7 +36,7 @@ Add `#!python "reactpy_django"` to [`INSTALLED_APPS`](https://docs.djangoproject
3636

3737
ReactPy-Django requires Django ASGI and [Django Channels](https://github.com/django/channels) WebSockets.
3838

39-
If you have not enabled ASGI on your **Django project** yet, here is a summary of the [`django`](https://docs.djangoproject.com/en/dev/howto/deployment/asgi/) and [`channels`](https://channels.readthedocs.io/en/stable/installation.html) installation docs:
39+
If you have not enabled ASGI on your **Django project** yet, here is a summary of the [`django`](https://docs.djangoproject.com/en/stable/howto/deployment/asgi/) and [`channels`](https://channels.readthedocs.io/en/stable/installation.html) installation docs:
4040

4141
1. Install `channels[daphne]`
4242
2. Add `#!python "daphne"` to `#!python INSTALLED_APPS`.
@@ -59,7 +59,7 @@ Add `#!python "reactpy_django"` to [`INSTALLED_APPS`](https://docs.djangoproject
5959

6060
## Step 3: Configure `urls.py`
6161

62-
Add ReactPy HTTP paths to your `#!python urlpatterns` in your [`urls.py`](https://docs.djangoproject.com/en/dev/topics/http/urls/) file.
62+
Add ReactPy HTTP paths to your `#!python urlpatterns` in your [`urls.py`](https://docs.djangoproject.com/en/stable/topics/http/urls/) file.
6363

6464
=== "urls.py"
6565

@@ -69,7 +69,7 @@ Add ReactPy HTTP paths to your `#!python urlpatterns` in your [`urls.py`](https:
6969

7070
## Step 4: Configure `asgi.py`
7171

72-
Register ReactPy's WebSocket using `#!python REACTPY_WEBSOCKET_ROUTE` in your [`asgi.py`](https://docs.djangoproject.com/en/dev/howto/deployment/asgi/) file.
72+
Register ReactPy's WebSocket using `#!python REACTPY_WEBSOCKET_ROUTE` in your [`asgi.py`](https://docs.djangoproject.com/en/stable/howto/deployment/asgi/) file.
7373

7474
=== "asgi.py"
7575

@@ -97,23 +97,23 @@ Register ReactPy's WebSocket using `#!python REACTPY_WEBSOCKET_ROUTE` in your [`
9797

9898
## Step 5: Run database migrations
9999

100-
Run Django's [`migrate` command](https://docs.djangoproject.com/en/dev/topics/migrations/) to initialize ReactPy-Django's database table.
100+
Run Django's [`migrate` command](https://docs.djangoproject.com/en/stable/topics/migrations/) to initialize ReactPy-Django's database table.
101101

102102
```bash linenums="0"
103103
python manage.py migrate
104104
```
105105

106106
## Step 6: Check your configuration
107107

108-
Run Django's [`check` command](https://docs.djangoproject.com/en/dev/ref/django-admin/#check) to verify if ReactPy was set up correctly.
108+
Run Django's [`check` command](https://docs.djangoproject.com/en/stable/ref/django-admin/#check) to verify if ReactPy was set up correctly.
109109

110110
```bash linenums="0"
111111
python manage.py check
112112
```
113113

114114
## Step 7: Create your first component
115115

116-
The [next step](./your-first-component.md) will show you how to create your first ReactPy component.
116+
The [next page](./your-first-component.md) will show you how to create your first ReactPy component.
117117

118118
Prefer a quick summary? Read the **At a Glance** section below.
119119

Diff for: docs/src/learn/your-first-component.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ You will now need to pick at least one **Django app** to start using ReactPy-Dja
1818

1919
For the following examples, we will assume the following:
2020

21-
1. You have a **Django app** named `my_app`, which was created by Django's [`startapp` command](https://docs.djangoproject.com/en/dev/intro/tutorial01/#creating-the-polls-app).
21+
1. You have a **Django app** named `my_app`, which was created by Django's [`startapp` command](https://docs.djangoproject.com/en/stable/intro/tutorial01/#creating-the-polls-app).
2222
2. You have placed `my_app` directly into your **Django project** folder (`./example_project/my_app`). This is common for small projects.
2323

2424
??? question "How do I organize my Django project for ReactPy?"
@@ -31,7 +31,7 @@ You will need a file to start creating ReactPy components.
3131

3232
We recommend creating a `components.py` file within your chosen **Django app** to start out. For this example, the file path will look like this: `./example_project/my_app/components.py`.
3333

34-
Within this file, you can define your component functions using ReactPy's `#!python @component` decorator.
34+
Within this file, you will define your component function(s) using the `#!python @component` decorator.
3535

3636
=== "components.py"
3737

@@ -43,7 +43,7 @@ Within this file, you can define your component functions using ReactPy's `#!pyt
4343

4444
We recommend creating a `components.py` for small **Django apps**. If your app has a lot of components, you should consider breaking them apart into individual modules such as `components/navbar.py`.
4545

46-
Ultimately, components are referenced by Python dotted path in `my_template.html` ([_see next step_](#embedding-in-a-template)). This path must be valid to Python's `#!python importlib`.
46+
Ultimately, components are referenced by Python dotted path in `my_template.html` ([_see next step_](#embedding-in-a-template)). This dotted path must be valid to Python's `#!python importlib`.
4747

4848
??? question "What does the decorator actually do?"
4949

@@ -66,25 +66,31 @@ Additionally, you can pass in `#!python args` and `#!python kwargs` into your co
6666

6767
{% include-markdown "../../../README.md" start="<!--html-code-start-->" end="<!--html-code-end-->" %}
6868

69+
???+ tip "Components are automatically registered!"
70+
71+
ReactPy-Django will automatically register any component that is referenced in a Django HTML template. This means you [typically](../reference/utils.md#register-component) do not need to manually register components in your **Django app**.
72+
73+
Please note that this HTML template must be properly stored within a registered Django app. ReactPy-Django will output a console log message containing all detected components when the server starts up.
74+
6975
{% include-markdown "../reference/template-tag.md" start="<!--context-start-->" end="<!--context-end-->" %}
7076

7177
{% include-markdown "../reference/template-tag.md" start="<!--multiple-components-start-->" end="<!--multiple-components-end-->" %}
7278

7379
??? question "Where is my templates folder?"
7480

75-
If you do not have a `./templates/` folder in your **Django app**, you can simply create one! Keep in mind, templates within this folder will not be detected by Django unless you [add the corresponding **Django app** to `settings.py:INSTALLED_APPS`](https://docs.djangoproject.com/en/dev/ref/applications/#configuring-applications).
81+
If you do not have a `./templates/` folder in your **Django app**, you can simply create one! Keep in mind, templates within this folder will not be detected by Django unless you [add the corresponding **Django app** to `settings.py:INSTALLED_APPS`](https://docs.djangoproject.com/en/stable/ref/applications/#configuring-applications).
7682

7783
## Setting up a Django view
7884

79-
Within your **Django app**'s `views.py` file, you will need to [create a view function](https://docs.djangoproject.com/en/dev/intro/tutorial01/#write-your-first-view) to render the HTML template `my_template.html` ([_from the previous step_](#embedding-in-a-template)).
85+
Within your **Django app**'s `views.py` file, you will need to [create a view function](https://docs.djangoproject.com/en/stable/intro/tutorial01/#write-your-first-view) to render the HTML template `my_template.html` ([_from the previous step_](#embedding-in-a-template)).
8086

8187
=== "views.py"
8288

8389
```python
8490
{% include "../../examples/python/example/views.py" %}
8591
```
8692

87-
We will add this new view into your [`urls.py`](https://docs.djangoproject.com/en/dev/intro/tutorial01/#write-your-first-view) and define what URL it should be accessible at.
93+
We will add this new view into your [`urls.py`](https://docs.djangoproject.com/en/stable/intro/tutorial01/#write-your-first-view) and define what URL it should be accessible at.
8894

8995
=== "urls.py"
9096

@@ -98,7 +104,7 @@ We will add this new view into your [`urls.py`](https://docs.djangoproject.com/e
98104

99105
Once you reach that point, we recommend creating an individual `urls.py` within each of your **Django apps**.
100106

101-
Then, within your **Django project's** `urls.py` you will use Django's [`include` function](https://docs.djangoproject.com/en/dev/ref/urls/#include) to link it all together.
107+
Then, within your **Django project's** `urls.py` you will use Django's [`include` function](https://docs.djangoproject.com/en/stable/ref/urls/#include) to link it all together.
102108

103109
## Viewing your component
104110

@@ -114,7 +120,7 @@ If you copy-pasted our example component, you will now see your component displa
114120

115121
??? warning "Do not use `manage.py runserver` for production"
116122

117-
This command is only intended for development purposes. For production deployments make sure to read [Django's documentation](https://docs.djangoproject.com/en/dev/howto/deployment/).
123+
This command is only intended for development purposes. For production deployments make sure to read [Django's documentation](https://docs.djangoproject.com/en/stable/howto/deployment/).
118124

119125
## Learn more
120126

Diff for: docs/src/reference/components.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Automatically convert a Django view into a component.
124124

125125
At this time, this works best with static views with no interactivity.
126126

127-
Compatible with sync or async [Function Based Views](https://docs.djangoproject.com/en/dev/topics/http/views/) and [Class Based Views](https://docs.djangoproject.com/en/dev/topics/class-based-views/).
127+
Compatible with sync or async [Function Based Views](https://docs.djangoproject.com/en/stable/topics/http/views/) and [Class Based Views](https://docs.djangoproject.com/en/stable/topics/class-based-views/).
128128

129129
=== "components.py"
130130

@@ -254,7 +254,7 @@ Automatically convert a Django view into an [`iframe` element](https://www.techt
254254

255255
The contents of this `#!python iframe` is handled entirely by traditional Django view rendering. While this solution is compatible with more views than `#!python view_to_component`, it comes with different limitations.
256256

257-
Compatible with sync or async [Function Based Views](https://docs.djangoproject.com/en/dev/topics/http/views/) and [Class Based Views](https://docs.djangoproject.com/en/dev/topics/class-based-views/).
257+
Compatible with sync or async [Function Based Views](https://docs.djangoproject.com/en/stable/topics/http/views/) and [Class Based Views](https://docs.djangoproject.com/en/stable/topics/class-based-views/).
258258

259259
=== "components.py"
260260

@@ -383,7 +383,7 @@ Compatible with sync or async [Function Based Views](https://docs.djangoproject.
383383

384384
## Django CSS
385385

386-
Allows you to defer loading a CSS stylesheet until a component begins rendering. This stylesheet must be stored within [Django's static files](https://docs.djangoproject.com/en/dev/howto/static-files/).
386+
Allows you to defer loading a CSS stylesheet until a component begins rendering. This stylesheet must be stored within [Django's static files](https://docs.djangoproject.com/en/stable/howto/static-files/).
387387

388388
=== "components.py"
389389

@@ -436,11 +436,11 @@ Allows you to defer loading a CSS stylesheet until a component begins rendering.
436436

437437
## Django JS
438438

439-
Allows you to defer loading JavaScript until a component begins rendering. This JavaScript must be stored within [Django's static files](https://docs.djangoproject.com/en/dev/howto/static-files/).
439+
Allows you to defer loading JavaScript until a component begins rendering. This JavaScript must be stored within [Django's static files](https://docs.djangoproject.com/en/stable/howto/static-files/).
440440

441441
<!--
442-
TODO: This is no longer true since we don't insert elements on the page via JSON Patch anymore.
443-
However, we may go back to diffing at some point in the future.
442+
TODO: The following is no longer true since we don't insert elements on the page via JSON Patch anymore.
443+
However, we may go back to diffing at some point in the future so this is kept here for now.
444444
445445
!!! warning "Pitfall"
446446

Diff for: docs/src/reference/decorators.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Decorator functions can be used within your `components.py` to help simplify dev
1212

1313
You can limit component access to users that pass a test function by using this decorator.
1414

15-
This decorator is inspired by Django's [`user_passes_test`](http://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.decorators.user_passes_test) decorator, but this one works with ReactPy components.
15+
This only works with ReactPy components, and is inspired by Django's [`user_passes_test`](http://docs.djangoproject.com/en/stable/topics/auth/default/#django.contrib.auth.decorators.user_passes_test) decorator.
1616

1717
=== "components.py"
1818

0 commit comments

Comments
 (0)