From: Andreas J. <svn...@pl...> - 2008-11-23 17:37:23
|
Author: ajung Date: Sun Nov 23 17:37:17 2008 New Revision: 76354 Modified: zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/extenders/document.py zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/minefield.py zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/storage.py Log: support for tuples - we can handle subject+creators Modified: zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/extenders/document.py ============================================================================== --- zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/extenders/document.py (original) +++ zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/extenders/document.py Sun Nov 23 17:37:17 2008 @@ -21,4 +21,6 @@ schema['description'].storage = RDBMSStorage() schema['title'].storage = RDBMSStorage() schema['text'].storage = RDBMSStorage() + schema['subject'].storage = RDBMSStorage() + schema['creators'].storage = RDBMSStorage() Modified: zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/minefield.py ============================================================================== --- zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/minefield.py (original) +++ zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/minefield.py Sun Nov 23 17:37:17 2008 @@ -8,6 +8,15 @@ Base = declarative_base(bind=engine) Session = sessionmaker(bind=engine, autocommit=True, autoflush=True) + + +import logging + +logging.basicConfig() +logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) +logging.getLogger('sqlalchemy.orm.unitofwork').setLevel(logging.DEBUG) + + class Subject(Base): __tablename__ = 'subject' id = Column('id', Integer, Sequence('subject_id_seq'), primary_key=True) @@ -32,15 +41,15 @@ content_type = Column('content_type', String) language = Column('language', String) - # 1:n relation subjects - _subjects = relation(Subject, primaryjoin=id==Subject.dublincore_id) + # 1:n relation subject + _subject = relation(Subject, primaryjoin=id==Subject.dublincore_id) - def _get_subjects(self): - return [s.subject for s in self._subjects] + def _get_subject(self): + return [s.subject for s in self._subject] - def _set_subjects(self, subjects): - self._subjects = [Subject(subject=s) for s in subjects] - subjects = synonym('_subjects', descriptor=property(_get_subjects, _set_subjects)) + def _set_subject(self, subject): + self._subject = [Subject(subject=s) for s in subject] + subject = synonym('_subject', descriptor=property(_get_subject, _set_subject)) # 1:n relation creators _creators = relation(Creator, primaryjoin=id==Creator.dublincore_id) @@ -64,23 +73,3 @@ Base.metadata.create_all() -#session = Session() -# -#session.begin() -##doc = Document(id=9999, -## title=u'the title', -# description=u'no description', -# text=u'the text', -# subjects=[u'n', u'b', u'c'], -# creators=[u'ajung', u'junga'] -# ) -# -#session.save(doc) -#session.commit() -# -# -#for x in session.query(DublinCore).with_polymorphic('*').all(): -# print x.__dict__ -# print x.id -# print x.subjects -# Modified: zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/storage.py ============================================================================== --- zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/storage.py (original) +++ zopyx.plone.archetypes_on_rdbms/trunk/zopyx/plone/archetypes_on_rdbms/storage.py Sun Nov 23 17:37:17 2008 @@ -56,7 +56,7 @@ row = mapper_cls(uuid=uuid) session.save(row) - if isinstance(value, unicode): + if isinstance(value, (unicode, tuple)): setattr(row, name, value) else: setattr(row, name, value.raw) |