WuttaWeb 0.2.0__tar.gz → 0.4.0__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.
Files changed (95) hide show
  1. wuttaweb-0.4.0/CHANGELOG.md +50 -0
  2. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/PKG-INFO +5 -2
  3. wuttaweb-0.4.0/docs/api/wuttaweb/auth.rst +6 -0
  4. wuttaweb-0.4.0/docs/api/wuttaweb/db.rst +6 -0
  5. wuttaweb-0.4.0/docs/api/wuttaweb/forms.base.rst +6 -0
  6. wuttaweb-0.4.0/docs/api/wuttaweb/forms.rst +6 -0
  7. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/index.rst +8 -0
  8. wuttaweb-0.4.0/docs/api/wuttaweb/views.auth.rst +6 -0
  9. wuttaweb-0.4.0/docs/api/wuttaweb/views.essential.rst +6 -0
  10. wuttaweb-0.4.0/docs/api/wuttaweb/views.master.rst +6 -0
  11. wuttaweb-0.4.0/docs/api/wuttaweb/views.settings.rst +6 -0
  12. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/conf.py +3 -0
  13. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/pyproject.toml +5 -2
  14. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/app.py +18 -3
  15. wuttaweb-0.4.0/src/wuttaweb/auth.py +150 -0
  16. wuttaweb-0.4.0/src/wuttaweb/db.py +66 -0
  17. wuttaweb-0.4.0/src/wuttaweb/forms/__init__.py +31 -0
  18. wuttaweb-0.4.0/src/wuttaweb/forms/base.py +476 -0
  19. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/menus.py +3 -2
  20. wuttaweb-0.4.0/src/wuttaweb/static/img/favicon.ico +0 -0
  21. wuttaweb-0.4.0/src/wuttaweb/static/img/logo.png +0 -0
  22. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/subscribers.py +116 -3
  23. wuttaweb-0.4.0/src/wuttaweb/templates/appinfo/index.mako +56 -0
  24. wuttaweb-0.4.0/src/wuttaweb/templates/auth/change_password.mako +7 -0
  25. wuttaweb-0.4.0/src/wuttaweb/templates/auth/login.mako +48 -0
  26. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/templates/base.mako +51 -4
  27. wuttaweb-0.4.0/src/wuttaweb/templates/base_meta.mako +25 -0
  28. wuttaweb-0.4.0/src/wuttaweb/templates/deform/checked_password.pt +13 -0
  29. wuttaweb-0.4.0/src/wuttaweb/templates/deform/password.pt +8 -0
  30. wuttaweb-0.4.0/src/wuttaweb/templates/deform/textinput.pt +7 -0
  31. wuttaweb-0.4.0/src/wuttaweb/templates/form.mako +24 -0
  32. wuttaweb-0.4.0/src/wuttaweb/templates/forms/vue_template.mako +58 -0
  33. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/templates/home.mako +3 -5
  34. wuttaweb-0.4.0/src/wuttaweb/templates/master/index.mako +13 -0
  35. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/util.py +22 -1
  36. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/views/__init__.py +3 -1
  37. wuttaweb-0.4.0/src/wuttaweb/views/auth.py +288 -0
  38. wuttaweb-0.4.0/src/wuttaweb/views/base.py +99 -0
  39. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/views/common.py +4 -1
  40. wuttaweb-0.4.0/src/wuttaweb/views/essential.py +46 -0
  41. wuttaweb-0.4.0/src/wuttaweb/views/master.py +443 -0
  42. wuttaweb-0.2.0/src/wuttaweb/views/base.py → wuttaweb-0.4.0/src/wuttaweb/views/settings.py +15 -21
  43. wuttaweb-0.4.0/tests/forms/test_base.py +273 -0
  44. wuttaweb-0.4.0/tests/test_auth.py +145 -0
  45. wuttaweb-0.4.0/tests/test_subscribers.py +257 -0
  46. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tests/test_util.py +27 -0
  47. wuttaweb-0.4.0/tests/utils.py +11 -0
  48. wuttaweb-0.4.0/tests/views/__init__.py +0 -0
  49. wuttaweb-0.4.0/tests/views/test_auth.py +190 -0
  50. wuttaweb-0.4.0/tests/views/test_base.py +41 -0
  51. wuttaweb-0.4.0/tests/views/test_master.py +282 -0
  52. wuttaweb-0.4.0/tests/views/test_settings.py +13 -0
  53. wuttaweb-0.4.0/tests/views/utils.py +57 -0
  54. wuttaweb-0.2.0/CHANGELOG.md +0 -20
  55. wuttaweb-0.2.0/src/wuttaweb/templates/base_meta.mako +0 -21
  56. wuttaweb-0.2.0/tests/test_subscribers.py +0 -100
  57. wuttaweb-0.2.0/tests/views/test_base.py +0 -21
  58. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/.gitignore +0 -0
  59. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/COPYING.txt +0 -0
  60. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/README.md +0 -0
  61. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/Makefile +0 -0
  62. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/_static/.keepme +0 -0
  63. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/index.rst +0 -0
  64. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/app.rst +0 -0
  65. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/handler.rst +0 -0
  66. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/helpers.rst +0 -0
  67. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/menus.rst +0 -0
  68. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/static.rst +0 -0
  69. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/subscribers.rst +0 -0
  70. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/util.rst +0 -0
  71. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/views.base.rst +0 -0
  72. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/views.common.rst +0 -0
  73. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/api/wuttaweb/views.rst +0 -0
  74. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/glossary.rst +0 -0
  75. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/index.rst +0 -0
  76. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/make.bat +0 -0
  77. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/docs/narr/index.rst +0 -0
  78. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/__init__.py +0 -0
  79. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/_version.py +0 -0
  80. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/handler.py +0 -0
  81. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/helpers.py +0 -0
  82. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/static/__init__.py +0 -0
  83. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/static/img/testing.png +0 -0
  84. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/src/wuttaweb/templates/page.mako +0 -0
  85. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tasks.py +0 -0
  86. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tests/__init__.py +0 -0
  87. {wuttaweb-0.2.0/tests/views → wuttaweb-0.4.0/tests/forms}/__init__.py +0 -0
  88. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tests/test_app.py +0 -0
  89. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tests/test_handler.py +0 -0
  90. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tests/test_helpers.py +0 -0
  91. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tests/test_menus.py +0 -0
  92. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tests/test_static.py +0 -0
  93. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tests/views/test___init__.py +0 -0
  94. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tests/views/test_common.py +0 -0
  95. {wuttaweb-0.2.0 → wuttaweb-0.4.0}/tox.ini +0 -0
