-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgtfs_feed_impl.py
More file actions
31 lines (26 loc) · 1.29 KB
/
Copy pathgtfs_feed_impl.py
File metadata and controls
31 lines (26 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from shared.db_models.bounding_box_impl import BoundingBoxImpl
from shared.db_models.feed_impl import FeedImpl
from shared.database_gen.sqlacodegen_models import Gtfsfeed as GtfsfeedOrm
from shared.db_models.latest_dataset_impl import LatestDatasetImpl
from shared.db_models.location_impl import LocationImpl
from feeds_gen.models.gtfs_feed import GtfsFeed
class GtfsFeedImpl(FeedImpl, GtfsFeed):
"""Implementation of the `GtfsFeed` model.
This class converts a SQLAlchemy row DB object to a Pydantic model.
"""
class Config:
"""Pydantic configuration.
Enabling `from_attributes` method to create a model instance from a SQLAlchemy row object."""
from_attributes = True
@classmethod
def from_orm(cls, feed: GtfsfeedOrm | None) -> GtfsFeed | None:
gtfs_feed: GtfsFeed = super().from_orm(feed)
if not gtfs_feed:
return None
gtfs_feed.locations = [LocationImpl.from_orm(item) for item in feed.locations]
gtfs_feed.latest_dataset = LatestDatasetImpl.from_orm(feed.latest_dataset)
gtfs_feed.bounding_box = BoundingBoxImpl.from_orm(feed.bounding_box)
gtfs_feed.visualization_dataset_id = (
feed.visualization_dataset.stable_id if feed.visualization_dataset else None
)
return gtfs_feed