Skip to content

Commit

Permalink
imp: mvp dodoo-run client session store
Browse files Browse the repository at this point in the history
  • Loading branch information
David Arnold committed Dec 30, 2019
1 parent 58680b5 commit 3a195df
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 23 deletions.
5 changes: 5 additions & 0 deletions dodoo-run/dodoo_run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

from dodoo import RUNMODE

from .patchers.odoo import SessionStoragePatcher

_log = logging.getLogger(__name__)


Expand All @@ -31,6 +33,7 @@ def _is_dev():


def http(host: str, port: int) -> None:
SessionStoragePatcher().apply()
from .servers import server
from .servers.http import app as _app

Expand All @@ -40,6 +43,7 @@ def http(host: str, port: int) -> None:


def bus(host: str, port: int) -> None:
SessionStoragePatcher().apply()
from .servers import server
from .servers.bus import app as _app

Expand All @@ -49,6 +53,7 @@ def bus(host: str, port: int) -> None:


def graphql(schema: Path, host: str, port: int) -> None:
SessionStoragePatcher().apply()
from .servers import server
from .servers.graphql import app as _app

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@
from dodoo.interfaces import odoo
from dodoo.patchers import BasePatcher

from ..interfaces import _odoo
from ..interfaces import odoo as _odoo
from ..sessions import ClientSessionStore

# lazy_property = odoo.Tools()._f.lazy_property


class OdooClientSessionStore(ClientSessionStore):
"""Modified Odoo client session store. Provides the path interface for
session.save_request_data / session.load_request_data methods of the
Odoo Session Class.
"""

def __init__(self, session_class=_odoo.Session().SessionClass, **kwargs):
super().__init__(**kwargs)
def __init__(self, **kwargs):
super().__init__(session_class=_odoo.Session().SessionClass, **kwargs)
self.path = odoo.Config().session_dir()


# Inheriting order important
class SessionStoragePatcher(_odoo.Patchable, BasePatcher):
@property
def session_store(self):
return OdooClientSessionStore(scope=scope.get())
return OdooClientSessionStore(global_scope=scope)
21 changes: 12 additions & 9 deletions dodoo-run/dodoo_run/sessions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@

class ClientSessionStore(SessionStore):
"""Werkzeug client session store implementation for asgi.
:param scope: The asgi scope to strore the session on.
:param global_scope: A global handle to access the asgi scope
to strore the session on.
"""

# path = odoo.tools.config.session_dir
def __init__(self, scope=None, **kwargs):
def __init__(self, global_scope=None, **kwargs):
super().__init__(**kwargs)
self.scope = scope
self.global_scope = global_scope

def save(self, session):
"""Save a session."""
self.scope = dict(session)
scope = self.global_scope.get()
scope["session"] = dict(session)

def delete(self, session):
"""Delete a session."""
if self.scope["session"].get("sid") != session.sid:
scope = self.global_scope.get()
if scope["session"].get("sid") != session.sid:
return
self.scope = {}
scope["session"] = {}

def get(self, sid):
"""Get a session for this sid or a new session object. This
Expand All @@ -37,7 +39,8 @@ def get(self, sid):
if not self.is_valid_key(sid):
return self.new()

if self.scope["session"].get("sid") != sid:
scope = self.global_scope.get()
if scope["session"].get("sid") != sid:
return self.new()
data = self.scope["session"]
data = scope["session"]
return self.session_class(data, sid, False)
37 changes: 27 additions & 10 deletions dodoo-run/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dodoo-run/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ hupper = {version = "^1.9.1", optional = true}
uvicorn = {version = "^0.10.8", optional = true}
strawberry-graphql = {version = "^0.18.3", optional = true}
itsdangerous = "^1.1.0"
secure-cookie = {git = "https://github.com/pallets/secure-cookie.git"}

[tool.poetry.dev-dependencies]
# TODO: clone odoo with cache https://github.com/sdispater/poetry/issues/1698
Expand Down
3 changes: 3 additions & 0 deletions dodoo/dodoo/interfaces/odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def resetlocale(self):
def lazy(self, obj):
return self._f.lazy(obj)

def lazy_property(self, func):
return self._f.lazy_property(func)


class Service:
def __init__(self):
Expand Down

0 comments on commit 3a195df

Please sign in to comment.