Beispiel #1
0
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))
Beispiel #2
0
class JourneysSerializer(JourneysCommon):
    journeys = JourneySerializer(many=True)
    tickets = TicketSerializer(many=True, display_none=True)
    disruptions = pt.DisruptionSerializer(attr='impacts', many=True, display_none=True)
    context = MethodField(schema_type=ContextSerializer(), display_none=False)
    notes = DescribedField(schema_type=NoteSerializer(many=True))
    exceptions = DescribedField(schema_type=ExceptionSerializer(many=True))

    def get_context(self, obj):
        return ContextSerializer(obj, display_none=False).data
Beispiel #3
0
class CoveragesSerializer(serpy.DictSerializer):
    regions = CoverageSerializer(many=True)
    links = DescribedField(schema_type=LinkSchema(many=True))
    context = MethodField(schema_type=ContextSerializer(), display_none=False)

    def get_context(self, obj):
        return ContextSerializer(obj, is_utc=True, display_none=False).data
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
class JourneysSerializer(JourneysCommon):
    journeys = JourneySerializer(many=True)
    tickets = TicketSerializer(many=True, display_none=True)
    disruptions = pt.DisruptionSerializer(attr='impacts', 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
                    }
                }
            }
Beispiel #7
0
class SchedulesSerializer(PTReferentialSerializer):
    exceptions = DescribedField(schema_type=ExceptionSerializer(many=True))