Source code for winterthur.models.address

from __future__ import annotations

from onegov.core.orm import Base
from onegov.core.orm.mixins import TimestampMixin
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import Mapped


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from typing import Self


[docs] class WinterthurAddress(Base, TimestampMixin):
[docs] __tablename__ = 'winterthur_addresses'
#: the adress id
[docs] id: Mapped[int] = mapped_column(primary_key=True)
#: the street
[docs] street_id: Mapped[int]
[docs] street: Mapped[str]
#: the house
[docs] house_number: Mapped[int]
[docs] house_extra: Mapped[str | None]
#: the place
[docs] zipcode: Mapped[int]
[docs] zipcode_extra: Mapped[int | None]
[docs] place: Mapped[str]
#: the district
[docs] district: Mapped[str]
#: the neighbourhood
[docs] neighbourhood: Mapped[str]
@classmethod
[docs] def as_addressless(cls, street_id: int, street: str) -> Self: return cls( street_id=street_id, street=street, house_number=-1, zipcode=-1, place='', district='', neighbourhood='', )
@property
[docs] def is_addressless(self) -> bool: return self.house_number == -1
@property
[docs] def title(self) -> str: if self.is_addressless: return self.street else: return f'{self.street} {self.house_number}{self.house_extra}'