@@ -0,0 +1,50 @@
1
+
2
+ # Changelog
3
+ All notable changes to wuttaweb will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
+
8
+ ## v0.4.0 (2024-08-05)
9
+
10
+ ### Feat
11
+
12
+ - add basic App Info view (index only)
13
+ - add initial `MasterView` support
14
+
15
+ ### Fix
16
+
17
+ - add `notfound()` View method; auto-append trailing slash
18
+ - bump min version for wuttjamaican
19
+
20
+ ## v0.3.0 (2024-08-05)
21
+
22
+ ### Feat
23
+
24
+ - add support for admin user to become / stop being root
25
+ - add view to change current user password
26
+ - add basic logo, favicon images
27
+ - add auth views, for login/logout
28
+ - add custom security policy, login/logout for pyramid
29
+ - add `wuttaweb.views.essential` module
30
+ - add initial/basic forms support
31
+ - add `wuttaweb.db` module, with `Session`
32
+ - add `util.get_form_data()` convenience function
33
+
34
+ ### Fix
35
+
36
+ - allow custom user getter for `new_request_set_user()` hook
37
+
38
+ ## v0.2.0 (2024-07-14)
39
+
40
+ ### Feat
41
+
42
+ - add basic support for menu handler
43
+
44
+ - add "web handler" feature; it must get the menu handler
45
+
46
+ ## v0.1.0 (2024-07-12)
47
+
48
+ ### Feat
49
+
50
+ - basic support for WSGI app, views, templates
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: WuttaWeb
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Web App for Wutta Framework
5
5
  Project-URL: Homepage, https://wuttaproject.org/
6
6
  Project-URL: Repository, https://forgejo.wuttaproject.org/wutta/wuttaweb
@@ -25,11 +25,14 @@ Classifier: Topic :: Internet :: WWW/HTTP
25
25
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
26
  Requires-Python: >=3.8
27
27
  Requires-Dist: pyramid-beaker
28
+ Requires-Dist: pyramid-deform
28
29
  Requires-Dist: pyramid-mako
30
+ Requires-Dist: pyramid-tm
29
31
  Requires-Dist: pyramid>=2
30
32
  Requires-Dist: waitress
31
33
  Requires-Dist: webhelpers2
32
- Requires-Dist: wuttjamaican[db]>=0.7.0
34
+ Requires-Dist: wuttjamaican[db]>=0.8.3
35
+ Requires-Dist: zope-sqlalchemy>=1.5
33
36
  Provides-Extra: docs
34
37
  Requires-Dist: furo; extra == 'docs'
35
38
  Requires-Dist: sphinx; extra == 'docs'
