From 7603b33b2bef5feaff0d61f633841305f7ad606f Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Thu, 2 Nov 2023 09:11:11 +0000 Subject: [PATCH] Fix some bugs --- matcher/model.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/matcher/model.py b/matcher/model.py index 1c68da7..63fba92 100644 --- a/matcher/model.py +++ b/matcher/model.py @@ -19,6 +19,7 @@ from sqlalchemy.orm import ( backref, column_property, deferred, + mapped_column, registry, relationship, ) @@ -473,7 +474,7 @@ def location_objects( return locations -class MapBase(Base): +class MapMixin: """Map base class.""" @declared_attr @@ -485,7 +486,7 @@ class MapBase(Base): admin_level = Column(String) boundary = Column(String) - tags: Mapped[postgresql.HSTORE] + tags: Mapped[postgresql.hstore] = mapped_column(postgresql.HSTORE) @declared_attr def way(cls): @@ -494,19 +495,19 @@ class MapBase(Base): ) @declared_attr - def kml(cls) -> sqlalchemy.orm.properties.ColumnProperty: + def kml(cls) -> Mapped[str]: """Get object in KML format.""" return column_property(func.ST_AsKML(cls.way), deferred=True) @declared_attr - def geojson_str(cls) -> sqlalchemy.orm.properties.ColumnProperty: + def geojson_str(cls) -> Mapped[str]: """Get object as GeoJSON string.""" return column_property( func.ST_AsGeoJSON(cls.way, maxdecimaldigits=6), deferred=True ) @declared_attr - def as_EWKT(cls) -> sqlalchemy.orm.properties.ColumnProperty: + def as_EWKT(cls) -> Mapped[str]: """As EWKT.""" return column_property(func.ST_AsEWKT(cls.way), deferred=True) @@ -568,13 +569,13 @@ class MapBase(Base): return f"https://www.openstreetmap.org/{self.type}/{self.id}" -class Point(MapBase): +class Point(MapMixin, Base): """OSM planet point.""" type = "node" -class Line(MapBase): +class Line(MapMixin, Base): """OSM planet line.""" @property @@ -588,7 +589,7 @@ class Line(MapBase): return cls.query.get(src_id) -class Polygon(MapBase): +class Polygon(MapMixin, Base): """OSM planet polygon.""" way_area = Column(Float)