Coverage for .tox/coverage/lib/python3.11/site-packages/wuttaweb/db/continuum.py: 100%
12 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-27 21:18 -0500
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-27 21:18 -0500
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"""
24SQLAlchemy-Continuum Plugin
25"""
27from pyramid.threadlocal import get_current_request
29try:
30 from wutta_continuum.conf import WuttaContinuumPlugin
31except ImportError: # pragma: no cover
32 pass
33else:
35 class WuttaWebContinuumPlugin(WuttaContinuumPlugin):
36 """
37 SQLAlchemy-Continuum manager plugin for WuttaWeb.
39 This tries to use the current request to obtain user and IP
40 address for the transaction.
41 """
43 # TODO: should find a better way, threadlocals are bad?
44 # https://docs.pylonsproject.org/projects/pyramid/en/latest/api/threadlocal.html#pyramid.threadlocal.get_current_request
46 def get_remote_addr(self, uow, session):
47 """ """
48 request = get_current_request()
49 if request:
50 return request.client_addr
52 def get_user_id(self, uow, session):
53 """ """
54 request = get_current_request()
55 if request and request.user:
56 return request.user.uuid