Пример #1
0
def theme_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import (
        Functionality,
        Interface,
        LayerGroup,
        LayergroupTreeitem,
        LayerWMS,
        Metadata,
        OGCServer,
        Role,
        Theme,
    )

    interfaces = [
        Interface(name) for name in ["desktop", "mobile", "edit", "routing"]
    ]

    groups = [LayerGroup(name="layer_group_{}".format(i)) for i in range(0, 5)]

    layer = LayerWMS(name="layer_wms")
    layer.ogc_server = OGCServer(name="server")
    dbsession.add(layer)
    layers = [layer]

    functionalities = [
        Functionality(name=name, value="value_{}".format(v))
        for name in ("default_basemap", "location") for v in range(0, 4)
    ]

    roles = [Role("secretary_" + str(i)) for i in range(0, 4)]

    metadatas_protos = [
        ("copyable", "true"),
        ("disclaimer", "© le momo"),
        ("snappingConfig", '{"tolerance": 50}'),
    ]
    themes = []
    for i in range(0, 25):
        theme = Theme(name="theme_{}".format(i),
                      ordering=1,
                      icon="icon_{}".format(i))
        theme.public = 1 == i % 2
        theme.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]]
        theme.metadatas = [
            Metadata(name=metadatas_protos[id][0],
                     value=metadatas_protos[id][1])
            for id in [i % 3, (i + 2) % 3]
        ]
        for metadata in theme.metadatas:
            metadata.item = theme
        theme.functionalities = [
            functionalities[i % 8], functionalities[(i + 3) % 8]
        ]
        theme.restricted_roles = [roles[i % 4], roles[(i + 2) % 4]]

        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[i % 5],
                               ordering=len(groups[i % 5].children_relation)))
        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[(i + 3) % 5],
                               ordering=len(groups[(i + 3) %
                                                   5].children_relation)))

        dbsession.add(theme)
        themes.append(theme)

    dbsession.flush()

    yield {
        "themes": themes,
        "interfaces": interfaces,
        "groups": groups,
        "layers": layers,
        "functionalities": functionalities,
        "roles": roles,
    }
Пример #2
0
def theme_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import \
        Theme, Role, Functionality, LayergroupTreeitem, \
        Interface, Metadata, LayerGroup, LayerWMS, OGCServer

    interfaces = [
        Interface(name) for name in ['desktop', 'mobile', 'edit', 'routing']
    ]

    groups = [LayerGroup(name='layer_group_{}'.format(i)) for i in range(0, 5)]

    layer = LayerWMS(name='layer_wms')
    layer.ogc_server = OGCServer(name='server')
    dbsession.add(layer)
    layers = [layer]

    functionalities = [
        Functionality(name=name, value='value_{}'.format(v))
        for name in ('default_basemap', 'location') for v in range(0, 4)
    ]

    roles = [Role('secretary_' + str(i)) for i in range(0, 4)]

    metadatas_protos = [('copyable', 'true'), ('disclaimer', '© le momo'),
                        ('snappingConfig', '{"tolerance": 50}')]
    themes = []
    for i in range(0, 25):
        theme = Theme(name='theme_{}'.format(i),
                      ordering=1,
                      icon='icon_{}'.format(i))
        theme.public = 1 == i % 2
        theme.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]]
        theme.metadatas = [
            Metadata(name=metadatas_protos[id][0],
                     value=metadatas_protos[id][1])
            for id in [i % 3, (i + 2) % 3]
        ]
        for metadata in theme.metadatas:
            metadata.item = theme
        theme.functionalities = [
            functionalities[i % 8], functionalities[(i + 3) % 8]
        ]
        theme.restricted_roles = [roles[i % 4], roles[(i + 2) % 4]]

        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[i % 5],
                               ordering=len(groups[i % 5].children_relation)))
        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[(i + 3) % 5],
                               ordering=len(groups[(i + 3) %
                                                   5].children_relation)))

        dbsession.add(theme)
        themes.append(theme)

    dbsession.flush()

    yield {
        'themes': themes,
        'interfaces': interfaces,
        'groups': groups,
        'layers': layers,
        'functionalities': functionalities,
        'roles': roles,
    }
Пример #3
0
def theme_test_data(dbsession):
    from c2cgeoportal_commons.models.main import \
        Theme, Role, Functionality, LayergroupTreeitem, \
        Interface, Metadata, LayerGroup, LayerWMS, OGCServer

    dbsession.begin_nested()

    interfaces = [Interface(name) for name in ['desktop', 'mobile', 'edit', 'routing']]

    groups = [LayerGroup(name='layer_group_{}'.format(i)) for i in range(0, 5)]

    layer = LayerWMS(name='layer_wms')
    layer.ogc_server = OGCServer(name='server')
    dbsession.add(layer)
    layers = [layer]

    functionalities = [Functionality(name=name, value='value_{}'.format(v))
                       for name in ('default_basemap', 'location') for v in range(0, 4)]

    roles = [Role('secretary_' + str(i)) for i in range(0, 4)]

    metadatas_protos = [('copyable', 'true'),
                        ('disclaimer', '© le momo'),
                        ('snappingConfig', '{"tolerance": 50}')]
    themes = []
    for i in range(0, 25):
        theme = Theme(name='theme_{}'.format(i),
                      ordering=1,
                      icon='icon_{}'.format(i))
        theme.public = 1 == i % 2
        theme.interfaces = [interfaces[i % 4],
                            interfaces[(i + 2) % 4]]
        theme.metadatas = [Metadata(name=metadatas_protos[id][0],
                                    value=metadatas_protos[id][1])
                           for id in [i % 3, (i + 2) % 3]]
        for metadata in theme.metadatas:
            metadata.item = theme
        theme.functionalities = [functionalities[i % 8], functionalities[(i + 3) % 8]]
        theme.restricted_roles = [roles[i % 4], roles[(i + 2) % 4]]

        dbsession.add(LayergroupTreeitem(group=theme,
                                         item=groups[i % 5],
                                         ordering=len(groups[i % 5].children_relation)))
        dbsession.add(LayergroupTreeitem(group=theme,
                                         item=groups[(i + 3) % 5],
                                         ordering=len(groups[(i + 3) % 5].children_relation)))

        dbsession.add(theme)
        themes.append(theme)

    dbsession.flush()
    yield {
        'themes': themes,
        'interfaces': interfaces,
        'groups': groups,
        'layers': layers,
        'functionalities': functionalities,
        'roles': roles,
    }

    dbsession.rollback()