@@ -0,0 +1,6 @@
1
+
2
+ ``wuttaweb.auth``
3
+ =================
4
+
5
+ .. automodule:: wuttaweb.auth
6
+ :members:
@@ -0,0 +1,6 @@
1
+
2
+ ``wuttaweb.db``
3
+ ===============
4
+
5
+ .. automodule:: wuttaweb.db
6
+ :members:
@@ -0,0 +1,6 @@
1
+
2
+ ``wuttaweb.forms.base``
3
+ =======================
4
+
5
+ .. automodule:: wuttaweb.forms.base
6
+ :members:
@@ -0,0 +1,6 @@
1
+
2
+ ``wuttaweb.forms``
3
+ ==================
4
+
5
+ .. automodule:: wuttaweb.forms
6
+ :members:
@@ -8,6 +8,10 @@
8
8
  :maxdepth: 1
9
9
 
10
10
  app
11
+ auth
12
+ db
13
+ forms
14
+ forms.base
11
15
  handler
12
16
  helpers
13
17
  menus
@@ -15,5 +19,9 @@
15
19
  subscribers
16
20
  util
17
21
  views
22
+ views.auth
18
23
  views.base
19
24
  views.common
25
+ views.essential
26
+ views.master
27
+ views.settings
@@ -0,0 +1,6 @@
1
+
2
+ ``wuttaweb.views.auth``
3
+ =======================
4
+
5
+ .. automodule:: wuttaweb.views.auth
6
+ :members:
@@ -0,0 +1,6 @@
1
+
2
+ ``wuttaweb.views.essential``
3
+ ============================
4
+
5
+ .. automodule:: wuttaweb.views.essential
6
+ :members:
@@ -0,0 +1,6 @@
1
+
2
+ ``wuttaweb.views.master``
3
+ =========================
4
+
5
+ .. automodule:: wuttaweb.views.master
6
+ :members:
@@ -0,0 +1,6 @@
1
+
2
+ ``wuttaweb.views.settings``
3
+ ===========================
4
+
5
+ .. automodule:: wuttaweb.views.settings
6
+ :members:
@@ -20,12 +20,15 @@ extensions = [
20
20
  'sphinx.ext.autodoc',
21
21
  'sphinx.ext.intersphinx',
22
22
  'sphinx.ext.viewcode',
23
+ 'sphinx.ext.todo',
23
24
  ]
24
25
 
25
26
  templates_path = ['_templates']
26
27
  exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
27
28
 
