pyview-web 0.0.20__tar.gz → 0.0.21__tar.gz

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.

Files changed (46) hide show
  1. {pyview_web-0.0.20 → pyview_web-0.0.21}/PKG-INFO +1 -1
  2. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyproject.toml +1 -1
  3. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/live_view.py +10 -10
  4. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/pyview.py +9 -1
  5. pyview_web-0.0.21/pyview/template/__init__.py +17 -0
  6. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/template/root_template.py +5 -1
  7. pyview_web-0.0.21/pyview/template/utils.py +24 -0
  8. pyview_web-0.0.20/pyview/template/__init__.py +0 -3
  9. {pyview_web-0.0.20 → pyview_web-0.0.21}/LICENSE +0 -0
  10. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/__init__.py +0 -0
  11. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/assets/js/app.js +0 -0
  12. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/assets/package-lock.json +0 -0
  13. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/assets/package.json +0 -0
  14. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/auth/__init__.py +0 -0
  15. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/auth/provider.py +0 -0
  16. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/auth/required.py +0 -0
  17. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/changesets/__init__.py +0 -0
  18. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/changesets/changesets.py +0 -0
  19. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/csrf.py +0 -0
  20. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/events.py +0 -0
  21. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/js.py +0 -0
  22. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/live_routes.py +0 -0
  23. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/live_socket.py +0 -0
  24. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/phx_message.py +0 -0
  25. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/secret.py +0 -0
  26. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/session.py +0 -0
  27. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/static/assets/app.js +0 -0
  28. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/template/live_template.py +0 -0
  29. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/template/serializer.py +0 -0
  30. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/test_csrf.py +0 -0
  31. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/uploads.py +0 -0
  32. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/__init__.py +0 -0
  33. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/flet/pubsub/__init__.py +0 -0
  34. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/flet/pubsub/pub_sub.py +0 -0
  35. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/ibis/__init__.py +0 -0
  36. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/ibis/compiler.py +0 -0
  37. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/ibis/context.py +0 -0
  38. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/ibis/errors.py +0 -0
  39. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/ibis/filters.py +0 -0
  40. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/ibis/loaders.py +0 -0
  41. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/ibis/nodes.py +0 -0
  42. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/ibis/template.py +0 -0
  43. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/ibis/tree.py +0 -0
  44. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/vendor/ibis/utils.py +0 -0
  45. {pyview_web-0.0.20 → pyview_web-0.0.21}/pyview/ws_handler.py +0 -0
  46. {pyview_web-0.0.20 → pyview_web-0.0.21}/readme.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyview-web
3
- Version: 0.0.20
3
+ Version: 0.0.21
4
4
  Summary: LiveView in Python
5
5
  Home-page: https://pyview.rocks
6
6
  License: MIT
@@ -5,7 +5,7 @@ packages = [
5
5
  { include = "pyview" },
6
6
  ]
7
7
 
8
- version = "0.0.20"
8
+ version = "0.0.21"
9
9
  description = "LiveView in Python"
10
10
  authors = ["Larry Ogrodnek <ogrodnek@gmail.com>"]
11
11
  license = "MIT"
@@ -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 LiveTemplate, template_file, RenderedContent, LiveRender
4
- import inspect
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
- cf = inspect.getfile(m.__class__)
47
- return _find_template(cf)
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)
@@ -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 RootTemplate, RootTemplateContext, defaultRootTemplate
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))
@@ -0,0 +1,17 @@
1
+ from pyview.vendor.ibis import Template
2
+ from .live_template import LiveTemplate, template_file, RenderedContent, LiveRender
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
+ ]
@@ -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
  )
@@ -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 []
@@ -1,3 +0,0 @@
1
- from pyview.vendor.ibis import Template
2
- from .live_template import LiveTemplate, template_file, RenderedContent, LiveRender
3
- from .root_template import RootTemplate, RootTemplateContext, defaultRootTemplate
File without changes
File without changes
File without changes
File without changes