Skip to content

Commit

Permalink
add first bunch of work
Browse files Browse the repository at this point in the history
  • Loading branch information
vvmruder committed Oct 26, 2023
1 parent 057cca2 commit ee7612d
Show file tree
Hide file tree
Showing 31 changed files with 888 additions and 195 deletions.
76 changes: 16 additions & 60 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import sphinx_rtd_theme
from pyramid_oereb.core.config import Config
Config._config = {'srid': -1, 'app_schema': {'name': 'pyramid_oereb_main'}}
from pyramid_oereb.contrib.data_sources.standard.sources.plr import StandardThemeConfigParser # noqa E402
import pyramid_oereb.contrib.data_sources.standard # noqa E402
import pyramid_oereb.contrib.data_sources.standard.models.main # noqa E402


# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -65,16 +62,6 @@
'../../.venv/bin/mako-render' if os.path.exists('../../.venv/bin/mako-render') else 'mako-render',
'core/sources.rst.mako']).decode('utf-8'))

with open('standard/sources.rst', 'w') as sources:
sources.write(subprocess.check_output([
'../../.venv/bin/mako-render' if os.path.exists('../../.venv/bin/mako-render') else 'mako-render',
'standard/sources.rst.mako']).decode('utf-8'))

with open('contrib/sources.rst', 'w') as sources:
sources.write(subprocess.check_output([
'../../.venv/bin/mako-render' if os.path.exists('../../.venv/bin/mako-render') else 'mako-render',
'contrib/sources.rst.mako']).decode('utf-8'))

