From 838f4ca19f1b17ee5b93acd529be21ca26925f93 Mon Sep 17 00:00:00 2001 From: Moritz Kirmse Date: Tue, 16 Jan 2024 15:09:59 +0100 Subject: [PATCH] demonstrator for source/record refactoring --- dev/config/pyramid_oereb.yml.mako | 43 ++++++++++ .../data_sources/interlis_2_3/sources/plr.py | 5 +- .../data_sources/standard/sources/address.py | 48 +++-------- .../data_sources/standard/sources/plr.py | 5 +- pyramid_oereb/core/records/address.py | 9 +- pyramid_oereb/core/records/municipality.py | 21 ++--- pyramid_oereb/core/renderer/extract/json_.py | 2 +- pyramid_oereb/core/sources/__init__.py | 34 ++++++++ pyramid_oereb/core/sources/plr.py | 37 -------- .../sources/test_plr_oereblex.py | 14 ++- .../sources/test_adress.py | 33 ++++--- .../sources/test_disclaimer.py | 3 +- .../sources/test_document.py | 3 +- .../sources/test_document_types.py | 3 +- .../sources/test_general_information.py | 3 +- .../sources/test_glossary.py | 3 +- .../sources/test_law_status.py | 3 +- .../sources/test_legend.py | 3 +- .../sources/test_logo.py | 3 +- .../sources/test_map_layering.py | 3 +- .../sources/test_municipalities.py | 3 +- .../sources/test_office.py | 3 +- .../sources/test_plr.py | 14 ++- .../sources/test_real_estate.py | 3 +- .../sources/test_real_estate_type.py | 3 +- .../sources/test_theme.py | 3 +- .../sources/test_theme_document.py | 3 +- tests/core/test_config.py | 86 ++++++++++++------- tests/resources/test_config.yml | 35 ++++++++ 29 files changed, 286 insertions(+), 145 deletions(-) diff --git a/dev/config/pyramid_oereb.yml.mako b/dev/config/pyramid_oereb.yml.mako index 812b8598ad..7d64705983 100644 --- a/dev/config/pyramid_oereb.yml.mako +++ b/dev/config/pyramid_oereb.yml.mako @@ -267,6 +267,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the real estate database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.RealEstate + record_class: pyramid_oereb.core.records.real_estate.RealEstateRecord # The processor of the oereb project needs access to address data. In the standard configuration, this # is assumed to be read from a database. Hint: If you want to read the addresses out of an existing database @@ -284,6 +285,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the address database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.Address + record_class: pyramid_oereb.core.records.address.AddressRecord # Alternatively, you can use the search service of the GeoAdmin API to look up the real estate by # address. Replace the configuration above with the following lines: # class: pyramid_oereb.contrib.data_sources.swisstopo.address.AddressGeoAdminSource @@ -313,6 +315,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the municipality database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.Municipality + record_class: pyramid_oereb.core.records.municipality.MunicipalityRecord # The extract provides logos. Therefor you need to provide the logos from the database # or by a path to these logos. Note: This must be a valid absolute system path available @@ -343,6 +346,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the logo images database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.Logo + record_class: pyramid_oereb.core.records.logo.LogoRecord hooks: get_logo_ref: pyramid_oereb.core.hook_methods.get_logo_ref get_qr_code_ref: pyramid_oereb.core.hook_methods.get_qr_code_ref @@ -363,6 +367,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the document type texts database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.DocumentTypeText + record_class: pyramid_oereb.core.records.document_types.DocumentTypeRecord # The processor of the oereb project joins the document type labels. In the standard configuration this # is assumed to be read from a database. Hint: If you want to read the values out of an existing database @@ -380,6 +385,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the document type texts database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.Document + record_class: pyramid_oereb.core.records.documents.DocumentRecord # The processor of the oereb project joins the document type labels. In the standard configuration this # is assumed to be read from a database. Hint: If you want to read the values out of an existing database @@ -397,6 +403,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the document type texts database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.Office + record_class: pyramid_oereb.core.records.office.OfficeRecord # The processor of the oereb project needs access to theme data. In the standard configuration this # is assumed to be read from a database. Hint: If you want to read the themes out of an existing database @@ -414,6 +421,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the theme database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.Theme + record_class: pyramid_oereb.core.records.theme.ThemeRecord # The processor of the oereb project needs access to theme document data. In the standard configuration # this is assumed to be read from a database. Hint: If you want to read the theme documents out of an existing @@ -431,6 +439,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the theme database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.ThemeDocument + record_class: pyramid_oereb.core.records.theme_document.ThemeDocumentRecord # The processor of the oereb project needs access to glossary data. In the standard configuration this # is assumed to be read from a database. Hint: If you want to read the glossary out of an existing database @@ -448,6 +457,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the glossary database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.Glossary + record_class: pyramid_oereb.core.records.glossary.GlossaryRecord # The processor of the oereb project needs access to disclaimer data. In the standard # configuration this is assumed to be read from a database. Hint: If you want to read the disclaimer @@ -466,6 +476,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the disclaimer database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.Disclaimer + record_class: pyramid_oereb.core.records.disclaimer.DisclaimerRecord # The processor of the oereb project joins the law status labels. In the standard configuration this # is assumed to be read from a database. Hint: If you want to read the values out of an existing database @@ -483,6 +494,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the document type texts database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.LawStatus + record_class: pyramid_oereb.core.records.law_status.LawStatusRecord # The processor of the oereb project joins the real estate type labels. In the standard configuration this # is assumed to be read from a database. Hint: If you want to read the values out of an existing database @@ -519,6 +531,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the document type texts database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.RealEstateType + record_class: pyramid_oereb.core.records.real_estate_type.RealEstateTypeRecord # The processor of the oereb project needs access to general information data. In the standard # configuration this is assumed to be read from a database. Hint: If you want to read the general @@ -537,6 +550,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the general_information database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.GeneralInformation + record_class: pyramid_oereb.core.records.general_information.GeneralInformationRecord # The processor of the oereb project needs access to map layering data. In the standard configuration this # is assumed to be read from a database. Hint: If you want to read the map layering out of an existing database @@ -554,6 +568,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the map layering database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.MapLayering + record_class: pyramid_oereb.core.records.map_layering.MapLayeringRecord # The extract is the entry point which binds everything # related to data together. @@ -587,6 +602,7 @@ pyramid_oereb: db_connection: *main_db_connection # The model which maps the map layering database table. model: pyramid_oereb.contrib.data_sources.standard.models.main.Availability + record_class: pyramid_oereb.core.records.availability.AvailabilityRecord # All PLRs which are provided by this application. This is related to all application behaviour, especially # the extract creation process which loops over this list. @@ -629,6 +645,17 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: land_use_plans + record_class: &plr_records + documents: pyramid_oereb.core.records.documents.DocumentRecord + disclaimer: pyramid_oereb.core.records.disclaimer.DisclaimerRecord + geometry: pyramid_oereb.core.records.geometry.GeometryRecord + glossary: pyramid_oereb.core.records.glossary.GlossaryRecord + legend_entry: pyramid_oereb.core.records.view_service.LegendEntryRecord + office: pyramid_oereb.core.records.office.OfficeRecord + plr: pyramid_oereb.core.records.plr.PlrRecord + view_service: pyramid_oereb.core.records.view_service.ViewServiceRecord + law_status: pyramid_oereb.core.records.law_status.LawStatusRecord + datasource: pyramid_oereb.core.records.embeddable.DatasourceRecord hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -676,6 +703,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: motorways_project_planning_zones + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -723,6 +751,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: motorways_building_lines + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -770,6 +799,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: railways_project_planning_zones + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -817,6 +847,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: railways_building_lines + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -864,6 +895,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: airports_project_planning_zones + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -911,6 +943,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: airports_building_lines + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -958,6 +991,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: airports_security_zone_plans + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -1006,6 +1040,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: contaminated_sites + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -1053,6 +1088,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: contaminated_military_sites + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -1100,6 +1136,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.interlis_2_3.models.theme.model_factory_integer_pk schema_name: contaminated_civil_aviation_sites + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.interlis_2_3.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -1147,6 +1184,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: contaminated_public_transport_sites + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -1194,6 +1232,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: groundwater_protection_zones + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -1241,6 +1280,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: groundwater_protection_sites + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -1288,6 +1328,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: noise_sensitivity_levels + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -1338,6 +1379,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: forest_perimeters + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -1385,6 +1427,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: forest_distance_lines + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref diff --git a/pyramid_oereb/contrib/data_sources/interlis_2_3/sources/plr.py b/pyramid_oereb/contrib/data_sources/interlis_2_3/sources/plr.py index c26858199f..af4d4b0806 100644 --- a/pyramid_oereb/contrib/data_sources/interlis_2_3/sources/plr.py +++ b/pyramid_oereb/contrib/data_sources/interlis_2_3/sources/plr.py @@ -105,9 +105,12 @@ def __init__(self, **kwargs): """ config_parser = StandardThemeConfigParser(**kwargs) self.models = config_parser.get_models() + BaseDatabaseSource.__init__(self, **{**kwargs['source']['params'], + 'model': self.models.PublicLawRestriction}) bds_kwargs = { 'model': self.models.Geometry, - 'db_connection': kwargs.get('source').get('params').get('db_connection') + 'db_connection': kwargs.get('source').get('params').get('db_connection'), + 'record_class': self._geometry_record_class, } BaseDatabaseSource.__init__(self, **bds_kwargs) diff --git a/pyramid_oereb/contrib/data_sources/standard/sources/address.py b/pyramid_oereb/contrib/data_sources/standard/sources/address.py index 46a68c9619..20e62a6ba3 100644 --- a/pyramid_oereb/contrib/data_sources/standard/sources/address.py +++ b/pyramid_oereb/contrib/data_sources/standard/sources/address.py @@ -1,19 +1,13 @@ # -*- coding: utf-8 -*- -from geoalchemy2.elements import _SpatialElement -from geoalchemy2.shape import to_shape -from sqlalchemy.orm.exc import NoResultFound - from pyramid_oereb.core.sources import BaseDatabaseSource -from pyramid_oereb.core.sources.address import AddressBaseSource -class DatabaseSource(BaseDatabaseSource, AddressBaseSource): +class DatabaseSource(BaseDatabaseSource): - def read(self, params, street_name, zip_code, street_number): + def filter(self, query, params, street_name, zip_code, street_number): """ - The read method to access the standard database structure. It uses SQL-Alchemy for querying. It tries - to find the items via passed arguments. If there was no result found it goes on with assigning an - empty list as records instance attribute. + The filter method only selects some specific results from the standard database structure. + It uses SQL-Alchemy for querying via passed arguments. Args: params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract request. @@ -21,28 +15,12 @@ def read(self, params, street_name, zip_code, street_number): zip_code (int): The postal zipcode for the desired address. street_number (str): The house or so called street number of the desired address. """ - session = self._adapter_.get_session(self._key_) - try: - query = session.query(self._model_) - results = [query.filter( - self._model_.street_name == street_name - ).filter( - self._model_.zip_code == zip_code - ).filter( - self._model_.street_number == street_number - ).one()] - - self.records = [] - for result in results: - self.records.append(self._record_class_( - result.street_name, - result.zip_code, - result.street_number, - to_shape(result.geom) if isinstance(result.geom, _SpatialElement) else None - )) - - except NoResultFound: - self.records = [] - - finally: - session.close() + filtered_query = query.filter( + self._model_.street_name == street_name + ).filter( + self._model_.zip_code == zip_code + ).filter( + self._model_.street_number == street_number + ).limit(1) + + return filtered_query diff --git a/pyramid_oereb/contrib/data_sources/standard/sources/plr.py b/pyramid_oereb/contrib/data_sources/standard/sources/plr.py index 15c7422857..7712d5ee2c 100644 --- a/pyramid_oereb/contrib/data_sources/standard/sources/plr.py +++ b/pyramid_oereb/contrib/data_sources/standard/sources/plr.py @@ -102,9 +102,12 @@ def __init__(self, **kwargs): """ config_parser = StandardThemeConfigParser(**kwargs) self.models = config_parser.get_models() + BaseDatabaseSource.__init__(self, **{**kwargs['source']['params'], + 'model': self.models.PublicLawRestriction}) bds_kwargs = { 'model': self.models.Geometry, - 'db_connection': kwargs.get('source').get('params').get('db_connection') + 'db_connection': kwargs.get('source').get('params').get('db_connection'), + 'record_class': self._geometry_record_class, } BaseDatabaseSource.__init__(self, **bds_kwargs) diff --git a/pyramid_oereb/core/records/address.py b/pyramid_oereb/core/records/address.py index 869a0a3f4e..ebf3a6427b 100644 --- a/pyramid_oereb/core/records/address.py +++ b/pyramid_oereb/core/records/address.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +from geoalchemy2.elements import _SpatialElement +from geoalchemy2.shape import to_shape +from shapely import is_geometry class AddressRecord(object): @@ -24,4 +27,8 @@ def __init__(self, street_name, zip_code, street_number, geom): self.street_name = street_name self.zip_code = zip_code self.street_number = street_number - self.geom = geom + self.geom = None + if is_geometry(geom) or isinstance(geom, str): + self.geom = geom + elif isinstance(geom, _SpatialElement): + self.geom = to_shape(geom) diff --git a/pyramid_oereb/core/records/municipality.py b/pyramid_oereb/core/records/municipality.py index f5863032f1..e5e877cf81 100644 --- a/pyramid_oereb/core/records/municipality.py +++ b/pyramid_oereb/core/records/municipality.py @@ -1,7 +1,10 @@ # -*- coding: utf-8 -*- +from dataclasses import dataclass +from typing import Any -class MunicipalityRecord(object): +@dataclass +class MunicipalityRecord: """ The base document class. @@ -11,15 +14,7 @@ class MunicipalityRecord(object): published (bool): Is this municipality ready for publishing via server. geom (str or None): The geometry which is representing this municipality as a WKT. """ - def __init__(self, fosnr, name, published, geom=None): - """ - Args: - fosnr (int): The unique id bfs of the municipality. - name (unicode): The zipcode for this address. - published (bool): Is this municipality ready for publishing via server. - geom (str or None): The geometry which is representing this municipality as a WKT. - """ - self.fosnr = fosnr - self.name = name - self.published = published - self.geom = geom + fosnr: int + name: str + published: bool + geom: Any = None diff --git a/pyramid_oereb/core/renderer/extract/json_.py b/pyramid_oereb/core/renderer/extract/json_.py index 82e4331b18..4bc16c7f76 100644 --- a/pyramid_oereb/core/renderer/extract/json_.py +++ b/pyramid_oereb/core/renderer/extract/json_.py @@ -11,7 +11,7 @@ from pyramid_oereb.core import get_multilingual_element from pyramid_oereb.core.records.documents import DocumentRecord from pyramid_oereb.core.records.theme import ThemeRecord -from pyramid_oereb.core.sources.plr import PlrRecord +from pyramid_oereb.core.records.plr import PlrRecord from pyramid_oereb.core.renderer import Base from pyramid_oereb.core.views.webservice import Parameter diff --git a/pyramid_oereb/core/sources/__init__.py b/pyramid_oereb/core/sources/__init__.py index 71b957f678..5a27798ad7 100644 --- a/pyramid_oereb/core/sources/__init__.py +++ b/pyramid_oereb/core/sources/__init__.py @@ -7,6 +7,7 @@ from pyramid.config import ConfigurationError from pyramid.path import DottedNameResolver from sqlalchemy import text +from sqlalchemy.orm.exc import NoResultFound log = logging.getLogger(__name__) @@ -55,6 +56,15 @@ def __init__(self, **kwargs): self._model_ = DottedNameResolver().maybe_resolve(kwargs.get('model')) else: raise ConfigurationError('"model" for source has to be defined in used yaml configuration file') + record_class = kwargs.get('record_class') + if record_class: + if isinstance(record_class, dict): + for key, current_class in record_class.items(): + self.__setattr__(f"_{key}_record_class", DottedNameResolver().maybe_resolve(current_class)) + else: + self._record_class_ = DottedNameResolver().maybe_resolve(kwargs.get('record_class')) + else: + raise ConfigurationError('"record_class" for source has to be defined in used yaml configuration file') # check if database is available and wait until it might be or raise error timeout_target = time.time() + self.TIMEOUT db_healthy = False @@ -88,3 +98,27 @@ def health_check(self): return True except Exception: return False + + @staticmethod + def filter(self, query, *args, **kwargs): + """ + abstract method to be overridden + """ + return query + + def read(self, *args, **kwargs): + session = self._adapter_.get_session(self._key_) + try: + query = session.query(self._model_) + results = self.filter(query, *args, **kwargs).all() + + self.records = [] + for result in results: + res_dict = {c.name: result.__getattribute__(c.name) for c in result.__table__.columns} + self.records.append(self._record_class_(**res_dict)) + + except NoResultFound: + self.records = [] + + finally: + session.close() diff --git a/pyramid_oereb/core/sources/plr.py b/pyramid_oereb/core/sources/plr.py index 341758e0ae..4f68a1dccd 100644 --- a/pyramid_oereb/core/sources/plr.py +++ b/pyramid_oereb/core/sources/plr.py @@ -1,15 +1,6 @@ # -*- coding: utf-8 -*- import logging -from pyramid_oereb.core.records.documents import DocumentRecord -from pyramid_oereb.core.records.embeddable import DatasourceRecord -from pyramid_oereb.core.records.disclaimer import DisclaimerRecord -from pyramid_oereb.core.records.geometry import GeometryRecord -from pyramid_oereb.core.records.glossary import GlossaryRecord -from pyramid_oereb.core.records.law_status import LawStatusRecord -from pyramid_oereb.core.records.office import OfficeRecord -from pyramid_oereb.core.records.plr import PlrRecord -from pyramid_oereb.core.records.view_service import ViewServiceRecord, LegendEntryRecord from pyramid_oereb.core.sources import Base log = logging.getLogger(__name__) @@ -25,17 +16,6 @@ class PlrBaseSource(Base): datasource (list of pyramid_oereb.lib.records.embeddable.DatasourceRecord): List of data source records used for the additional data in flavour `embeddable`. """ - _documents_record_class = DocumentRecord - _disclaimer_record_class = DisclaimerRecord - _geometry_record_class = GeometryRecord - _glossary_record_class = GlossaryRecord - _legend_entry_record_class = LegendEntryRecord - _office_record_class = OfficeRecord - _plr_record_class = PlrRecord - _view_service_record_class = ViewServiceRecord - _law_status_record_class = LawStatusRecord - _datasource_record_class = DatasourceRecord - datasource = list() def __init__(self, **kwargs): @@ -69,20 +49,3 @@ def info(self): dict: The info dictionary. """ return self._plr_info - - def read(self, params, real_estate, bbox): - """ - Every public law restriction source has to implement a read method. This method must accept the two - key word parameters. If you want adapt to your own source for real estates, this is the point where - to hook in. - - Args: - params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract request. - real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real estate which is - used as filter to find all related public law restrictions. - bbox (shapely.geometry.base.BaseGeometry): The bounding box which is used as a pre-filter to find - all public law restrictions. This is related to the fact that we need to provide not only the - public law restrictions that are related to the real estate but also the ones which are in - the visible extent of the map. - """ - self.records = list() diff --git a/tests/contrib.data_sources.oereblex/sources/test_plr_oereblex.py b/tests/contrib.data_sources.oereblex/sources/test_plr_oereblex.py index c84330e723..8e32b63650 100644 --- a/tests/contrib.data_sources.oereblex/sources/test_plr_oereblex.py +++ b/tests/contrib.data_sources.oereblex/sources/test_plr_oereblex.py @@ -76,7 +76,19 @@ def plr_source_params(db_connection): "db_connection": db_connection, "model_factory": "pyramid_oereb.contrib.data_sources.standard." "models.theme.model_factory_string_pk", - "schema_name": "forest_perimeters" + "schema_name": "forest_perimeters", + "record_class": { + "documents": "pyramid_oereb.core.records.documents.DocumentRecord", + "disclaimer": "pyramid_oereb.core.records.disclaimer.DisclaimerRecord", + "geometry": "pyramid_oereb.core.records.geometry.GeometryRecord", + "glossary": "pyramid_oereb.core.records.glossary.GlossaryRecord", + "legend_entry": "pyramid_oereb.core.records.view_service.LegendEntryRecord", + "office": "pyramid_oereb.core.records.office.OfficeRecord", + "plr": "pyramid_oereb.core.records.plr.PlrRecord", + "view_service": "pyramid_oereb.core.records.view_service.ViewServiceRecord", + "law_status": "pyramid_oereb.core.records.law_status.LawStatusRecord", + "datasource": "pyramid_oereb.core.records.embeddable.DatasourceRecord", + } } }, "hooks": { diff --git a/tests/contrib.data_sources.standard/sources/test_adress.py b/tests/contrib.data_sources.standard/sources/test_adress.py index a4ce892062..b4f4237868 100644 --- a/tests/contrib.data_sources.standard/sources/test_adress.py +++ b/tests/contrib.data_sources.standard/sources/test_adress.py @@ -13,7 +13,8 @@ def address_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Address" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Address", + "record_class": "pyramid_oereb.core.records.address.AddressRecord" } @@ -28,13 +29,18 @@ def one_address_result_session(session, query, wkb_point): class Query(query): - def one(self): - return Address(**{ - 'street_name': 'teststreet', - 'street_number': '99a', - 'zip_code': 4050, - 'geom': wkb_point - }) + def limit(self, limit): + class LimitedQuery(Query): + def all(self): + return [ + Address(**{ + 'street_name': 'teststreet', + 'street_number': '99a', + 'zip_code': 4050, + 'geom': wkb_point + }) + ] + return LimitedQuery() class Session(session): @@ -49,8 +55,15 @@ def no_result_session(session, query, wkb_point): class Query(query): - def one(self): - raise NoResultFound + class LimitedQuery(query): + def all(self): + raise NoResultFound + + def limit(self, limit): + return self.LimitedQuery() + + def filter(self, term): + return self class Session(session): diff --git a/tests/contrib.data_sources.standard/sources/test_disclaimer.py b/tests/contrib.data_sources.standard/sources/test_disclaimer.py index c4695f2bbe..3422b4007b 100644 --- a/tests/contrib.data_sources.standard/sources/test_disclaimer.py +++ b/tests/contrib.data_sources.standard/sources/test_disclaimer.py @@ -9,7 +9,8 @@ def disclaimer_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Disclaimer" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Disclaimer", + "record_class": "pyramid_oereb.core.records.disclaimer.DisclaimerRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_document.py b/tests/contrib.data_sources.standard/sources/test_document.py index 8b2311aede..e3154c2202 100644 --- a/tests/contrib.data_sources.standard/sources/test_document.py +++ b/tests/contrib.data_sources.standard/sources/test_document.py @@ -17,7 +17,8 @@ def document_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Document" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Document", + "record_class": "pyramid_oereb.core.records.documents.DocumentRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_document_types.py b/tests/contrib.data_sources.standard/sources/test_document_types.py index ae63624482..77e902c4fc 100644 --- a/tests/contrib.data_sources.standard/sources/test_document_types.py +++ b/tests/contrib.data_sources.standard/sources/test_document_types.py @@ -9,7 +9,8 @@ def document_types_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.DocumentTypeText" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.DocumentTypeText", + "record_class": "pyramid_oereb.core.records.document_types.DocumentTypeRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_general_information.py b/tests/contrib.data_sources.standard/sources/test_general_information.py index 6486cd3d21..c3fceb81db 100644 --- a/tests/contrib.data_sources.standard/sources/test_general_information.py +++ b/tests/contrib.data_sources.standard/sources/test_general_information.py @@ -9,7 +9,8 @@ def general_information_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.GeneralInformation" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.GeneralInformation", + "record_class": "pyramid_oereb.core.records.general_information.GeneralInformationRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_glossary.py b/tests/contrib.data_sources.standard/sources/test_glossary.py index dbffdb5ce2..9bde946dd7 100644 --- a/tests/contrib.data_sources.standard/sources/test_glossary.py +++ b/tests/contrib.data_sources.standard/sources/test_glossary.py @@ -9,7 +9,8 @@ def glossary_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Glossary" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Glossary", + "record_class": "pyramid_oereb.core.records.glossary.GlossaryRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_law_status.py b/tests/contrib.data_sources.standard/sources/test_law_status.py index 69e37e303b..9dd6e48a27 100644 --- a/tests/contrib.data_sources.standard/sources/test_law_status.py +++ b/tests/contrib.data_sources.standard/sources/test_law_status.py @@ -10,7 +10,8 @@ def law_status_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.LawStatus" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.LawStatus", + "record_class": "pyramid_oereb.core.records.law_status.LawStatusRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_legend.py b/tests/contrib.data_sources.standard/sources/test_legend.py index b2e9d888fe..8142abdf70 100644 --- a/tests/contrib.data_sources.standard/sources/test_legend.py +++ b/tests/contrib.data_sources.standard/sources/test_legend.py @@ -22,7 +22,8 @@ def legend_entry_model_class(): def legend_entry_source_params(legend_entry_model_class, db_connection): yield { "db_connection": db_connection, - "model": legend_entry_model_class + "model": legend_entry_model_class, + "record_class": "pyramid_oereb.core.records.view_service.LegendEntryRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_logo.py b/tests/contrib.data_sources.standard/sources/test_logo.py index f4c5379e50..13972fc637 100644 --- a/tests/contrib.data_sources.standard/sources/test_logo.py +++ b/tests/contrib.data_sources.standard/sources/test_logo.py @@ -11,7 +11,8 @@ def logo_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Logo" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Logo", + "record_class": "pyramid_oereb.core.records.logo.LogoRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_map_layering.py b/tests/contrib.data_sources.standard/sources/test_map_layering.py index 1153caae49..6847009da3 100644 --- a/tests/contrib.data_sources.standard/sources/test_map_layering.py +++ b/tests/contrib.data_sources.standard/sources/test_map_layering.py @@ -9,7 +9,8 @@ def map_layering_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.MapLayering" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.MapLayering", + "record_class": "pyramid_oereb.core.records.map_layering.MapLayeringRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_municipalities.py b/tests/contrib.data_sources.standard/sources/test_municipalities.py index 3a14a66338..e62681a931 100644 --- a/tests/contrib.data_sources.standard/sources/test_municipalities.py +++ b/tests/contrib.data_sources.standard/sources/test_municipalities.py @@ -11,7 +11,8 @@ def municipalities_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Municipality" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Municipality", + "record_class": "pyramid_oereb.core.records.municipality.MunicipalityRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_office.py b/tests/contrib.data_sources.standard/sources/test_office.py index 3767b3b0ab..847a2db90c 100644 --- a/tests/contrib.data_sources.standard/sources/test_office.py +++ b/tests/contrib.data_sources.standard/sources/test_office.py @@ -13,7 +13,8 @@ def office_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Office" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Office", + "record_class": "pyramid_oereb.core.records.office.OfficeRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_plr.py b/tests/contrib.data_sources.standard/sources/test_plr.py index a8e280e0ec..b2c9022d2f 100644 --- a/tests/contrib.data_sources.standard/sources/test_plr.py +++ b/tests/contrib.data_sources.standard/sources/test_plr.py @@ -88,7 +88,19 @@ def plr_source_params(db_connection): "db_connection": db_connection, "model_factory": "pyramid_oereb.contrib.data_sources.standard." "models.theme.model_factory_string_pk", - "schema_name": "land_use_plans" + "schema_name": "land_use_plans", + "record_class": { + "documents": "pyramid_oereb.core.records.documents.DocumentRecord", + "disclaimer": "pyramid_oereb.core.records.disclaimer.DisclaimerRecord", + "geometry": "pyramid_oereb.core.records.geometry.GeometryRecord", + "glossary": "pyramid_oereb.core.records.glossary.GlossaryRecord", + "legend_entry": "pyramid_oereb.core.records.view_service.LegendEntryRecord", + "office": "pyramid_oereb.core.records.office.OfficeRecord", + "plr": "pyramid_oereb.core.records.plr.PlrRecord", + "view_service": "pyramid_oereb.core.records.view_service.ViewServiceRecord", + "law_status": "pyramid_oereb.core.records.law_status.LawStatusRecord", + "datasource": "pyramid_oereb.core.records.embeddable.DatasourceRecord", + } } }, "hooks": { diff --git a/tests/contrib.data_sources.standard/sources/test_real_estate.py b/tests/contrib.data_sources.standard/sources/test_real_estate.py index 8661e3a974..0aee8390fa 100644 --- a/tests/contrib.data_sources.standard/sources/test_real_estate.py +++ b/tests/contrib.data_sources.standard/sources/test_real_estate.py @@ -12,7 +12,8 @@ def real_estate_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.RealEstate" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.RealEstate", + "record_class": "pyramid_oereb.core.records.real_estate.RealEstateRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_real_estate_type.py b/tests/contrib.data_sources.standard/sources/test_real_estate_type.py index cf70f34007..1f077c2e17 100644 --- a/tests/contrib.data_sources.standard/sources/test_real_estate_type.py +++ b/tests/contrib.data_sources.standard/sources/test_real_estate_type.py @@ -10,7 +10,8 @@ def real_estate_type_source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.RealEstateType" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.RealEstateType", + "record_class": "pyramid_oereb.core.records.real_estate_type.RealEstateTypeRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_theme.py b/tests/contrib.data_sources.standard/sources/test_theme.py index a70d205129..9552f15f96 100644 --- a/tests/contrib.data_sources.standard/sources/test_theme.py +++ b/tests/contrib.data_sources.standard/sources/test_theme.py @@ -9,7 +9,8 @@ def source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Theme" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Theme", + "record_class": "pyramid_oereb.core.records.theme.ThemeRecord" } diff --git a/tests/contrib.data_sources.standard/sources/test_theme_document.py b/tests/contrib.data_sources.standard/sources/test_theme_document.py index e34f0a4f39..f8b961b214 100644 --- a/tests/contrib.data_sources.standard/sources/test_theme_document.py +++ b/tests/contrib.data_sources.standard/sources/test_theme_document.py @@ -9,7 +9,8 @@ def source_params(db_connection): yield { "db_connection": db_connection, - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.ThemeDocument" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.ThemeDocument", + "record_class": "pyramid_oereb.core.records.theme_document.ThemeDocumentRecord" } diff --git a/tests/core/test_config.py b/tests/core/test_config.py index 4b857a85fb..6935a9d11c 100644 --- a/tests/core/test_config.py +++ b/tests/core/test_config.py @@ -118,7 +118,8 @@ def mock_read_logos(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.logo.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Logo" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Logo", + "record_class": "pyramid_oereb.core.records.logo.LogoRecord" } } }, 0), @@ -127,7 +128,8 @@ def mock_read_logos(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.logo.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Logo" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Logo", + "record_class": "pyramid_oereb.core.records.logo.LogoRecord" } } }, 1) @@ -251,7 +253,8 @@ def test_get_theme_config_by_code_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.theme.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Theme" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Theme", + "record_class": "pyramid_oereb.core.records.theme.ThemeRecord" } } }, 0), @@ -260,7 +263,8 @@ def test_get_theme_config_by_code_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.theme.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Theme" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Theme", + "record_class": "pyramid_oereb.core.records.theme.ThemeRecord" } } }, 1) @@ -287,7 +291,8 @@ def test_read_themes_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.theme_document.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.ThemeDocument" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.ThemeDocument", + "record_class": "pyramid_oereb.core.records.theme_document.ThemeDocumentRecord" } } }, 0), @@ -296,7 +301,8 @@ def test_read_themes_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.theme_document.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.ThemeDocument" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.ThemeDocument", + "record_class": "pyramid_oereb.core.records.theme_document.ThemeDocumentRecord" } } }, 1) @@ -446,7 +452,8 @@ def test_get_extract_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.general_information.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.GeneralInformation" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.GeneralInformation", + "record_class": "pyramid_oereb.core.records.general_information.GeneralInformationRecord" } } }, 0), @@ -455,7 +462,8 @@ def test_get_extract_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.general_information.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.GeneralInformation" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.GeneralInformation", + "record_class": "pyramid_oereb.core.records.general_information.GeneralInformationRecord" } } }, 1) @@ -483,7 +491,8 @@ def test_read_general_information_config_none(): "pyramid_oereb.contrib.data_sources.standard.sources.law_status.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.LawStatus" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.LawStatus", + "record_class": "pyramid_oereb.core.records.law_status.LawStatusRecord" } } }, 0), @@ -491,8 +500,9 @@ def test_read_general_information_config_none(): "source": { "class": "pyramid_oereb.contrib.data_sources.standard.sources.law_status.DatabaseSource", "params": { - "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.LawStatus" + "db_connection": "*main_db_connection", + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.LawStatus", + "record_class": "pyramid_oereb.core.records.law_status.LawStatusRecord" } } }, 1) @@ -520,7 +530,8 @@ def test_read_law_status_config_none(): "pyramid_oereb.contrib.data_sources.standard.sources.document.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Document" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Document", + "record_class": "pyramid_oereb.core.records.documents.DocumentRecord" } } }, 0), @@ -530,7 +541,8 @@ def test_read_law_status_config_none(): "pyramid_oereb.contrib.data_sources.standard.sources.document.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Document" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Document", + "record_class": "pyramid_oereb.core.records.documents.DocumentRecord" } } }, 1) @@ -557,7 +569,8 @@ def test_read_documents_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.office.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Office" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Office", + "record_class": "pyramid_oereb.core.records.office.OfficeRecord" } } }, 0), @@ -566,7 +579,8 @@ def test_read_documents_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.office.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Office" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Office", + "record_class": "pyramid_oereb.core.records.office.OfficeRecord" } } }, 1), @@ -593,7 +607,8 @@ def test_read_offices_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.availability.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Availability" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Availability", + "record_class": "pyramid_oereb.core.records.availability.AvailabilityRecord" } } }, 0), @@ -602,7 +617,8 @@ def test_read_offices_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.availability.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Availability" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Availability", + "record_class": "pyramid_oereb.core.records.availability.AvailabilityRecord" } } }, 1) @@ -629,7 +645,8 @@ def test_read_availabilities_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.glossary.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Glossary" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Glossary", + "record_class": "pyramid_oereb.core.records.glossary.GlossaryRecord" } } }, 0), @@ -638,7 +655,8 @@ def test_read_availabilities_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.glossary.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Glossary" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Glossary", + "record_class": "pyramid_oereb.core.records.glossary.GlossaryRecord" } } }, 1) @@ -665,7 +683,8 @@ def test_read_glossaries_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.disclaimer.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Disclaimer" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Disclaimer", + "record_class": "pyramid_oereb.core.records.disclaimer.DisclaimerRecord" } } }, 0), @@ -674,7 +693,8 @@ def test_read_glossaries_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.disclaimer.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Disclaimer" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Disclaimer", + "record_class": "pyramid_oereb.core.records.disclaimer.DisclaimerRecord" } } }, 1), @@ -701,7 +721,8 @@ def test_read_disclaimers_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.municipality.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Municipality" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Municipality", + "record_class": "pyramid_oereb.core.records.municipality.MunicipalityRecord" } } }, 0), @@ -710,7 +731,8 @@ def test_read_disclaimers_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.municipality.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Municipality" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.Municipality", + "record_class": "pyramid_oereb.core.records.municipality.MunicipalityRecord" } } }, 1) @@ -737,7 +759,8 @@ def test_read_municipalities_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.document_types.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.DocumentTypeText" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.DocumentTypeText", + "record_class": "pyramid_oereb.core.records.document_types.DocumentTypeRecord" } } }, 0), @@ -746,7 +769,8 @@ def test_read_municipalities_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.document_types.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.DocumentTypeText" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.DocumentTypeText", + "record_class": "pyramid_oereb.core.records.document_types.DocumentTypeRecord" } } }, 1) @@ -773,7 +797,8 @@ def test_read_document_types_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.real_estate_type.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.RealEstateType" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.RealEstateType", + "record_class": "pyramid_oereb.core.records.real_estate_type.RealEstateTypeRecord" } } }, 0), @@ -782,7 +807,8 @@ def test_read_document_types_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.real_estate_type.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.RealEstateType" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.RealEstateType", + "record_class": "pyramid_oereb.core.records.real_estate_type.RealEstateTypeRecord" } } }, 1) @@ -810,7 +836,8 @@ def test_read_real_estate_types_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.map_layering.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.MapLayering" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.MapLayering", + "record_class": "pyramid_oereb.core.records.map_layering.MapLayeringRecord" } } } @@ -821,7 +848,8 @@ def test_read_real_estate_types_config_none(): "class": "pyramid_oereb.contrib.data_sources.standard.sources.map_layering.DatabaseSource", "params": { "db_connection": "*main_db_connection", - "model": "pyramid_oereb.contrib.data_sources.standard.models.main.MapLayering" + "model": "pyramid_oereb.contrib.data_sources.standard.models.main.MapLayering", + "record_class": "pyramid_oereb.core.records.map_layering.MapLayeringRecord" } } } diff --git a/tests/resources/test_config.yml b/tests/resources/test_config.yml index ad896d48a6..4a804c86e9 100644 --- a/tests/resources/test_config.yml +++ b/tests/resources/test_config.yml @@ -78,6 +78,17 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: land_use_plans + record_class: &plr_records + documents: pyramid_oereb.core.records.documents.DocumentRecord + disclaimer: pyramid_oereb.core.records.disclaimer.DisclaimerRecord + geometry: pyramid_oereb.core.records.geometry.GeometryRecord + glossary: pyramid_oereb.core.records.glossary.GlossaryRecord + legend_entry: pyramid_oereb.core.records.view_service.LegendEntryRecord + office: pyramid_oereb.core.records.office.OfficeRecord + plr: pyramid_oereb.core.records.plr.PlrRecord + view_service: pyramid_oereb.core.records.view_service.ViewServiceRecord + law_status: pyramid_oereb.core.records.law_status.LawStatusRecord + datasource: pyramid_oereb.core.records.embeddable.DatasourceRecord hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -127,6 +138,7 @@ pyramid_oereb: # uncomment line above and comment line below to use integer type for primary keys model_factory: pyramid_oereb.contrib.data_sources.standard.models.theme.model_factory_string_pk schema_name: contaminated_sites + record_class: *plr_records hooks: get_symbol: pyramid_oereb.contrib.data_sources.standard.hook_methods.get_symbol get_symbol_ref: pyramid_oereb.core.hook_methods.get_symbol_ref @@ -159,6 +171,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.RealEstate + record_class: pyramid_oereb.core.records.real_estate.RealEstateRecord theme: source: @@ -166,6 +179,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.Theme + record_class: pyramid_oereb.core.records.theme.ThemeRecord law_status: inKraft: inKraft AenderungMitVorwirkung: AenderungMitVorwirkung @@ -178,6 +192,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.Logo + record_class: pyramid_oereb.core.records.logo.LogoRecord hooks: get_logo_ref: pyramid_oereb.core.hook_methods.get_logo_ref get_qr_code_ref: pyramid_oereb.core.hook_methods.get_qr_code_ref @@ -188,6 +203,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.DocumentTypeText + record_class: pyramid_oereb.core.records.document_types.DocumentTypeRecord general_information: source: @@ -195,6 +211,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.GeneralInformation + record_class: pyramid_oereb.core.records.general_information.GeneralInformationRecord law_status_labels: source: @@ -202,6 +219,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.LawStatus + record_class: pyramid_oereb.core.records.law_status.LawStatusRecord real_estate_type_lookup: Liegenschaft: "Liegenschaft" @@ -224,13 +242,16 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.RealEstateType + record_class: pyramid_oereb.core.records.real_estate_type.RealEstateTypeRecord offices: source: class: pyramid_oereb.contrib.data_sources.standard.sources.office.DatabaseSource params: db_connection: *main_db_connection + record_class: pyramid_oereb.core.records.office.OfficeRecord model: pyramid_oereb.contrib.data_sources.standard.models.main.Office + record_class: pyramid_oereb.core.records.office.OfficeRecord theme_document: source: @@ -238,6 +259,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.ThemeDocument + record_class: pyramid_oereb.core.records.theme_document.ThemeDocumentRecord documents: source: @@ -245,6 +267,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.Document + record_class: pyramid_oereb.core.records.document_types.DocumentTypeRecord map_layering: source: @@ -252,6 +275,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.MapLayering + record_class: pyramid_oereb.core.records.map_layering.MapLayeringRecord address: source: @@ -259,6 +283,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.Address + record_class: pyramid_oereb.core.records.address.AddressRecord disclaimer: source: @@ -266,6 +291,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.Disclaimer + record_class: pyramid_oereb.core.records.disclaimer.DisclaimerRecord availability: source: @@ -273,6 +299,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.Availability + record_class: pyramid_oereb.core.records.availability.AvailabilityRecord print: renderer: pyramid_oereb.contrib.print_proxy.mapfish_print.mapfish_print.Renderer @@ -326,6 +353,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.Glossary + record_class: pyramid_oereb.core.records.glossary.GlossaryRecord municipality: source: @@ -333,6 +361,7 @@ pyramid_oereb: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.Municipality + record_class: pyramid_oereb.core.records.municipality.MunicipalityRecord # The error message returned if an error occurs when requesting a static extract # The content of the message is defined in the specification (document "Inhalt und Darstellung des statischen Auszugs") @@ -357,6 +386,7 @@ section2: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.Theme + record_class: pyramid_oereb.core.records.theme.ThemeRecord law_status: inKraft: inKraft AenderungMitVorwirkung: AenderungMitVorwirkung @@ -368,6 +398,7 @@ section2: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.Logo + record_class: pyramid_oereb.core.records.logo.LogoRecord document_types: source: @@ -375,6 +406,7 @@ section2: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.DocumentTypeText + record_class: pyramid_oereb.core.records.document_types.DocumentTypeRecord general_information: source: @@ -382,6 +414,7 @@ section2: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.GeneralInformation + record_class: pyramid_oereb.core.records.general_information.GeneralInformationRecord real_estate_type: source: @@ -389,6 +422,7 @@ section2: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.RealEstateType + record_class: pyramid_oereb.core.records.real_estate_type.RealEstateTypeRecord law_status_labels: source: @@ -396,3 +430,4 @@ section2: params: db_connection: *main_db_connection model: pyramid_oereb.contrib.data_sources.standard.models.main.LawStatus + record_class: pyramid_oereb.core.records.law_status.LawStatusRecord