pyview-web 0.0.20__py3-none-any.whl → 0.0.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyview-web might be problematic. Click here for more details.
- pyview/live_view.py +10 -10
- pyview/pyview.py +9 -1
- pyview/template/__init__.py +14 -0
- pyview/template/root_template.py +5 -1
- pyview/template/utils.py +24 -0
- {pyview_web-0.0.20.dist-info → pyview_web-0.0.21.dist-info}/METADATA +1 -1
- {pyview_web-0.0.20.dist-info → pyview_web-0.0.21.dist-info}/RECORD +9 -8
- {pyview_web-0.0.20.dist-info → pyview_web-0.0.21.dist-info}/LICENSE +0 -0
- {pyview_web-0.0.20.dist-info → pyview_web-0.0.21.dist-info}/WHEEL +0 -0
pyview/live_view.py
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
from typing import TypeVar, Generic, Optional, Union, Any
|
|
2
2
|
from .live_socket import LiveViewSocket, UnconnectedSocket
|
|
3
|
-
from pyview.template import
|
|
4
|
-
|
|
3
|
+
from pyview.template import (
|
|
4
|
+
LiveTemplate,
|
|
5
|
+
template_file,
|
|
6
|
+
RenderedContent,
|
|
7
|
+
LiveRender,
|
|
8
|
+
find_associated_file,
|
|
9
|
+
)
|
|
5
10
|
from pyview.events import InfoEvent
|
|
6
11
|
from urllib.parse import ParseResult
|
|
7
12
|
|
|
@@ -43,11 +48,6 @@ class LiveView(Generic[T]):
|
|
|
43
48
|
|
|
44
49
|
|
|
45
50
|
def _find_render(m: LiveView) -> Optional[LiveTemplate]:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def _find_template(cf: str) -> Optional[LiveTemplate]:
|
|
51
|
-
if cf.endswith(".py"):
|
|
52
|
-
cf = cf[:-3]
|
|
53
|
-
return template_file(cf + ".html")
|
|
51
|
+
html = find_associated_file(m, ".html")
|
|
52
|
+
if html is not None:
|
|
53
|
+
return template_file(html)
|
pyview/pyview.py
CHANGED
|
@@ -14,7 +14,12 @@ from pyview.auth import AuthProviderFactory
|
|
|
14
14
|
from .ws_handler import LiveSocketHandler
|
|
15
15
|
from .live_view import LiveView
|
|
16
16
|
from .live_routes import LiveViewLookup
|
|
17
|
-
from .template import
|
|
17
|
+
from .template import (
|
|
18
|
+
RootTemplate,
|
|
19
|
+
RootTemplateContext,
|
|
20
|
+
defaultRootTemplate,
|
|
21
|
+
find_associated_css,
|
|
22
|
+
)
|
|
18
23
|
|
|
19
24
|
|
|
20
25
|
class PyView(Starlette):
|
|
@@ -57,6 +62,8 @@ async def liveview_container(
|
|
|
57
62
|
await lv.handle_params(urlparse(url._url), parse_qs(url.query), s)
|
|
58
63
|
r = await lv.render(s.context)
|
|
59
64
|
|
|
65
|
+
liveview_css = find_associated_css(lv)
|
|
66
|
+
|
|
60
67
|
id = str(uuid.uuid4())
|
|
61
68
|
|
|
62
69
|
context: RootTemplateContext = {
|
|
@@ -65,6 +72,7 @@ async def liveview_container(
|
|
|
65
72
|
"title": s.live_title,
|
|
66
73
|
"csrf_token": generate_csrf_token("lv:phx-" + id),
|
|
67
74
|
"session": serialize_session(session),
|
|
75
|
+
"additional_head_elements": liveview_css,
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
return HTMLResponse(template(context))
|
pyview/template/__init__.py
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
from pyview.vendor.ibis import Template
|
|
2
2
|
from .live_template import LiveTemplate, template_file, RenderedContent, LiveRender
|
|
3
3
|
from .root_template import RootTemplate, RootTemplateContext, defaultRootTemplate
|
|
4
|
+
from .utils import find_associated_css, find_associated_file
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"Template",
|
|
8
|
+
"LiveTemplate",
|
|
9
|
+
"template_file",
|
|
10
|
+
"RenderedContent",
|
|
11
|
+
"LiveRender",
|
|
12
|
+
"RootTemplate",
|
|
13
|
+
"RootTemplateContext",
|
|
14
|
+
"defaultRootTemplate",
|
|
15
|
+
"find_associated_css",
|
|
16
|
+
"find_associated_file",
|
|
17
|
+
]
|
pyview/template/root_template.py
CHANGED
|
@@ -8,6 +8,7 @@ class RootTemplateContext(TypedDict):
|
|
|
8
8
|
title: Optional[str]
|
|
9
9
|
csrf_token: str
|
|
10
10
|
session: Optional[str]
|
|
11
|
+
additional_head_elements: list[Markup]
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
RootTemplate = Callable[[RootTemplateContext], str]
|
|
@@ -45,6 +46,8 @@ def _defaultRootTemplate(
|
|
|
45
46
|
),
|
|
46
47
|
)
|
|
47
48
|
|
|
49
|
+
additional_head_elements = "\n".join(context["additional_head_elements"])
|
|
50
|
+
|
|
48
51
|
return (
|
|
49
52
|
Markup(
|
|
50
53
|
f"""
|
|
@@ -56,8 +59,9 @@ def _defaultRootTemplate(
|
|
|
56
59
|
<meta charset="utf-8">
|
|
57
60
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
58
61
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
59
|
-
{css}
|
|
62
|
+
{css}
|
|
60
63
|
<script defer type="text/javascript" src="/static/assets/app.js"></script>
|
|
64
|
+
{additional_head_elements}
|
|
61
65
|
</head>
|
|
62
66
|
<body>"""
|
|
63
67
|
)
|
pyview/template/utils.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import inspect
|
|
3
|
+
import os
|
|
4
|
+
from markupsafe import Markup
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def find_associated_file(o: object, extension: str) -> Optional[str]:
|
|
8
|
+
object_file = inspect.getfile(o.__class__)
|
|
9
|
+
|
|
10
|
+
if object_file.endswith(".py"):
|
|
11
|
+
object_file = object_file[:-3]
|
|
12
|
+
|
|
13
|
+
associated_file = object_file + extension
|
|
14
|
+
if os.path.isfile(associated_file):
|
|
15
|
+
return associated_file
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def find_associated_css(o: object) -> list[Markup]:
|
|
19
|
+
css_file = find_associated_file(o, ".css")
|
|
20
|
+
if css_file:
|
|
21
|
+
with open(css_file, "r") as css:
|
|
22
|
+
return [Markup(f"<style>{css.read()}</style>")]
|
|
23
|
+
|
|
24
|
+
return []
|
|
@@ -12,16 +12,17 @@ pyview/events.py,sha256=Zv8G2F1XeXUk1wrnfomeFfxB0OPYmHdjSvxRjQew3No,125
|
|
|
12
12
|
pyview/js.py,sha256=4OnPEfBfuvmekeQlm9444As4PLR22zLMIyyzQIIkmls,751
|
|
13
13
|
pyview/live_routes.py,sha256=tsKFh2gmH2BWsjsZQZErzRp_-KiAZcn4lFKNLRIN5Nc,498
|
|
14
14
|
pyview/live_socket.py,sha256=6SLEkEBzK-zIUNh_5j_OG5t6IHGTDNCpGXk7D7SMNJ4,4370
|
|
15
|
-
pyview/live_view.py,sha256=
|
|
15
|
+
pyview/live_view.py,sha256=A0vCCvHUy39_eEhRzDbYMEDzgpRqseZPjCnBAMjogxw,1406
|
|
16
16
|
pyview/phx_message.py,sha256=DUdPfl6tlw9K0FNXJ35ehq03JGgynvwA_JItHQ_dxMQ,2007
|
|
17
|
-
pyview/pyview.py,sha256=
|
|
17
|
+
pyview/pyview.py,sha256=xy8on2f-chU4JWVy6zGTDqjP8BW-kOoi16voNIgWRg4,2478
|
|
18
18
|
pyview/secret.py,sha256=HbaNpGAkFs4uxMVAmk9HwE3FIehg7dmwEOlED7C9moM,363
|
|
19
19
|
pyview/session.py,sha256=nC8ExyVwfCgQfx9T-aJGyFhr2C7jsrEY_QFkaXtP28U,432
|
|
20
20
|
pyview/static/assets/app.js,sha256=QoXfdcOCYwVYJftvjsIIVwFye7onaOJMxRpalyYqoMU,200029
|
|
21
|
-
pyview/template/__init__.py,sha256=
|
|
21
|
+
pyview/template/__init__.py,sha256=c5hLRfsF2fDOz8aOsoOgoCeBV6VBzdqN_Ktg3mYPw8A,509
|
|
22
22
|
pyview/template/live_template.py,sha256=wSKyBw7ejpUY5qXUZdE36Jeeix8Of0CUq8eZdQwxXyg,1864
|
|
23
|
-
pyview/template/root_template.py,sha256=
|
|
23
|
+
pyview/template/root_template.py,sha256=zCUs1bt8R7qynhBE0tTSEYfdkGtbeKNmPhwzRiFNdsI,2031
|
|
24
24
|
pyview/template/serializer.py,sha256=WDZfqJr2LMlf36fUW2CmWc2aREc63553_y_GRP2-qYc,826
|
|
25
|
+
pyview/template/utils.py,sha256=S8593UjUJztUrtC3h1EL9MxQp5uH7rFDTNkv9C6A_xU,642
|
|
25
26
|
pyview/test_csrf.py,sha256=QWTOtfagDMkoYDK_ehYxua34F7-ltPsSeTwQGEOlqHU,684
|
|
26
27
|
pyview/uploads.py,sha256=cFNOlJD5dkA2VccZT_W1bJn_5vYAaphhRJX-RCfEXm8,9598
|
|
27
28
|
pyview/vendor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -38,7 +39,7 @@ pyview/vendor/ibis/template.py,sha256=IX9z-Ig13yJyRnMqtB52eiRLe002qdIxnfa7fYEXLq
|
|
|
38
39
|
pyview/vendor/ibis/tree.py,sha256=5LAjl3q9iPMZBb6QbKurWj9-QGKLVf11K2_bQotWlUc,2293
|
|
39
40
|
pyview/vendor/ibis/utils.py,sha256=nLSaxPR9vMphzV9qinlz_Iurv9c49Ps6Knv8vyNlewU,2768
|
|
40
41
|
pyview/ws_handler.py,sha256=Mkbw6UKEy4HYURSZUdmpF95oWiuEymzS_VGG8WV8mGw,7977
|
|
41
|
-
pyview_web-0.0.
|
|
42
|
-
pyview_web-0.0.
|
|
43
|
-
pyview_web-0.0.
|
|
44
|
-
pyview_web-0.0.
|
|
42
|
+
pyview_web-0.0.21.dist-info/LICENSE,sha256=M_bADaBm9_MV9llX3lCicksLhwk3eZUjA2srE0uUWr0,1071
|
|
43
|
+
pyview_web-0.0.21.dist-info/METADATA,sha256=zdBbcWKMhS8AmhaKam_H89jKFTcSGh7yEG_gILGXOWY,5276
|
|
44
|
+
pyview_web-0.0.21.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
45
|
+
pyview_web-0.0.21.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|