with open('contrib/print_proxy.rst', 'w') as sources:
sources.write(subprocess.check_output([
'../../.venv/bin/mako-render' if os.path.exists('../../.venv/bin/mako-render') else 'mako-render',
Expand All @@ -84,54 +71,23 @@
sources.write(subprocess.check_output([
'../../.venv/bin/mako-render' if os.path.exists('../../.venv/bin/mako-render') else 'mako-render',
'contrib/stats.rst.mako']).decode('utf-8'))
target_paths = [
'contrib/data_sources/standard/index.rst',
'contrib/data_sources/standard/models.rst',
'contrib/data_sources/standard/models-main.rst',
'contrib/data_sources/standard/models-theme.rst',
'contrib/data_sources/standard/sources.rst',
'contrib/data_sources/interlis_2_3/index.rst',
'contrib/data_sources/oereblex/index.rst',
'contrib/data_sources/swisstopo/index.rst',
'contrib/data_sources/index.rst'
]

module_file_names = []
module_name = 'pyramid_oereb.contrib.data_sources.standard.models.main'
file_name = 'pyramid_oereb_contrib_data_sources_standard_models_main'
module_file_names.append(file_name)
main_classes = []
for name, obj in inspect.getmembers(pyramid_oereb.contrib.data_sources.standard.models.main):
if inspect.isclass(obj) and obj.__module__ == module_name:
main_classes.append(name)
with open('standard/models/{name}.rst'.format(name=file_name), 'w') as sources:
template = Template(filename='standard/models/models.rst.mako')
sources.write(template.render(**{'module_name': module_name, 'classes': main_classes}))

conf_parser = StandardThemeConfigParser(source={
"class": 'pyramid_oereb.contrib.data_sources.standard.sources.plr.DatabaseSource',
"params": {
"model_factory": "pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk",
"schema_name": "land_use_plans"
}
})

models = conf_parser.get_models()
modelnames = [modelname for modelname in dir(models) if modelname[0].isupper() and modelname != 'Base']

# create fake python module pyramid_oereb.contrib.data_sources.standard.factory_models
factory_models = types.ModuleType('FactoryModels', 'Virtual module for factory generated classes')
factory_models.__name__ = 'factory_models'
factory_models.__mro__ = []
factory_models.__module__ = 'pyramid_oereb.contrib.data_sources.standard'
for modelname in modelnames:
model = models.__getattribute__(modelname)
model.__name__ = modelname
model.__module__ = 'pyramid_oereb.contrib.data_sources.standard.factory_models'
factory_models.__dict__.update({modelname: model})

pyramid_oereb.contrib.data_sources.standard.__dict__.update({'factory_models': factory_models})
sys.modules['pyramid_oereb.contrib.data_sources.standard.factory_models'] = factory_models

module_name = 'pyramid_oereb.contrib.data_sources.standard.factory_models'
file_name = module_name.replace('.', '_').lower()
module_file_names.append(file_name)
with open('standard/models/{name}.rst'.format(name=file_name), 'w') as sources:
template = Template(filename='standard/models/factory_models.rst.mako')
sources.write(template.render(**{'module_name': module_name, 'classes': modelnames}))

with open('standard/models/index.rst', 'w') as sources:
template = Template(filename='standard/models/index.rst.mako')
sources.write(template.render(**{'module_file_names': module_file_names}))
for target_path in target_paths:
with open(target_path, 'w') as sources:
sources.write(subprocess.check_output([
'../../.venv/bin/mako-render' if os.path.exists('../../.venv/bin/mako-render') else 'mako-render',
f'{target_path}.mako']).decode('utf-8'))

# Add any paths that contain templates here, relative to this directory.
templates_path = ['doc/_buildtemplates']
Expand Down
29 changes: 29 additions & 0 deletions doc/source/contrib/data_sources/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. _contrib-data-sources:

Data Sources
------------

``pyramid_oereb`` provides a plugable system to offer an extendable system. The most
interesting part of that is probably the extension of what data sources should be
connected to the core system of ``pyramid_oereb``.

As of now ``pyramid_oereb`` offers the following data sources (db structures) you can store
your data to:

* :ref:`contrib-data-sources-standard`
* oereblex
* interlis 2.3



In addition there is a source to use with the address localisation:

* swisstopo

.. toctree::
:hidden:

standard/index
oereblex/index
interlis_2_3/index
swisstopo/index
29 changes: 29 additions & 0 deletions doc/source/contrib/data_sources/index.rst.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. _contrib-data-sources:

Data Sources
------------

``pyramid_oereb`` provides a plugable system to offer an extendable system. The most
interesting part of that is probably the extension of what data sources should be
connected to the core system of ``pyramid_oereb``.

As of now ``pyramid_oereb`` offers the following data sources (db structures) you can store
your data to:

* :ref:`contrib-data-sources-standard`
* oereblex
* interlis 2.3



In addition there is a source to use with the address localisation:

* swisstopo

.. toctree::
:hidden:

standard/index
oereblex/index
interlis_2_3/index
swisstopo/index
8 changes: 8 additions & 0 deletions doc/source/contrib/data_sources/interlis_2_3/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _contrib-data-sources-interlis-23:

Application schema Models
=========================


.. toctree::
:hidden:
8 changes: 8 additions & 0 deletions doc/source/contrib/data_sources/interlis_2_3/index.rst.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _contrib-data-sources-interlis-23:

Application schema Models
=========================


.. toctree::
:hidden:
8 changes: 8 additions & 0 deletions doc/source/contrib/data_sources/oereblex/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _contrib-data-sources-oereblex:

ÖREBlex
=======


.. toctree::
:hidden:
8 changes: 8 additions & 0 deletions doc/source/contrib/data_sources/oereblex/index.rst.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _contrib-data-sources-oereblex:

ÖREBlex
=======


.. toctree::
:hidden:
43 changes: 43 additions & 0 deletions doc/source/contrib/data_sources/standard/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.. _contrib-data-sources-standard:

Standard
^^^^^^^^

The standard data source is a binding to a database following the definitions of
`OeREBKRMkvs_V2_0 <http://models.geo.admin.ch/V_D/OeREB/OeREBKRMkvs_V2_0.ili>`__
and `OeREBKRMtrsfr_V2_0 <http://models.geo.admin.ch/V_D/OeREB/OeREBKRMtrsfr_V2_0.ili>`__
but adds some magic sugar for convenience.

Exemplary schema of a standard database:

.. image:: ../../../../images/standard_database_schema_example.png
:scale: 20 %
:align: center

This structure is defined as models for SQL-Alchemy ORM and as a fitting set of
DataBaseSource-Adapters to hook it into the core of ``pyramid_oereb``. The models
defined in this contribution package describing 2 different structures. The ``main``
definitions are used by ``pyramid_oereb`` application itself and contain the application
configuration as suggested in
`OeREBKRMkvs_V2_0 <http://models.geo.admin.ch/V_D/OeREB/OeREBKRMkvs_V2_0.ili>`__.
The ``theme`` definitions define a single ÖREB-Theme as it is suggested by
`OeREBKRMtrsfr_V2_0 <http://models.geo.admin.ch/V_D/OeREB/OeREBKRMtrsfr_V2_0.ili>`__.
Please be aware that for performance reasons the schematic mapping of SQL-Alchemy ORM
definitions and the linked INTERLIS models is not 1:1.

The definition of main and theme schema share some classes. These are provided via
factory methods at modul level. These methods can be found here :ref:`contrib-data-sources-standard-models`

* :ref:`contrib-data-sources-standard-models`
* :ref:`contrib-data-sources-standard-models-main`
* :ref:`contrib-data-sources-standard-models-theme`
* :ref:`contrib-data-sources-standard-sources`


.. toctree::
:hidden:

models
models-main
models-theme
sources
43 changes: 43 additions & 0 deletions doc/source/contrib/data_sources/standard/index.rst.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.. _contrib-data-sources-standard:

Standard
^^^^^^^^

The standard data source is a binding to a database following the definitions of
`OeREBKRMkvs_V2_0 <http://models.geo.admin.ch/V_D/OeREB/OeREBKRMkvs_V2_0.ili>`__
and `OeREBKRMtrsfr_V2_0 <http://models.geo.admin.ch/V_D/OeREB/OeREBKRMtrsfr_V2_0.ili>`__
but adds some magic sugar for convenience.

Exemplary schema of a standard database:

.. image:: ../../../../images/standard_database_schema_example.png
:scale: 20 %
:align: center

This structure is defined as models for SQL-Alchemy ORM and as a fitting set of
DataBaseSource-Adapters to hook it into the core of ``pyramid_oereb``. The models
defined in this contribution package describing 2 different structures. The ``main``
definitions are used by ``pyramid_oereb`` application itself and contain the application
configuration as suggested in
`OeREBKRMkvs_V2_0 <http://models.geo.admin.ch/V_D/OeREB/OeREBKRMkvs_V2_0.ili>`__.
The ``theme`` definitions define a single ÖREB-Theme as it is suggested by
`OeREBKRMtrsfr_V2_0 <http://models.geo.admin.ch/V_D/OeREB/OeREBKRMtrsfr_V2_0.ili>`__.
Please be aware that for performance reasons the schematic mapping of SQL-Alchemy ORM
definitions and the linked INTERLIS models is not 1:1.

The definition of main and theme schema share some classes. These are provided via
factory methods at modul level. These methods can be found here :ref:`contrib-data-sources-standard-models`

* :ref:`contrib-data-sources-standard-models`
* :ref:`contrib-data-sources-standard-models-main`
* :ref:`contrib-data-sources-standard-models-theme`
* :ref:`contrib-data-sources-standard-sources`


.. toctree::
:hidden:

models
models-main
models-theme
sources
Loading

0 comments on commit ee7612d

Please sign in to comment.