-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demonstrator for source/record refactoring
- Loading branch information
Showing
29 changed files
with
286 additions
and
145 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 13 additions & 35 deletions
48
pyramid_oereb/contrib/data_sources/standard/sources/address.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,26 @@ | ||
# -*- 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. | ||
street_name (unicode): The name of the street for the desired address. | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.