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",
"summary": """Session Store Options""",
"version": "12.0.1.0.1",
"version": "12.0.1.0.2",
"category": "Extra Tools",
"license": "AGPL-3",
"website": "http://www.mukit.at",

16
muk_session_store/store/postgres.py

@ -23,6 +23,7 @@ import psycopg2
import functools
from contextlib import closing
from datetime import datetime, date
from werkzeug.contrib.sessions import SessionStore
@ -101,10 +102,19 @@ class PostgresSessionStore(SessionStore):
def get(self, sid):
if not self.is_valid_key(sid):
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:
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:
return self.session_class({}, sid, False)

Loading…
Cancel
Save