class PlacesSerializer(serpy.Serializer): error = ErrorSerializer(display_none=False) feed_publishers = FeedPublisherSerializer(many=True, display_none=True) disruptions = pt.DisruptionSerializer(attr='impacts', many=True, display_none=True) places = pt.PlaceSerializer(many=True)
class JourneysCommon(PbNestedSerializer): error = ErrorSerializer(display_none=False) feed_publishers = FeedPublisherSerializer(many=True, display_none=True) links = MethodField(schema_type=LinkSchema(many=True), display_none=True) def get_links(self, obj): # note: some request args can be there several times, # but when there is only one elt, flask does not want lists response = [] for value in obj.links: args = {} for e in value.kwargs: if len(e.values) > 1: args[e.key] = [v for v in e.values] else: args[e.key] = e.values[0] args["_type"] = value.type args["templated"] = value.is_templated args["description"] = value.description args["rel"] = value.rel response.append( create_external_link('v1.{}'.format(value.ressource_name), **args)) return response
class PTReferentialSerializerNoContext(serpy.Serializer): pagination = PaginationSerializer(attr='pagination', display_none=True) error = ErrorSerializer(display_none=False) feed_publishers = FeedPublisherSerializer(many=True, display_none=True) disruptions = pt.DisruptionSerializer(attr='impacts', many=True, display_none=True) notes = DescribedField(schema_type=NoteSerializer(many=True)) links = DescribedField(schema_type=LinkSchema(many=True))
class PTReferentialSerializer(serpy.Serializer): pagination = PaginationSerializer(attr='pagination', display_none=True, required=True) error = ErrorSerializer(display_none=False) feed_publishers = FeedPublisherSerializer(many=True, display_none=False) disruptions = pt.DisruptionSerializer(attr='impacts', many=True)
class PtObjectsSerializer(serpy.Serializer): error = ErrorSerializer(display_none=False) feed_publishers = FeedPublisherSerializer(many=True, display_none=True) disruptions = pt.DisruptionSerializer(attr='impacts', many=True, display_none=True) pt_objects = pt.PtObjectSerializer(many=True, attr='places') links = DescribedField(schema_type=LinkSchema(many=True)) context = MethodField(schema_type=ContextSerializer(), display_none=False) def get_context(self, obj): return ContextSerializer(obj, False, display_none=False).data
class PlacesSerializer(serpy.Serializer): error = ErrorSerializer(display_none=False) feed_publishers = FeedPublisherSerializer(many=True, display_none=True) disruptions = pt.DisruptionSerializer(attr='impacts', many=True, display_none=True) places = pt.PlaceSerializer(many=True) context = MethodField(schema_type=ContextSerializer(), display_none=False) def get_context(self, obj): return ContextSerializer(obj, display_none=False).data
class JourneysSerializer(PbNestedSerializer): journeys = JourneySerializer(many=True) error = ErrorSerializer(display_none=False, attr='error') tickets = TicketSerializer(many=True, display_none=True) disruptions = pt.DisruptionSerializer(attr='impacts', many=True, display_none=True) feed_publishers = FeedPublisherSerializer(many=True, display_none=True) links = MethodField(schema_type=LinkSchema(many=True), display_none=True) context = MethodField(schema_type=ContextSerializer(), display_none=True) notes = DescribedField(schema_type=NoteSerializer(many=True)) exceptions = DescribedField(schema_type=ExceptionSerializer(many=True)) def get_context(self, obj): if obj.HasField(str('car_co2_emission')): return ContextSerializer(obj, display_none=False).data else: return { 'car_direct_path': { 'co2_emission': { 'unit': '', 'value': 0.0 } } } def get_links(self, obj): # note: some request args can be there several times, # but when there is only one elt, flask does not want lists response = [] for value in obj.links: args = {} for e in value.kwargs: if len(e.values) > 1: args[e.key] = [v for v in e.values] else: args[e.key] = e.values[0] response.append( create_external_link('v1.{}'.format(value.ressource_name), rel=value.rel, _type=value.type, templated=value.is_templated, description=value.description, **args)) return response