1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013 Team tiramisu (see AUTHORS for all contributors)
4 # This program is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Lesser General Public License as published by the
6 # Free Software Foundation, either version 3 of the License, or (at your
7 # option) any later version.
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # ____________________________________________________________
17 from tiramisu.i18n import _
18 from ..util import SerializeObject
19 from .util import SqlAlchemyBase
21 from sqlalchemy import Column, Integer, String
24 class Setting(SerializeObject):
25 """:param extension: database file extension (by default: db)
26 :param dir_database: root database directory (by default: /tmp)
36 class Session(SqlAlchemyBase):
37 __tablename__ = 'session'
38 id = Column(Integer, primary_key=True)
39 session = Column(String, index=True)
41 def __init__(self, session_id):
42 self.session = session_id
45 def list_sessions(): # pragma: optional cover
47 for val in util.session.query(Session).all():
48 ret.append(val.session)
52 def delete_session(session_id): # pragma: optional cover
53 #Must remove all values for this session!
54 util.session.delete(util.session.query(Session).filter_by(session=session_id).first())
58 class Storage(object):
59 __slots__ = ('session_id', 'persistent')
60 storage = 'sqlalchemy'
61 #if object could be serializable
64 def __init__(self, session_id, persistent, test=False):
65 if util.session.query(Session).filter_by(session=session_id).first(): # pragma: optional cover
66 raise ValueError(_('session already used'))
67 self.session_id = session_id
68 self.persistent = persistent
69 util.session.add(Session(session_id))
73 delete_session(self.session_id)