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

view_to_iframe component #188

Merged
merged 29 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7938867
`view_to_iframe` component
Archmonger Sep 19, 2023
0ab5822
add changelog
Archmonger Sep 19, 2023
40b846f
Merge remote-tracking branch 'upstream/main' into view-to-iframe
Archmonger Sep 21, 2023
79462f9
functional view_to_iframe
Archmonger Sep 22, 2023
68e15a0
ViewToIframeConstructor type
Archmonger Sep 22, 2023
46dc39e
temporarily remove section index plugin
Archmonger Sep 22, 2023
b508589
better API
Archmonger Sep 23, 2023
afe31ac
update docs
Archmonger Sep 23, 2023
1b46664
Auto height and width
Archmonger Sep 23, 2023
38799ce
interface docs
Archmonger Sep 23, 2023
b45f7a9
register_iframe function
Archmonger Sep 24, 2023
8ac3415
move error tests to their own URL
Archmonger Sep 24, 2023
89af32d
reorganize and fix type hints
Archmonger Sep 24, 2023
b296774
update component docs
Archmonger Sep 24, 2023
e8e8455
misc docs tweaks
Archmonger Sep 24, 2023
614b863
add test for ComponentNotRegisteredError
Archmonger Sep 24, 2023
b3f2548
misc doc tweaks
Archmonger Sep 24, 2023
9bb8dda
Register Iframe docs
Archmonger Sep 24, 2023
c55ee3b
add interface utils.md
Archmonger Sep 24, 2023
63e6c98
more obvious error
Archmonger Sep 24, 2023
39171d0
ViewNotRegisteredError and ViewDoesNotExistError
Archmonger Sep 24, 2023
2b66156
clean up register component example
Archmonger Sep 24, 2023
376f7b7
remove dead types
Archmonger Sep 24, 2023
0eb6e90
misc docs tweaks
Archmonger Sep 24, 2023
b52a400
remove thread sensitive
Archmonger Sep 24, 2023
ea067e0
Use .as_view() for CBVs
Archmonger Sep 24, 2023
cad5720
update changelog
Archmonger Sep 24, 2023
b702eea
fix broken example
Archmonger Sep 25, 2023
bf768e0
revert proper docs tests while `reactpy.html` type hints suck
Archmonger Sep 25, 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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,19 @@ Using the following categories, list your changes in this order:
- ReactPy components can now use SEO compatible rendering!
- `settings.py:REACTPY_PRERENDER` can be set to `True` to enable this behavior by default
- Or, you can enable it on individual components via the template tag: `{% component "..." prerender="True" %}`
- `reactpy_django.components.view_to_iframe` component has been added, which uses an `<iframe>` to render a Django view.
- `reactpy_django.utils.register_iframe` function has been added, which is mandatory to use alongside `reactpy_django.components.view_to_iframe`.

### Changed

- Renamed undocumented utility function `reactpy_django.utils.ComponentPreloader` to `reactpy_django.utils.RootComponentFinder`.
- It is now recommended to call `as_view()` when using `view_to_component` or `view_to_iframe` with Class Based Views.
- Thread sensitivity has been enabled in all locations where ORM queries are possible.

### Deprecated

- The `compatibility` argument on `reactpy_django.components.view_to_component` is deprecated. Use `reactpy_django.components.view_to_iframe` instead.
- Using `reactpy_django.components.view_to_component` as a decorator is deprecated. Check the docs on the new suggested usage.

## [3.5.1] - 2023-09-07

Expand Down
11 changes: 11 additions & 0 deletions docs/python/hello_world_app_config_cbv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.apps import AppConfig
from reactpy_django.utils import register_iframe

from . import views


class ExampleAppConfig(AppConfig):
name = "example"

def ready(self):
register_iframe(views.HelloWorld)
11 changes: 11 additions & 0 deletions docs/python/hello_world_app_config_fbv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.apps import AppConfig
from reactpy_django.utils import register_iframe

from . import views


class ExampleAppConfig(AppConfig):
name = "example"

def ready(self):
register_iframe(views.hello_world)
5 changes: 5 additions & 0 deletions docs/python/hello_world_args_kwargs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.http import HttpResponse


def hello_world(request, arg1, arg2, kwarg1=None, kwarg2=None):
return HttpResponse(f"Hello World! {arg1} {arg2} {kwarg1} {kwarg2}")
7 changes: 7 additions & 0 deletions docs/python/hello_world_cbv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.http import HttpResponse
from django.views import View


class HelloWorld(View):
def get(self, request):
return HttpResponse("Hello World!")
5 changes: 5 additions & 0 deletions docs/python/hello_world_fbv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.http import HttpResponse


def hello_world(request):
return HttpResponse("Hello World!")
5 changes: 5 additions & 0 deletions docs/python/hello_world_fbv_with_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.http import HttpResponse


def hello_world(request):
return HttpResponse('<div id="hello-world"> Hello World! </div>')
5 changes: 3 additions & 2 deletions docs/python/register-component.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from reactpy_django.utils import register_component


class ExampleConfig(AppConfig):
class ExampleAppConfig(AppConfig):
name = "example"

