Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

add basic structure for config support #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions bauble/model/config.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions bauble/server/config.py
Original file line number Diff line number Diff line change
@@ -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