Source code for winterthur.models.address

from onegov.core.orm import Base
from onegov.core.orm.mixins import TimestampMixin
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import Text


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from typing_extensions import Self


[docs] class WinterthurAddress(Base, TimestampMixin):
[docs] __tablename__ = 'winterthur_addresses'
#: the adress id
[docs] id: 'Column[int]' = Column(Integer, nullable=False, primary_key=True)
#: the street
[docs] street_id: 'Column[int]' = Column(Integer, nullable=False)
[docs] street: 'Column[str]' = Column(Text, nullable=False)
#: the house
[docs] house_number: 'Column[int]' = Column(Integer, nullable=False)
[docs] house_extra: 'Column[str | None]' = Column(Text, nullable=True)
#: the place
[docs] zipcode: 'Column[int]' = Column(Integer, nullable=False)
[docs] zipcode_extra: 'Column[int | None]' = Column(Integer, nullable=True)
[docs] place: 'Column[str]' = Column(Text, nullable=False)
#: the district
[docs] district: 'Column[str]' = Column(Text, nullable=False)
#: the neighbourhood
[docs] neighbourhood: 'Column[str]' = Column(Text, nullable=False)
@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}"