Exemple #1
0
 def cb(tb, cls):
     attrs = {}
     attrs['minOccurs'] = str(0)
     attrs['nillable'] = 'true'
     attrs['name'] = 'rel'
     with tag(tb, 'xsd:element', attrs) as tb:
         with tag(tb, 'xsd:simpleType') as tb:
             with tag(tb, 'xsd:restriction',
                      {'base': 'xsd:string'}) as tb:
                 for enum in ('male', 'female'):
                     with tag(tb, 'xsd:enumeration',
                              {'value': enum}):
                         pass
 def test_xsd_sequence_callback(self):
     from xml.etree.ElementTree import TreeBuilder, tostring
     from c2cgeoportal.lib.dbreflection import _xsd_sequence_callback
     from papyrus.xsd import tag
     tb = TreeBuilder()
     with tag(tb, "xsd:sequence") as tb:
         _xsd_sequence_callback(tb, self.cls)
     e = tb.close()
     self.assertEqual(
         tostring(e),
         '<xsd:sequence>'
         '<xsd:element minOccurs="0" name="child1" nillable="true">'
         '<xsd:simpleType>'
         '<xsd:restriction base="xsd:string">'
         '<xsd:enumeration value="foo" />'
         '<xsd:enumeration value="bar" />'
         '</xsd:restriction>'
         '</xsd:simpleType>'
         '</xsd:element>'
         '<xsd:element minOccurs="0" name="child2" nillable="true">'
         '<xsd:simpleType>'
         '<xsd:restriction base="xsd:string">'
         '<xsd:enumeration value="foo" />'
         '<xsd:enumeration value="bar" />'
         '</xsd:restriction>'
         '</xsd:simpleType>'
         '</xsd:element>'
         '</xsd:sequence>')
Exemple #3
0
def _xsd_sequence_callback(tb, cls):
    from c2cgeoportal.models import DBSession
    for k, p in cls.__dict__.iteritems():
        if not isinstance(p, _association_proxy):
            continue
        relationship_property = class_mapper(cls) \
            .get_property(p.target)
        target_cls = relationship_property.argument
        query = DBSession.query(getattr(target_cls, p.value_attr))
        attrs = {}
        attrs['minOccurs'] = str(0)
        attrs['nillable'] = 'true'
        attrs['name'] = k
        with tag(tb, 'xsd:element', attrs) as tb:
            with tag(tb, 'xsd:simpleType') as tb:
                with tag(tb, 'xsd:restriction', {'base': 'xsd:string'}) as tb:
                    for value, in query:
                        with tag(tb, 'xsd:enumeration', {'value': value}):
                            pass
def _xsd_sequence_callback(tb, cls):
    from c2cgeoportal.models import DBSession
    for k, p in cls.__dict__.iteritems():
        if not isinstance(p, _AssociationProxy):
            continue
        relationship_property = class_mapper(cls) \
            .get_property(p.target)
        target_cls = relationship_property.argument
        query = DBSession.query(getattr(target_cls, p.value_attr))
        attrs = {}
        attrs["minOccurs"] = str(0)
        attrs["nillable"] = "true"
        attrs["name"] = k
        with tag(tb, "xsd:element", attrs) as tb:
            with tag(tb, "xsd:simpleType") as tb:
                with tag(tb, "xsd:restriction", {"base": "xsd:string"}) as tb:
                    for value, in query:
                        with tag(tb, "xsd:enumeration", {"value": value}):
                            pass
Exemple #5
0
def _xsd_sequence_callback(tb, cls):
    from c2cgeoportal.models import DBSession

    for k, p in cls.__dict__.iteritems():
        if not isinstance(p, _association_proxy):
            continue
        relationship_property = class_mapper(cls).get_property(p.target)
        target_cls = relationship_property.argument
        query = DBSession.query(getattr(target_cls, p.value_attr))
        attrs = {}
        attrs["minOccurs"] = str(0)
        attrs["nillable"] = "true"
        attrs["name"] = k
        with tag(tb, "xsd:element", attrs) as tb:
            with tag(tb, "xsd:simpleType") as tb:
                with tag(tb, "xsd:restriction", {"base": "xsd:string"}) as tb:
                    for (value,) in query:
                        with tag(tb, "xsd:enumeration", {"value": value}):
                            pass
Exemple #6
0
def _xsd_sequence_callback(tb, cls):
    from c2cgeoportal.models import DBSession
    for k, p in cls.__dict__.iteritems():
        if not isinstance(p, _association_proxy):
            continue
        relationship_property = class_mapper(cls) \
            .get_property(p.target)
        target_cls = relationship_property.argument
        query = DBSession.query(getattr(target_cls, p.value_attr))
        attrs = {}
        attrs['minOccurs'] = str(0)
        attrs['nillable'] = 'true'
        attrs['name'] = k
        with tag(tb, 'xsd:element', attrs) as tb:
            with tag(tb, 'xsd:simpleType') as tb:
                with tag(tb, 'xsd:restriction',
                         {'base': 'xsd:string'}) as tb:
                    for value, in query:
                        with tag(tb, 'xsd:enumeration', {'value': value}):
                            pass
Exemple #7
0
 def add_association_proxy_xsd(self, tb, column_property):
     from c2cgeoportal_commons.models import DBSession
     column = column_property.columns[0]
     proxy = column.info['association_proxy']
     attribute = column_property.class_attribute
     cls = attribute.parent.entity
     association_proxy = getattr(cls, proxy)
     relationship_property = class_mapper(cls) \
         .get_property(association_proxy.target)
     target_cls = relationship_property.argument
     query = DBSession.query(
         getattr(target_cls, association_proxy.value_attr))
     attrs = {}
     if association_proxy.nullable:
         attrs["minOccurs"] = "0"
         attrs["nillable"] = "true"
     attrs["name"] = proxy
     with tag(tb, "xsd:element", attrs) as tb:
         with tag(tb, "xsd:simpleType") as tb:
             with tag(tb, "xsd:restriction", {"base": "xsd:string"}) as tb:
                 for value, in query:
                     with tag(tb, "xsd:enumeration", {"value": value}):
                         pass
         self.element_callback(tb, column)
Exemple #8
0
 def element_callback(self, tb, column):
     if column.info.get('readonly'):
         with tag(tb, 'xsd:annotation'):
             with tag(tb, 'xsd:appinfo'):
                 with tag(tb, 'readonly', {'value': 'true'}):
                     pass
Exemple #9
0
 def element_callback(self, tb: str, column: sqlalchemy.sql.schema.Column) -> None:
     if column.info.get("readonly"):
         with tag(tb, "xsd:annotation"):
             with tag(tb, "xsd:appinfo"):
                 with tag(tb, "readonly", {"value": "true"}):
                     pass
Exemple #10
0
 def element_callback(self, tb, column):
     if column.info.get("readonly"):
         with tag(tb, "xsd:annotation"):
             with tag(tb, "xsd:appinfo"):
                 with tag(tb, "readonly", {"value": "true"}):
                     pass
Exemple #11
0
 def cb(tb, cls):
     with tag(tb, 'xsd:annotation'):
         with tag(tb, 'xsd:appinfo'):
             with tag(tb, 'readonly', {'value': 'true'}):
                 pass