@@ -37,7 +37,7 @@ def get_gtfs_feeds_query(
3737 dataset_latitudes : str | None = None ,
3838 dataset_longitudes : str | None = None ,
3939 bounding_filter_method : str | None = None ,
40- is_official : bool = False ,
40+ is_official : bool | None = None ,
4141 published_only : bool = True ,
4242 include_options_for_joinedload : bool = True ,
4343) -> Query [any ]:
@@ -46,35 +46,42 @@ def get_gtfs_feeds_query(
4646 stable_id = stable_id ,
4747 provider__ilike = provider ,
4848 producer_url__ilike = producer_url ,
49- location = LocationFilter (
50- country_code = country_code ,
51- subdivision_name__ilike = subdivision_name ,
52- municipality__ilike = municipality ,
53- ),
49+ location = None ,
5450 )
5551
56- subquery = gtfs_feed_filter .filter (select (Gtfsfeed .id ). join ( Location , Gtfsfeed . locations ) )
52+ subquery = gtfs_feed_filter .filter (select (Gtfsfeed .id ))
5753 subquery = apply_bounding_filtering (
5854 subquery , dataset_latitudes , dataset_longitudes , bounding_filter_method
5955 ).subquery ()
60-
6156 feed_query = (
6257 db_session .query (Gtfsfeed )
6358 .outerjoin (Gtfsfeed .gtfsdatasets )
6459 .filter (Gtfsfeed .id .in_ (subquery ))
65- .filter ((Gtfsdataset .latest ) | ( Gtfsdataset .id == None )) # noqa: E711
60+ .filter (or_ (Gtfsdataset .latest , Gtfsdataset .id == None )) # noqa: E711
6661 )
62+
63+ if country_code or subdivision_name or municipality :
64+ location_filter = LocationFilter (
65+ country_code = country_code ,
66+ subdivision_name__ilike = subdivision_name ,
67+ municipality__ilike = municipality ,
68+ )
69+ location_subquery = location_filter .filter (select (Location .id ))
70+ feed_query = feed_query .filter (Gtfsfeed .locations .any (Location .id .in_ (location_subquery )))
71+
6772 if published_only :
6873 feed_query = feed_query .filter (Gtfsfeed .operational_status == "published" )
6974
75+ feed_query = add_official_filter (feed_query , is_official )
76+
7077 if include_options_for_joinedload :
7178 feed_query = feed_query .options (
7279 contains_eager (Gtfsfeed .gtfsdatasets )
7380 .joinedload (Gtfsdataset .validation_reports )
7481 .joinedload (Validationreport .notices ),
7582 * get_joinedload_options (),
7683 ).order_by (Gtfsfeed .provider , Gtfsfeed .stable_id )
77- feed_query = add_official_filter ( feed_query , is_official )
84+
7885 feed_query = feed_query .limit (limit ).offset (offset )
7986 return feed_query
8087
0 commit comments