some improvements
[tiramisu.git] / tiramisu / storage / sqlalchemy / option.py
index 9d5e137..db2675b 100644 (file)
@@ -129,14 +129,14 @@ class _PropertyOption(SqlAlchemyBase):
 class _Information(SqlAlchemyBase):
     __tablename__ = 'information'
     id = Column(Integer, primary_key=True)
-    option = Column(String, index=True, nullable=False)
+    option = Column(String, ForeignKey('baseoption.id'), nullable=False)
     key = Column(String)
     value = Column(PickleType)
 
-    def __init__(self, option, key, value):
-        self.option = option
-        self.key = key
-        self.value = value
+#    def __init__(self, option, key, value):
+#        self.option = option
+#        self.key = key
+#        self.value = value
 
 
 #____________________________________________________________
@@ -392,6 +392,7 @@ class _Base(SqlAlchemyBase):
 #                          collection_class=attribute_mapped_collection('key'),
 #                          cascade="all, delete-orphan")
 #    _informations = association_proxy("_infos", "value")
+    _informations = relationship("_Information")
     _default = Column(PickleType)
     _default_multi = Column(PickleType)
     _subdyn = Column(Integer)
@@ -450,7 +451,8 @@ class _Base(SqlAlchemyBase):
         if allow_empty_list is not undefined:
             self._allow_empty_list = allow_empty_list
         if doc is not undefined:
-            self._informations = {'doc': doc}
+            self._informations = [_Information(key='doc', value=doc)]
+            #self._informations = {'doc': doc}
         if opt is not undefined:
             self._opt = opt.id
         if extra is not undefined:
@@ -489,10 +491,14 @@ class _Base(SqlAlchemyBase):
         return self.id
 
     def impl_get_callback(self):
+        a=self.getsession().query(_Base).filter_by(id=self.id).first()
         ret = self._callback
         if ret is None:
             return (None, {})
-        return ret, self._callback_params
+        params = self._callback_params
+        if params is None:
+            params = {}
+        return ret, params
 
     def impl_get_validator(self):
         ret = self._validator
@@ -559,7 +565,13 @@ class _Base(SqlAlchemyBase):
     def _set_callback(self, callback, callback_params):
         self._callback = callback
         if callback_params is not None:
-            self._callback_params = callback_params
+            opt._callback_params = callback_params
+        #session = self.getsession()
+        #opt = session.query(_Base).filter_by(id=self.id).first()
+        #opt._callback = callback
+        #if callback_params is not None:
+        #    opt._callback_params = callback_params
+        #session.commit()
 
     def impl_set_choice_values_params(self, values, values_params, session):
         self._choice_values = values
@@ -632,11 +644,10 @@ class _Base(SqlAlchemyBase):
     # information
     def impl_set_information(self, key, value):
         session = self.getsession()
-#        self._informations[key] = value
         val = session.query(_Information).filter_by(
             option=self.id, key=key).first()
         if val is None:
-            session.add(_Information(self.id, key, value))
+            session.add(_Information(self, key, value))
         else:
             val.value = value
         session.commit()