3
0
Fork 0

feat: add basic support for wutta-continuum

and i mean *basic* - so far..  eventually will expose version history
for viewing etc.

unfortunately got carried away and reorganized the api docs a little
while i was at it..
This commit is contained in:
Lance Edgar 2024-08-27 21:11:44 -05:00
parent 24f5ee1dcc
commit 71728718d8
53 changed files with 308 additions and 76 deletions

View file

@ -98,7 +98,8 @@ class WuttaSecurityPolicy:
for current user
:param db_session: Optional :term:`db session` to use, instead of
:class:`wuttaweb.db.Session`. Probably only useful for tests.
:class:`wuttaweb.db.sess.Session`. Probably only useful for
tests.
"""
def __init__(self, db_session=None):

43
src/wuttaweb/conf.py Normal file
View file

@ -0,0 +1,43 @@
# -*- coding: utf-8; -*-
################################################################################
#
# wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
# Wutta Framework is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Wutta Framework is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Config Extension
"""
from wuttjamaican.conf import WuttaConfigExtension
class WuttaWebConfigExtension(WuttaConfigExtension):
"""
Config extension for WuttaWeb.
This sets the default plugin for SQLAlchemy-Continuum. Which is
only relevant if Wutta-Continuum is installed and enabled. For
more info see :doc:`wutta-continuum:index`.
"""
key = 'wuttaweb'
def configure(self, config):
""" """
config.setdefault('wutta_continuum.wutta_plugin_spec',
'wuttaweb.db.continuum:WuttaWebContinuumPlugin')

View file

@ -0,0 +1,31 @@
# -*- coding: utf-8; -*-
################################################################################
#
# wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
# Wutta Framework is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Wutta Framework is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Database Utilities
The following are available from this ``wuttaweb.db`` namespace:
* :class:`~wuttaweb.db.sess.Session`
"""
from .sess import Session

View file

@ -0,0 +1,56 @@
# -*- coding: utf-8; -*-
################################################################################
#
# wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
# Wutta Framework is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Wutta Framework is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
SQLAlchemy-Continuum Plugin
"""
from pyramid.threadlocal import get_current_request
try:
from wutta_continuum.conf import WuttaContinuumPlugin
except ImportError: # pragma: no cover
pass
else:
class WuttaWebContinuumPlugin(WuttaContinuumPlugin):
"""
SQLAlchemy-Continuum manager plugin for WuttaWeb.
This tries to use the current request to obtain user and IP
address for the transaction.
"""
# TODO: should find a better way, threadlocals are bad?
# https://docs.pylonsproject.org/projects/pyramid/en/latest/api/threadlocal.html#pyramid.threadlocal.get_current_request
def get_remote_addr(self, uow, session):
""" """
request = get_current_request()
if request:
return request.client_addr
def get_user_id(self, uow, session):
""" """
request = get_current_request()
if request and request.user:
return request.user.uuid

View file

@ -128,7 +128,7 @@ class WuttaSet(colander.Set):
:param request: Current :term:`request` object.
:param session: Optional :term:`db session` to use instead of
:class:`wuttaweb.db.Session`.
:class:`wuttaweb.db.sess.Session`.
"""
def __init__(self, request, session=None):

View file

@ -99,8 +99,11 @@ class ObjectRefWidget(SelectWidget):
""" """
values = super().get_template_values(field, cstruct, kw)
if 'url' not in values and self.url and field.schema.model_instance:
values['url'] = self.url(field.schema.model_instance)
# add url, only if rendering readonly
readonly = kw.get('readonly', self.readonly)
if readonly:
if 'url' not in values and self.url and field.schema.model_instance:
values['url'] = self.url(field.schema.model_instance)
return values
@ -134,7 +137,7 @@ class WuttaCheckboxChoiceWidget(CheckboxChoiceWidget):
:param request: Current :term:`request` object.
:param session: Optional :term:`db session` to use instead of
:class:`wuttaweb.db.Session`.
:class:`wuttaweb.db.sess.Session`.
It uses these Deform templates:

View file

@ -147,7 +147,7 @@ def new_request_set_user(
from database, instead of :func:`default_user_getter()`.
:param db_session: Optional :term:`db session` to use,
instead of :class:`wuttaweb.db.Session`.
instead of :class:`wuttaweb.db.sess.Session`.
This will add to the request object:

View file

@ -491,10 +491,16 @@ def get_model_fields(config, model_class=None):
try:
mapper = sa.inspect(model_class)
except sa.exc.NoInspectionAvailable:
pass
else:
fields = [prop.key for prop in mapper.iterate_properties]
return fields
return
fields = [prop.key for prop in mapper.iterate_properties]
# nb. we never want the continuum 'versions' prop
app = config.get_app()
if app.continuum_is_enabled() and 'versions' in fields:
fields.remove('versions')
return fields
def make_json_safe(value, key=None, warn=True):