From 42f78eb37726701671f6111acbec1fb41c5d9d87 Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 6 Sep 2013 16:41:16 -0400 Subject: [PATCH] add basic structure for config support --- bauble/model/config.py | 52 +++++++++++++++++++++++++++++++++++++++++ bauble/server/config.py | 10 ++++++++ 2 files changed, 62 insertions(+) create mode 100644 bauble/model/config.py create mode 100644 bauble/server/config.py diff --git a/bauble/model/config.py b/bauble/model/config.py new file mode 100644 index 0000000..d7751a0 --- /dev/null +++ b/bauble/model/config.py @@ -0,0 +1,52 @@ +# +# Config table definition +# +from sqlalchemy import * +from sqlalchemy.orm import * +from sqlalchemy.orm.session import object_session +from sqlalchemy.exc import DBAPIError +from sqlalchemy.ext.associationproxy import association_proxy + +import bauble +import bauble.db as db +#import bauble.utils as utils +#from bauble.utils.log import debug +#import bauble.utils.web as web +import bauble.types as types +import bauble.search as search + + +def get(key, session): + return Config.get(key, session) + + +def set(key, value, session): + return Config(key, value, session) + + +class Config(db.Base): + __tablename__ = "config" + __mapper_args__ = {'order_by': ['key']} + + key = Column(String, nullable=False, index=True, unique=True) + value = Column(String) + #family_id = Column(Integer, ForeignKey('family.id'), nullable=False) + #family = relation('Family', backref=backref('genera', cascade='all,delete-orphan')) + + # TODO: see about using relationships across schema boundaries: + # http://docs.sqlalchemy.org/en/rel_0_8/dialects/postgresql.html#remote-cross-schema-table-introspection + user_id = Column(Integer, ForeignKey('user.id')) + + @staticmethod + def get(key, session): + config = session.query(Config).filter_by(key=key).first() + return config.value if config else None + + @staticmethod + def set(key, value, session): + config = session.query(Config).filter_by(key=key).first() + if config: + config.value = value + else: + config = Config(key=key, value=value) + session.add(session) diff --git a/bauble/server/config.py b/bauble/server/config.py new file mode 100644 index 0000000..4c3d60b --- /dev/null +++ b/bauble/server/config.py @@ -0,0 +1,10 @@ +# +# TODO: the config resource will act different from other resources since all configurations have +# unique names we'll get/set/del based on their names +# +from bauble.model.config import Config + +class ConfigResource: + """ + """ + pass