28
29
  intersphinx_mapping = {
30
+ 'colander': ('https://docs.pylonsproject.org/projects/colander/en/latest/', None),
31
+ 'deform': ('https://docs.pylonsproject.org/projects/deform/en/latest/', None),
29
32
  'pyramid': ('https://docs.pylonsproject.org/projects/pyramid/en/latest/', None),
30
33
  'python': ('https://docs.python.org/3/', None),
31
34
  'webhelpers2': ('https://webhelpers2.readthedocs.io/en/latest/', None),
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "WuttaWeb"
9
- version = "0.2.0"
9
+ version = "0.4.0"
10
10
  description = "Web App for Wutta Framework"
11
11
  readme = "README.md"
12
12
  authors = [{name = "Lance Edgar", email = "lance@edbob.org"}]
@@ -32,10 +32,13 @@ requires-python = ">= 3.8"
32
32
  dependencies = [
33
33
  "pyramid>=2",
34
34
  "pyramid_beaker",
35
+ "pyramid_deform",
35
36
  "pyramid_mako",
37
+ "pyramid_tm",
36
38
  "waitress",
37
39
  "WebHelpers2",
38
- "WuttJamaican[db]>=0.7.0",
40
+ "WuttJamaican[db]>=0.8.3",
41
+ "zope.sqlalchemy>=1.5",
39
42
  ]
40
43
 
41
44
 
@@ -31,6 +31,9 @@ from wuttjamaican.conf import make_config
31
31
 
32
32
  from pyramid.config import Configurator
33
33
 
34
+ import wuttaweb.db
35
+ from wuttaweb.auth import WuttaSecurityPolicy
36
+
34
37
 
35
38
  class WebAppProvider(AppProvider):
36
39
  """
@@ -83,17 +86,21 @@ def make_wutta_config(settings):
83
86
 
84
87
  If this config file path cannot be discovered, an error is raised.
85
88
  """
86
- # initialize config and embed in settings dict, to make
87
- # available for web requests later
89
+ # validate config file path
88
90
  path = settings.get('wutta.config')
89
91
  if not path or not os.path.exists(path):
90
92
  raise ValueError("Please set 'wutta.config' in [app:main] "
91
93
  "section of config to the path of your "
92
94
  "config file. Lame, but necessary.")
93
95
 
96
+ # make config per usual, add to settings
94
97
  wutta_config = make_config(path)
95
-
96
98
  settings['wutta_config'] = wutta_config
99
+
100
+ # configure database sessions
101
+ if hasattr(wutta_config, 'appdb_engine'):
102
+ wuttaweb.db.Session.configure(bind=wutta_config.appdb_engine)
103
+
97
104
  return wutta_config
98
105
 
99
106
 
@@ -104,10 +111,18 @@ def make_pyramid_config(settings):
104
111
  The config is initialized with certain features deemed useful for
105
112
  all apps.
106
113
  """
114
+ settings.setdefault('pyramid_deform.template_search_path',
115
+ 'wuttaweb:templates/deform')
116
+
107
117
  pyramid_config = Configurator(settings=settings)
108
118
 
119
+ # configure user authorization / authentication
120
+ pyramid_config.set_security_policy(WuttaSecurityPolicy())
121
+
109
122
  pyramid_config.include('pyramid_beaker')
123
+ pyramid_config.include('pyramid_deform')
110
124
  pyramid_config.include('pyramid_mako')
125
+ pyramid_config.include('pyramid_tm')
111
126
 
112
127
  return pyramid_config
113
128
 
@@ -0,0 +1,150 @@
1
+ # -*- coding: utf-8; -*-
2
+ ################################################################################
3
+ #
4
+ # wuttaweb -- Web App for Wutta Framework
5
+ # Copyright © 2024 Lance Edgar
6
+ #
7
+ # This file is part of Wutta Framework.
8
+ #
9
+ # Wutta Framework is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU General Public License as published by the Free
11
+ # Software Foundation, either version 3 of the License, or (at your option) any
12
+ # later version.
13
+ #
14
+ # Wutta Framework is distributed in the hope that it will be useful, but
15
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17
+ # more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License along with
20
+ # Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
21
+ #
22
+ ################################################################################
23
+ """
24
+ Auth Utility Logic
25
+ """
26
+
27
+ import re
28
+
29
+ from pyramid.authentication import SessionAuthenticationHelper
30
+ from pyramid.request import RequestLocalCache
31
+ from pyramid.security import remember, forget
32
+
33
+ from wuttaweb.db import Session
34
+
35
+
36
+ def login_user(request, user):
37
+ """
38
+ Perform the steps necessary to "login" the given user. This
39
+ returns a ``headers`` dict which you should pass to the final
40
+ redirect, like so::
41
+
42
+ from pyramid.httpexceptions import HTTPFound
43
+
44
+ headers = login_user(request, user)
45
+ return HTTPFound(location='/', headers=headers)
46
+
47
+ .. warning::
48
+
49
+ This logic does not "authenticate" the user! It assumes caller
50
+ has already authenticated the user and they are safe to login.
51
+
52
+ See also :func:`logout_user()`.
53
+ """
54
+ headers = remember(request, user.uuid)
55
+ return headers
56
+
57
+
58
+ def logout_user(request):
59
+ """
60
+ Perform the logout action for the given request. This returns a
61
+ ``headers`` dict which you should pass to the final redirect, like
62
+ so::
63
+
64
+ from pyramid.httpexceptions import HTTPFound
65
+
66
+ headers = logout_user(request)
67
+ return HTTPFound(location='/', headers=headers)
68
+
69
+ See also :func:`login_user()`.
70
+ """
71
+ request.session.delete()
72
+ request.session.invalidate()
73
+ headers = forget(request)
74
+ return headers
75
+
76
+
77
+ class WuttaSecurityPolicy:
78
+ """
79
+ Pyramid :term:`security policy` for WuttaWeb.
80
+
81
+ For more on the Pyramid details, see :doc:`pyramid:narr/security`.
82
+
83
+ But the idea here is that you should be able to just use this,
84
+ without thinking too hard::
85
+
86
+ from pyramid.config import Configurator
87
+ from wuttaweb.auth import WuttaSecurityPolicy
88
+
89
+ pyramid_config = Configurator()
90
+ pyramid_config.set_security_policy(WuttaSecurityPolicy())
91
+
92
+ This security policy will then do the following:
93
+
94
+ * use the request "web session" for auth storage (e.g. current
95
+ ``user.uuid``)
96
+ * check permissions as needed, by calling
97
+ :meth:`~wuttjamaican:wuttjamaican.auth.AuthHandler.has_permission()`
98
+ for current user
99
+
100
+ :param db_session: Optional :term:`db session` to use, instead of
101
+ :class:`wuttaweb.db.Session`. Probably only useful for tests.
102
+ """
103
+
104
+ def __init__(self, db_session=None):
105
+ self.session_helper = SessionAuthenticationHelper()
106
+ self.identity_cache = RequestLocalCache(self.load_identity)
107
+ self.db_session = db_session or Session()
108
+
109
+ def load_identity(self, request):
110
+ config = request.registry.settings['wutta_config']
111
+ app = config.get_app()
112
+ model = app.model
113
+
114
+ # fetch user uuid from current session
115
+ uuid = self.session_helper.authenticated_userid(request)
116
+ if not uuid:
117
+ return
118
+
119
+ # fetch user object from db
120
+ user = self.db_session.get(model.User, uuid)
121
+ if not user:
122
+ return
123
+
124
+ return user
125
+
126
+ def identity(self, request):
127
+ return self.identity_cache.get_or_create(request)
128
+
129
+ def authenticated_userid(self, request):
130
+ user = self.identity(request)
131
+ if user is not None:
132
+ return user.uuid
133
+
134
+ def remember(self, request, userid, **kw):
135
+ return self.session_helper.remember(request, userid, **kw)
136
+
137
+ def forget(self, request, **kw):
138
+ return self.session_helper.forget(request, **kw)
139
+
140
+ def permits(self, request, context, permission):
141
+
142
+ # nb. root user can do anything
143
+ if getattr(request, 'is_root', False):
144
+ return True
145
+
146
+ config = request.registry.settings['wutta_config']
147
+ app = config.get_app()
148
+ auth = app.get_auth_handler()
149
+ user = self.identity(request)
150
+ return auth.has_permission(self.db_session, user, permission)
@@ -0,0 +1,66 @@
1
+ # -*- coding: utf-8; -*-
2
+ ################################################################################
3
+ #
4
+ # wuttaweb -- Web App for Wutta Framework
5
+ # Copyright © 2024 Lance Edgar
6
+ #
7
+ # This file is part of Wutta Framework.
8
+ #
9
+ # Wutta Framework is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU General Public License as published by the Free
11
+ # Software Foundation, either version 3 of the License, or (at your option) any
12
+ # later version.
13
+ #
14
+ # Wutta Framework is distributed in the hope that it will be useful, but
15
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17
+ # more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License along with
20
+ # Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
21
+ #
22
+ ################################################################################
23
+ """
24
+ Database sessions for web app
25
+
26
+ The web app uses a different database session than other
27
+ (e.g. console) apps. The web session is "registered" to the HTTP
28
+ request/response life cycle (aka. transaction) such that the session
29
+ is automatically rolled back on error, and automatically committed if
30
+ the response is finalized without error.
31
+
32
+ .. class:: Session
33
+
34
+ Primary database session class for the web app.
35
+
36
+ Note that you often do not need to "instantiate" this session, and
37
+ can instead call methods directly on the class::
38
+
39
+ from wuttaweb.db import Session
40
+
41
+ users = Session.query(model.User).all()
42
+
43
+ However in certain cases you may still want/need to instantiate it,
44
+ e.g. when passing a "true/normal" session to other logic. But you
45
+ can always call instance methods as well::
46
+
47
+ from wuttaweb.db import Session
48
+ from some_place import some_func
49
+
50
+ session = Session()
51
+
52
+ # nb. assuming func does not expect a "web" session per se, pass instance
53
+ some_func(session)
54
+
55
+ # nb. these behave the same (instance vs. class method)
56
+ users = session.query(model.User).all()
57
+ users = Session.query(model.User).all()
58
+ """
59
+
60
+ from sqlalchemy import orm
61
+ from zope.sqlalchemy.datamanager import register
62
+
63
+
64
+ Session = orm.scoped_session(orm.sessionmaker())
65
+
66
+ register(Session)
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8; -*-
2
+ ################################################################################
3
+ #
4
+ # wuttaweb -- Web App for Wutta Framework
5
+ # Copyright © 2024 Lance Edgar
6
+ #
7
+ # This file is part of Wutta Framework.
8
+ #
9
+ # Wutta Framework is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU General Public License as published by the Free
11
+ # Software Foundation, either version 3 of the License, or (at your option) any
12
+ # later version.
13
+ #
14
+ # Wutta Framework is distributed in the hope that it will be useful, but
15
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17
+ # more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License along with
20
+ # Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
21
+ #
22
+ ################################################################################
23
+ """
24
+ Forms Library
25
+
26
+ The ``wuttaweb.forms`` namespace contains the following:
27
+
28
+ * :class:`~wuttaweb.forms.base.Form`
29
+ """
30
+
31
+ from .base import Form