예제 #1
0
파일: schedule.py 프로젝트: xlqian/navitia
class DateTimeTypeSerializer(PbNestedSerializer):
    date_time = jsonschema.MethodField(schema_type=TimeOrDateTimeType,
                                       display_none=True)
    base_date_time = DateTimeField()
    additional_informations = pt.AdditionalInformation(
        attr='additional_informations', display_none=True)
    links = jsonschema.MethodField(schema_type=LinkSchema(many=True),
                                   display_none=True)
    data_freshness = EnumField(attr="realtime_level", display_none=True)
    occupancy = jsonschema.MethodField(schema_type=str, display_none=False)

    def get_occupancy(self, obj):
        return obj.occupancy if obj.HasField('occupancy') else None

    def get_links(self, obj):
        disruption_links = [
            create_internal_link(_type="disruption", rel="disruptions", id=uri)
            for uri in obj.impact_uris
        ]
        properties_links = pt.make_properties_links(obj.properties)
        return properties_links + disruption_links

    def get_date_time(self, obj):
        __date_time_null_value__ = 2**64 - 1
        if obj.time == __date_time_null_value__:
            return ""
        if obj.HasField('date'):
            return timestamp_to_str(obj.date + obj.time)
        return datetime.utcfromtimestamp(obj.time).strftime('%H%M%S')
예제 #2
0
class DateTimeTypeSerializer(PbNestedSerializer):
    date_time = jsonschema.MethodField(schema_type=TimeOrDateTimeType, display_none=True)
    base_date_time = DateTimeField()
    additional_informations = pt.AdditionalInformation(attr='additional_informations', display_none=True)
    links = pt.PropertiesLinksSerializer(attr="properties")
    data_freshness = EnumField(attr="realtime_level", display_none=True)

    def get_date_time(self, obj):
        __date_time_null_value__ = 2**64 - 1
        if obj.time == __date_time_null_value__:
            return ""
        if obj.HasField('date'):
            return timestamp_to_str(obj.date + obj.time)
        return datetime.utcfromtimestamp(obj.time).strftime('%H%M%S')