Skip to content

Commit

Permalink
Re: #113 - Fix Tour Dossier Departure nested Query (#125)
Browse files Browse the repository at this point in the history
* Fix #113 - query-chain departures on tour-dossier

1. Adding the _Parent namedtuple in models.base broke this existing
   behaviour when Querying for departures under a tour-dossier

We can remove this, as 1) Tours are deprecated & 2) We use Sieve to
paginate through the departures resources under a tour-dossier.
  • Loading branch information
marz619 committed Apr 20, 2020
1 parent 1110dec commit 7171ea4
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions gapipy/resources/tour/tour_dossier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
from __future__ import unicode_literals

from gapipy.models import AdvertisedDeparture
from gapipy.query import Query
from gapipy.resources.base import Resource
from gapipy.resources.booking_company import BookingCompany
from gapipy.utils import get_resource_class_from_class_name


MAP_IMAGE_TYPE = 'MAP'
BANNER_IMAGE_TYPE = 'BANNER'
Expand All @@ -15,6 +12,7 @@
class TourDossier(Resource):

_resource_name = 'tour_dossiers'
_is_parent_resource = True

_as_is_fields = [
'id',
Expand All @@ -29,40 +27,31 @@ class TourDossier(Resource):
'site_links',
'slug',
]

_date_fields = [
'departures_start_date',
'departures_end_date',
]

_resource_fields = [
('tour', 'Tour'),
]

_resource_collection_fields = [
('departures', 'Departure'),
]

_model_collection_fields = [
('advertised_departures', AdvertisedDeparture),
('booking_companies', BookingCompany),
('structured_itineraries', 'Itinerary'),
]

def _set_resource_collection_field(self, field, value):
"""
Overridden to ensure that the `departures` query has the right
parent resource (i.e. the tour and not the tour dossier).
"""
if field == 'departures':
resource_cls = get_resource_class_from_class_name('Departure')
# Tour dossiers always have the same id as the corresponding tour
parent = ('tours', self.id, None)
query = Query(self._client, resource_cls, parent=parent, raw_data=value)
setattr(self, field, query)
else:
return super(TourDossier, self)._set_resource_collection_field(field, value)

def _get_image_url(self, image_type):
for image in self.images:
if image['type'] == image_type:
return image['image_href']
return None

def get_map_url(self):
return self._get_image_url(MAP_IMAGE_TYPE)
Expand All @@ -77,8 +66,10 @@ def get_trip_detail(self, label):
for detail in self.details:
if detail['detail_type']['label'] == label:
return detail['body']
return None

def get_category_name(self, label):
for category in self.categories:
if category['category_type']['label'] == label:
return category['name']
return None

0 comments on commit 7171ea4

Please sign in to comment.