Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
                    }
                }
            }
Ejemplo n.º 4
0
class SchedulesSerializer(PTReferentialSerializer):
    exceptions = DescribedField(schema_type=ExceptionSerializer(many=True))