tests pass now with dictionary and sqlalchemy storage
This commit is contained in:
@ -220,6 +220,19 @@ class _Consistency(SqlAlchemyBase):
|
||||
option._consistencies.append(self)
|
||||
|
||||
|
||||
class _Parent(SqlAlchemyBase):
|
||||
__tablename__ = 'parent'
|
||||
id = Column(Integer, primary_key=True)
|
||||
child_id = Column(Integer)
|
||||
child_name = Column(String)
|
||||
parent_id = Column(Integer)
|
||||
|
||||
def __init__(self, parent, child):
|
||||
self.parent_id = parent.id
|
||||
self.child_id = child.id
|
||||
self.child_name = child._name
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
#
|
||||
# Base
|
||||
@ -252,8 +265,6 @@ class _Base(SqlAlchemyBase):
|
||||
_validator_params = association_proxy("_call_params", "params",
|
||||
getset_factory=load_callback_parm)
|
||||
######
|
||||
_parent = Column(Integer, ForeignKey('baseoption.id'))
|
||||
_children = relationship('BaseOption', enable_typechecks=False)
|
||||
#FIXME pas 2 fois la meme properties dans la base ...
|
||||
#FIXME not autoload
|
||||
#FIXME normalement tuple ... transforme en set !
|
||||
@ -266,8 +277,6 @@ class _Base(SqlAlchemyBase):
|
||||
_readonly = Column(Boolean, default=False)
|
||||
_consistencies = relationship('_Consistency', secondary=consistency_table,
|
||||
backref=backref('options', enable_typechecks=False))
|
||||
_choice_values = Column(PickleType)
|
||||
_choice_open_values = Column(Boolean)
|
||||
_type = Column(String(50))
|
||||
__mapper_args__ = {
|
||||
'polymorphic_identity': 'option',
|
||||
@ -285,44 +294,45 @@ class _Base(SqlAlchemyBase):
|
||||
session.add(self)
|
||||
session.commit()
|
||||
|
||||
def _get_property_object(self, propname):
|
||||
prop_obj = session.query(_PropertyOption).filter(_PropertyOption.name == propname).first()
|
||||
if prop_obj is None:
|
||||
prop_obj = _PropertyOption(propname)
|
||||
return prop_obj
|
||||
|
||||
def _add_consistency(self, func, all_cons_opts):
|
||||
_Consistency(func, all_cons_opts)
|
||||
|
||||
def _get_consistencies(self):
|
||||
return [(consistency.func, consistency.options) for consistency in self._consistencies]
|
||||
|
||||
def _get_id(self):
|
||||
return self.id
|
||||
|
||||
# ____________________________________________________________
|
||||
# information
|
||||
def impl_set_information(self, key, value):
|
||||
"""updates the information's attribute
|
||||
(which is a dictionary)
|
||||
#def impl_set_information(self, key, value):
|
||||
# """updates the information's attribute
|
||||
# (which is a dictionary)
|
||||
|
||||
:param key: information's key (ex: "help", "doc"
|
||||
:param value: information's value (ex: "the help string")
|
||||
"""
|
||||
info = session.query(_Information).filter_by(option=self.id, key=key).first()
|
||||
#FIXME pas append ! remplacer !
|
||||
if info is None:
|
||||
self._informations.append(_Information(key, value))
|
||||
else:
|
||||
info.value = value
|
||||
# :param key: information's key (ex: "help", "doc"
|
||||
# :param value: information's value (ex: "the help string")
|
||||
# """
|
||||
# info = session.query(_Information).filter_by(option=self.id, key=key).first()
|
||||
# #FIXME pas append ! remplacer !
|
||||
# if info is None:
|
||||
# self._informations.append(_Information(key, value))
|
||||
# else:
|
||||
# info.value = value
|
||||
|
||||
def impl_get_information(self, key, default=None):
|
||||
"""retrieves one information's item
|
||||
#def impl_get_information(self, key, default=None):
|
||||
# """retrieves one information's item
|
||||
|
||||
:param key: the item string (ex: "help")
|
||||
"""
|
||||
info = session.query(_Information).filter_by(option=self.id, key=key).first()
|
||||
if info is not None:
|
||||
return info.value
|
||||
elif default is not None:
|
||||
return default
|
||||
else:
|
||||
raise ValueError(_("information's item not found: {0}").format(
|
||||
key))
|
||||
# :param key: the item string (ex: "help")
|
||||
# """
|
||||
# info = session.query(_Information).filter_by(option=self.id, key=key).first()
|
||||
# if info is not None:
|
||||
# return info.value
|
||||
# return self._informations[key]
|
||||
# elif default is not None:
|
||||
# return default
|
||||
# else:
|
||||
# raise ValueError(_("information's item not found: {0}").format(
|
||||
# key))
|
||||
|
||||
|
||||
class Cache(SqlAlchemyBase):
|
||||
@ -413,15 +423,24 @@ class StorageOptionDescription(object):
|
||||
ret.append((opt.path, option))
|
||||
return ret
|
||||
|
||||
def _add_children(self, child_names, children):
|
||||
for child in children:
|
||||
session.add(_Parent(self, child))
|
||||
|
||||
def impl_getchildren(self):
|
||||
for child in session.query(_Parent).filter_by(parent_id=self.id).all():
|
||||
yield(session.query(_Base).filter_by(id=child.child_id).first())
|
||||
#return
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name.startswith('_') or name.startswith('impl_'):
|
||||
return object.__getattribute__(self, name)
|
||||
ret = session.query(_Base).filter_by(_parent=self.id, _name=name).first()
|
||||
if ret is None:
|
||||
child = session.query(_Parent).filter_by(parent_id=self.id, child_name=name).first()
|
||||
if child is None:
|
||||
raise AttributeError(_('unknown Option {0} '
|
||||
'in OptionDescription {1}'
|
||||
'').format(name, self.impl_getname()))
|
||||
return ret
|
||||
return session.query(_Base).filter_by(id=child.child_id).first()
|
||||
|
||||
|
||||
class StorageBase(_Base):
|
||||
|
Reference in New Issue
Block a user