Browse Source

publish muk_session_store - 12.0

pull/9/head
MuK IT GmbH 6 years ago
parent
commit
3c008ab50b
  1. 2
      muk_session_store/__manifest__.py
  2. 16
      muk_session_store/store/postgres.py

2
muk_session_store/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Session Store", "name": "MuK Session Store",
"summary": """Session Store Options""", "summary": """Session Store Options""",
"version": "12.0.1.0.1",
"version": "12.0.1.0.2",
"category": "Extra Tools", "category": "Extra Tools",
"license": "AGPL-3", "license": "AGPL-3",
"website": "http://www.mukit.at", "website": "http://www.mukit.at",

16
muk_session_store/store/postgres.py

@ -23,6 +23,7 @@ import psycopg2
import functools import functools
from contextlib import closing from contextlib import closing
from datetime import datetime, date
from werkzeug.contrib.sessions import SessionStore from werkzeug.contrib.sessions import SessionStore
@ -101,10 +102,19 @@ class PostgresSessionStore(SessionStore):
def get(self, sid): def get(self, sid):
if not self.is_valid_key(sid): if not self.is_valid_key(sid):
return self.new() return self.new()
self.cursor.execute("UPDATE sessions SET write_date = now() at time zone 'UTC' WHERE sid=%s;", [sid])
self.cursor.execute("SELECT payload FROM sessions WHERE sid=%s;", [sid])
self.cursor.execute("""
SELECT payload, write_date
FROM sessions WHERE sid=%s;
""", [sid])
try: try:
return self.session_class(json.loads(self.cursor.fetchone()[0]), sid, False)
payload, write_date = self.cursor.fetchone()
if write_date.date() != datetime.today().date():
self.cursor.execute("""
UPDATE sessions
SET write_date = now() at time zone 'UTC'
WHERE sid=%s;
""", [sid])
return self.session_class(json.loads(payload), sid, False)
except Exception: except Exception:
return self.session_class({}, sid, False) return self.session_class({}, sid, False)

Loading…
Cancel
Save