Skip to content

Commit a0a6555

Browse files
authored
v1.0.0 (#73)
- Change Django IDOM version to 1.0.0 - Unpins top boundary on `channels` and `aiofile` - Bumps IDOM's minimum version - Use f-strings when possible - Use `contexlib.suppress` when possible - Implement `use_websocket`, `use_scope`, and `use_location` - Remove `websocket` parameter from components (replaced by `use_websocket` hook) - Create formal docs - Rename `idom_component` template tag to `component` in preparation for repo rename - Logging for when a component fails to import, or if no components were found within Django.
1 parent 83fcb8d commit a0a6555

30 files changed

+803
-232
lines changed

.github/workflows/publish-docs.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Publish Docs
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions/setup-python@v2
12+
with:
13+
python-version: 3.x
14+
- run: pip install requirements/build-docs.txt
15+
- run: mkdocs gh-deploy --force

CHANGELOG.md

+48-25
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5+
<!--attr-start-->
6+
7+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8+
9+
<!--attr-end-->
710

811
<!--
912
Types of changes are to be listed in this order
@@ -15,72 +18,92 @@ Types of changes are to be listed in this order
1518
- "Security" in case of vulnerabilities.
1619
-->
1720

21+
<!--changelog-start-->
22+
1823
## [Unreleased]
1924

20-
- Nothing (yet)
25+
- Nothing (yet)
26+
27+
## [1.0.0] - 2022-05-22
28+
29+
### Added
30+
31+
- Django-specific hooks! `use_websocket`, `use_scope`, and `use_location` are now available within the `django_idom.hooks` module.
32+
- Documentation has been placed into a formal docs webpage.
33+
- Logging for when a component fails to import, or if no components were found within Django.
34+
35+
### Changed
36+
37+
- `idom_component` template tag has been renamed to `component`
38+
- Bumped the minimum IDOM version to 0.38.0
39+
40+
### Removed
41+
42+
- `websocket` parameter for components has been removed. Functionally, it is replaced with `django_idom.hooks.use_websocket`.
2143

2244
## [0.0.5] - 2022-04-04
2345

2446
### Changed
2547

26-
- Bumped the minimum IDOM version to 0.37.2
48+
- Bumped the minimum IDOM version to 0.37.2
2749

2850
### Fixed
2951

30-
- ModuleNotFoundError: No module named `idom.core.proto` caused by IDOM 0.37.2
52+
- ModuleNotFoundError: No module named `idom.core.proto` caused by IDOM 0.37.2
3153

3254
## [0.0.4] - 2022-03-05
3355

3456
### Changed
3557

36-
- Bumped the minimum IDOM version to 0.37.1
58+
- Bumped the minimum IDOM version to 0.37.1
3759

3860
## [0.0.3] - 2022-02-19
3961

4062
### Changed
4163

42-
- Bumped the minimum IDOM version to 0.36.3
64+
- Bumped the minimum IDOM version to 0.36.3
4365

4466
## [0.0.2] - 2022-01-30
4567

4668
### Added
4769

48-
- Ability to declare the HTML class of the top-level component `div`
49-
- `name = ...` parameter to IDOM HTTP paths for use with `django.urls.reverse()`
50-
- Cache versioning to automatically invalidate old web module files from the cache backend
51-
- Automatic pre-population of the IDOM component registry
52-
- Type hinting for `IdomWebsocket`
70+
- Ability to declare the HTML class of the top-level component `div`
71+
- `name = ...` parameter to IDOM HTTP paths for use with `django.urls.reverse()`
72+
- Cache versioning to automatically invalidate old web module files from the cache backend
73+
- Automatic pre-population of the IDOM component registry
74+
- Type hinting for `IdomWebsocket`
5375

5476
### Changed
5577

56-
- Fetching web modules from disk and/or cache is now fully async
57-
- Static files are now contained within a `django_idom/` parent folder
58-
- Upgraded IDOM to version `0.36.0`
59-
- Minimum Django version required is now `4.0`
60-
- Minimum Python version required is now `3.8`
78+
- Fetching web modules from disk and/or cache is now fully async
79+
- Static files are now contained within a `django_idom/` parent folder
80+
- Upgraded IDOM to version `0.36.0`
81+
- Minimum Django version required is now `4.0`
82+
- Minimum Python version required is now `3.8`
6183

6284
### Removed
6385

64-
- `IDOM_WEB_MODULES_PATH` has been replaced with Django `include(...)`
65-
- `IDOM_WS_MAX_RECONNECT_DELAY` has been renamed to `IDOM_WS_MAX_RECONNECT_TIMEOUT`
66-
- `idom_web_modules` cache backend has been renamed to `idom`
86+
- `IDOM_WEB_MODULES_PATH` has been replaced with Django `include(...)`
87+
- `IDOM_WS_MAX_RECONNECT_DELAY` has been renamed to `IDOM_WS_MAX_RECONNECT_TIMEOUT`
88+
- `idom_web_modules` cache backend has been renamed to `idom`
6789

6890
### Fixed
6991

70-
- Increase test timeout values to prevent false positives
71-
- Windows compatibility for building Django-IDOM
92+
- Increase test timeout values to prevent false positives
93+
- Windows compatibility for building Django-IDOM
7294

7395
### Security
7496

75-
- Fixed potential directory travesal attack on the IDOM web modules URL
97+
- Fixed potential directory travesal attack on the IDOM web modules URL
7698

7799
## [0.0.1] - 2021-08-18
78100

79101
### Added
80102

81-
- Support for IDOM within the Django
103+
- Support for IDOM within the Django
82104

83-
[unreleased]: https://github.com/idom-team/django-idom/compare/0.0.2...HEAD
105+
[unreleased]: https://github.com/idom-team/django-idom/compare/1.0.0...HEAD
106+
[1.0.0]: https://github.com/idom-team/django-idom/compare/0.0.5...1.0.0
84107
[0.0.5]: https://github.com/idom-team/django-idom/compare/0.0.4...0.0.5
85108
[0.0.4]: https://github.com/idom-team/django-idom/compare/0.0.3...0.0.4
86109
[0.0.3]: https://github.com/idom-team/django-idom/compare/0.0.2...0.0.3

README.md

+48-153
Original file line numberDiff line numberDiff line change
@@ -1,184 +1,79 @@
1-
# Django IDOM &middot; [![Tests](https://github.com/idom-team/django-idom/workflows/Test/badge.svg?event=push)](https://github.com/idom-team/django-idom/actions?query=workflow%3ATest) [![PyPI Version](https://img.shields.io/pypi/v/django-idom.svg)](https://pypi.python.org/pypi/django-idom) [![License](https://img.shields.io/badge/License-MIT-purple.svg)](https://github.com/idom-team/django-idom/blob/main/LICENSE)
2-
3-
`django-idom` allows Django to integrate with [IDOM](https://github.com/idom-team/idom), a reactive Python web framework for building **interactive websites without needing a single line of Javascript**.
4-
5-
**You can try IDOM now in a Jupyter Notebook:**
6-
<a
7-
target="_blank"
8-
href="https://mybinder.org/v2/gh/idom-team/idom-jupyter/main?filepath=notebooks%2Fintroduction.ipynb">
9-
<img
10-
alt="Binder"
11-
valign="bottom"
12-
height="21px"
13-
src="https://mybinder.org/badge_logo.svg"/>
14-
</a>
15-
16-
# Quick Example
17-
18-
## `example_app/components.py`
19-
20-
This is where you'll define your [IDOM](https://github.com/idom-team/idom) components. Ultimately though, you should
21-
feel free to organize your component modules as you wish. Any components created will ultimately be referenced
22-
by Python dotted path in `your-template.html`.
23-
24-
```python
25-
from idom import component, html
26-
from django_idom import IdomWebsocket
27-
28-
# Components are CamelCase by ReactJS convention
29-
@component
30-
def Hello(websocket: IdomWebsocket, greeting_recipient: str):
31-
return html.h1(f"Hello {greeting_recipient}!")
32-
```
33-
34-
## [`example_app/templates/your-template.html`](https://docs.djangoproject.com/en/dev/topics/templates/)
35-
36-
In your templates, you may add IDOM components into your HTML by using the `idom_component`
37-
template tag. This tag requires the dotted path to the component function.
38-
39-
Additonally, you can pass in keyworded arguments into your component function.
40-
41-
In context this will look a bit like the following...
42-
43-
```jinja
44-
{% load idom %}
45-
46-
<!DOCTYPE html>
47-
<html>
48-
<head>
49-
<title>Example Project</title>
50-
</head>
51-
52-
<body>
53-
{% idom_component "my_django_project.example_app.components.Hello" greeting_recipient="World" %}
54-
</body>
55-
</html>
56-
```
57-
58-
# Installation
59-
60-
Install `django-idom` via pip.
1+
<!--header-start-->
612

62-
```bash
63-
pip install django-idom
64-
```
65-
66-
You'll also need to modify a few files in your Django project.
67-
68-
## [`settings.py`](https://docs.djangoproject.com/en/dev/topics/settings/)
69-
70-
In your settings you'll need to add `channels` and `django_idom` to [`INSTALLED_APPS`](https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-INSTALLED_APPS).
71-
72-
```python
73-
INSTALLED_APPS = [
74-
...,
75-
"channels",
76-
"django_idom",
77-
]
78-
79-
# Ensure ASGI_APPLICATION is set properly based on your project name!
80-
ASGI_APPLICATION = "my_django_project.asgi.application"
81-
```
82-
83-
**Optional:** You can also configure IDOM settings.
3+
# Django IDOM &middot; [![Tests](https://github.com/idom-team/django-idom/workflows/Test/badge.svg?event=push)](https://github.com/idom-team/django-idom/actions?query=workflow%3ATest) [![PyPI Version](https://img.shields.io/pypi/v/django-idom.svg)](https://pypi.python.org/pypi/django-idom) [![License](https://img.shields.io/badge/License-MIT-purple.svg)](https://github.com/idom-team/django-idom/blob/main/LICENSE)
844

85-
```python
86-
# If "idom" cache is not configured, then we'll use "default" instead
87-
CACHES = {
88-
"idom": {"BACKEND": ...},
89-
}
5+
<!--header-end-->
6+
<!--intro-start-->
907

91-
# Maximum seconds between two reconnection attempts that would cause the client give up.
92-
# 0 will disable reconnection.
93-
IDOM_WS_MAX_RECONNECT_TIMEOUT: int = 604800
8+
Django-IDOM connects your project to a ReactJS frontend, allowing you to create **interactive websites without needing JavaScript!**
949

95-
# The URL for IDOM to serve websockets
96-
IDOM_WEBSOCKET_URL: str = "idom/"
97-
```
10+
Following ReactJS styling, web elements are combined into [reusable "components"](https://idom-docs.herokuapp.com/docs/guides/creating-interfaces/your-first-components/index.html#parametrizing-components). These components can utilize [hooks](https://idom-docs.herokuapp.com/docs/reference/hooks-api.html) and [events](https://idom-docs.herokuapp.com/docs/guides/adding-interactivity/responding-to-events/index.html#async-event-handlers) to create infinitely complex web pages.
9811

99-
## [`urls.py`](https://docs.djangoproject.com/en/dev/topics/http/urls/)
12+
When needed, IDOM can [use components directly from NPM](https://idom-docs.herokuapp.com/docs/guides/escape-hatches/javascript-components.html#dynamically-loaded-components). For additional flexibility, components can also be [fully developed in JavaScript](https://idom-docs.herokuapp.com/docs/guides/escape-hatches/javascript-components.html#custom-javascript-components).
10013

101-
Add IDOM HTTP paths to your `urlpatterns`.
14+
Any Python web framework with Websockets can support IDOM. See below for what frameworks are supported out of the box.
10215

103-
```python
104-
from django.urls import include, path
16+
| Supported Frameworks | Supported Frameworks (External) |
17+
| ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18+
| [`Flask`, `FastAPI`, `Sanic`, `Tornado`](https://idom-docs.herokuapp.com/docs/guides/getting-started/installing-idom.html#officially-supported-servers) | [`Django`](https://github.com/idom-team/django-idom), [`Plotly-Dash`](https://github.com/idom-team/idom-dash), [`Jupyter`](https://github.com/idom-team/idom-jupyter) |
10519

106-
urlpatterns = [
107-
path("idom/", include("django_idom.http.urls")),
108-
...
109-
]
110-
```
20+
<!--intro-end-->
11121

112-
## [`asgi.py`](https://docs.djangoproject.com/en/dev/howto/deployment/asgi/)
22+
---
11323

114-
Register IDOM's websocket using `IDOM_WEBSOCKET_PATH`.
24+
# At a Glance
11525

116-
_Note: If you do not have an `asgi.py`, follow the [`channels` installation guide](https://channels.readthedocs.io/en/stable/installation.html)._
26+
## `my_app/components.py`
11727

118-
```python
28+
<!--py-header-start-->
11929

120-
import os
121-
from django.core.asgi import get_asgi_application
30+
You'll need a file to define your [IDOM](https://github.com/idom-team/idom) components. We recommend creating a `components.py` file within your chosen **Django app** to start out.
12231

123-
# Ensure DJANGO_SETTINGS_MODULE is set properly based on your project name!
124-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_django_project.settings")
125-
django_asgi_app = get_asgi_application()
32+
<!--py-header-end-->
33+
<!--py-code-start-->
12634

127-
from channels.auth import AuthMiddlewareStack
128-
from channels.routing import ProtocolTypeRouter, URLRouter
129-
from channels.sessions import SessionMiddlewareStack
130-
from django_idom import IDOM_WEBSOCKET_PATH
35+
```python title="components.py"
36+
from idom import component, html
13137

132-
application = ProtocolTypeRouter(
133-
{
134-
"http": django_asgi_app,
135-
"websocket": SessionMiddlewareStack(
136-
AuthMiddlewareStack(URLRouter([IDOM_WEBSOCKET_PATH]))
137-
),
138-
}
139-
)
38+
@component
39+
def HelloWorld(recipient: str):
40+
return html.h1(f"Hello {recipient}!")
14041
```
14142

142-
# Developer Guide
43+
<!--py-code-end-->
14344

144-
If you plan to make code changes to this repository, you'll need to install the
145-
following dependencies first:
45+
## [`my_app/templates/my-template.html`](https://docs.djangoproject.com/en/dev/topics/templates/)
14646

147-
- [NPM](https://docs.npmjs.com/try-the-latest-stable-version-of-npm) for
148-
installing and managing Javascript
149-
- [ChromeDriver](https://chromedriver.chromium.org/downloads) for testing with
150-
[Selenium](https://www.seleniumhq.org/)
47+
<!--html-header-start-->
15148

152-
Once done, you should clone this repository:
49+
In your **Django app**'s HTML located within your `templates` folder, 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.
15350

154-
```bash
155-
git clone https://github.com/idom-team/django-idom.git
156-
cd django-idom
157-
```
158-
159-
Then, by running the command below you can:
51+
Additonally, 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 `HelloWorld` (_in the previous example_) accepts a `recipient` argument.
16052

161-
- Install an editable version of the Python code
53+
<!--html-header-end-->
54+
<!--html-code-start-->
16255

163-
- Download, build, and install Javascript dependencies
164-
165-
```bash
166-
pip install -e . -r requirements.txt
56+
```jinja title="my-template.html"
57+
{% load idom %}
58+
<!DOCTYPE html>
59+
<html>
60+
<body>
61+
{% component "example_project.my_app.components.HelloWorld" recipient="World" %}
62+
</body>
63+
</html>
16764
```
16865

169-
Finally, to verify that everything is working properly, you'll want to run the test suite.
66+
<!--html-code-end-->
17067

171-
## Running The Tests
68+
---
17269

173-
This repo uses [Nox](https://nox.thea.codes/en/stable/) to run scripts which can
174-
be found in `noxfile.py`. For a full test of available scripts run `nox -l`. To run the full test suite simple execute:
70+
# Resources
17571

176-
```
177-
nox -s test
178-
```
72+
<!--resources-start-->
17973

180-
To run the tests using a headless browser:
74+
Follow the links below to find out more about this project.
18175

182-
```
183-
nox -s test -- --headless
184-
```
76+
- [Try it Now](https://mybinder.org/v2/gh/idom-team/idom-jupyter/main?urlpath=lab/tree/notebooks/introduction.ipynb) - Check out IDOM in a Jupyter Notebook.
77+
- [Documentation](https://idom-team.github.io/django-idom) - Learn how to install, run, and use IDOM.
78+
- [Community Forum](https://github.com/idom-team/idom/discussions) - Ask questions, share ideas, and show off projects.
79+
<!--resources-end-->

docs/changelog/index.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
hide:
3+
- navigation
4+
- toc
5+
---
6+
7+
!!! note "Attribution"
8+
9+
{% include-markdown "../../CHANGELOG.md" start="<!--attr-start-->" end="<!--attr-end-->" %}
10+
11+
{% include-markdown "../../CHANGELOG.md" start="<!--changelog-start-->" %}

0 commit comments

Comments
 (0)