def ready(self):
# Add components to the ReactPy component registry when Django is ready
register_component("example_project.my_app.components.hello_world")
2 changes: 1 addition & 1 deletion docs/python/use-mutation-thread-sensitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from reactpy_django.types import MutationOptions


def execute_thread_safe_mutation():
def execute_thread_safe_mutation(text):
"""This is an example mutation function that does some thread-safe operation."""
pass

Expand Down
7 changes: 7 additions & 0 deletions docs/python/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .hello_world_cbv import HelloWorld
from .hello_world_fbv import hello_world

__all__ = [
"HelloWorld",
"hello_world",
]
21 changes: 0 additions & 21 deletions docs/python/vtc-args-kwargs.py

This file was deleted.

23 changes: 23 additions & 0 deletions docs/python/vtc-args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.http import HttpRequest
from reactpy import component, html
from reactpy_django.components import view_to_component

from . import views

hello_world_component = view_to_component(views.hello_world)


@component
def my_component():
request = HttpRequest()
request.method = "GET"

return html.div(
hello_world_component(
request, # This request object is optional.
"value_1",
"value_2",
kwarg1="abc",
kwarg2="123",
),
)
10 changes: 0 additions & 10 deletions docs/python/vtc-cbv-compatibility.py

This file was deleted.

12 changes: 3 additions & 9 deletions docs/python/vtc-cbv.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
from django.http import HttpResponse
from django.views import View
from reactpy import component, html
from reactpy_django.components import view_to_component

from . import views

class HelloWorldView(View):
def get(self, request):
return HttpResponse("Hello World!")


vtc = view_to_component(HelloWorldView)
hello_world_component = view_to_component(views.HelloWorld.as_view())


@component
def my_component():
return html.div(
vtc(),
hello_world_component(),
)
15 changes: 0 additions & 15 deletions docs/python/vtc-compatibility.py

This file was deleted.

8 changes: 0 additions & 8 deletions docs/python/vtc-fbv-compat.py

This file was deleted.

12 changes: 0 additions & 12 deletions docs/python/vtc-func.py

This file was deleted.

20 changes: 0 additions & 20 deletions docs/python/vtc-request.py

This file was deleted.

8 changes: 3 additions & 5 deletions docs/python/vtc-strict-parsing.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from django.http import HttpResponse
from reactpy import component, html
from reactpy_django.components import view_to_component

from . import views

@view_to_component(strict_parsing=False)
def hello_world_view(request):
return HttpResponse("<my-tag> Hello World </my-tag>")
hello_world_component = view_to_component(views.hello_world)


@component
def my_component():
return html.div(
hello_world_view(),
hello_world_component(),
)
13 changes: 7 additions & 6 deletions docs/python/vtc-transforms.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from django.http import HttpResponse
from reactpy import component, html
from reactpy_django.components import view_to_component

from . import views


def example_transform(vdom):
attributes = vdom.get("attributes")
if attributes and attributes.get("id") == "hello-world":
vdom["children"][0] = "Good Bye World!"
vdom["children"][0] = "Farewell World!"


@view_to_component(transforms=[example_transform])
def hello_world_view(request):
return HttpResponse("<div id='hello-world'> Hello World! <div>")
hello_world_component = view_to_component(
views.hello_world, transforms=[example_transform]
)


@component
def my_component():
return html.div(
hello_world_view(),
hello_world_component(),
)
8 changes: 3 additions & 5 deletions docs/python/vtc.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from django.http import HttpResponse
from reactpy import component, html
from reactpy_django.components import view_to_component

from . import views

@view_to_component
def hello_world_view(request):
return HttpResponse("Hello World!")
hello_world_component = view_to_component(views.hello_world)


@component
def my_component():
return html.div(
hello_world_view(),
hello_world_component(),
)
20 changes: 20 additions & 0 deletions docs/python/vti-args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from reactpy import component, html
from reactpy_django.components import view_to_iframe

from . import views

hello_world_iframe = view_to_iframe(
views.hello_world,
)


@component
def my_component():
return html.div(
hello_world_iframe(
"value_1",
"value_2",
kwarg1="abc",
kwarg2="123",
),
)
13 changes: 13 additions & 0 deletions docs/python/vti-cbv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from reactpy import component, html
from reactpy_django.components import view_to_iframe

from . import views

hello_world_iframe = view_to_iframe(views.HelloWorld.as_view())


@component
def my_component():
return html.div(
hello_world_iframe(),
)
15 changes: 15 additions & 0 deletions docs/python/vti-extra-props.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from reactpy import component, html
from reactpy_django.components import view_to_iframe

from . import views

hello_world_iframe = view_to_iframe(
views.hello_world, extra_props={"title": "Hello World!"}
)


@component
def my_component():
return html.div(
hello_world_iframe(),
)
13 changes: 13 additions & 0 deletions docs/python/vti.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from reactpy import component, html
from reactpy_django.components import view_to_iframe

from . import views

hello_world_iframe = view_to_iframe(views.hello_world)


@component
def my_component():
return html.div(
hello_world_iframe(),
)
Loading