Example #1
0
class PoiSerializer(serpy.DictSerializer):
    id = NestedPropertyField(attr='properties.geocoding.id', display_none=True)
    coord = CoordField()
    label = NestedPropertyField(attr='properties.geocoding.label', display_none=True)
    name = NestedPropertyField(attr='properties.geocoding.name', display_none=True)
    administrative_regions = AdministrativeRegionsSerializer(display_none=False)
    poi_type = jsonschema.MethodField(display_none=False)
    properties = jsonschema.MethodField(display_none=False)
    address = jsonschema.MethodField(display_none=False)

    def get_poi_type(self, obj):
        poi_types = obj.get('properties', {}).get('geocoding', {}).get('poi_types', [])
        return PoiTypeSerializer(poi_types[0]).data if isinstance(poi_types, list) and poi_types else None

    def get_properties(self, obj):
        return {
            p.get("key"): p.get("value")
            for p in obj.get('properties', {}).get('geocoding', {}).get('properties', [])
        }

    def get_address(self, obj):
        address = obj.get('properties', {}).get('geocoding', {}).get('address', None)
        if not address:
            return None
        poi_lon, poi_lat = get_lon_lat(obj)
        return create_address_field(address, poi_lat=poi_lat, poi_lon=poi_lon)
Example #2
0
class StopAreaSerializer(serpy.DictSerializer):
    id = NestedPropertyField(attr='properties.geocoding.id', display_none=True)
    coord = CoordField()
    label = NestedPropertyField(attr='properties.geocoding.label',
                                display_none=True)
    name = NestedPropertyField(attr='properties.geocoding.name',
                               display_none=True)
    administrative_regions = AdministrativeRegionsSerializer(
        display_none=False)
    timezone = NestedPropertyField(attr='properties.geocoding.timezone')
    commercial_modes = NestedDictGenericField(
        attr='properties.geocoding.commercial_modes', many=True)
    physical_modes = NestedDictGenericField(
        attr='properties.geocoding.physical_modes', many=True)
    comments = NestedDictCommentField(attr='properties.geocoding.comments',
                                      many=True)
    comment = jsonschema.MethodField(display_none=True)
    codes = NestedDictCodeField(attr='properties.geocoding.codes', many=True)
    properties = NestedPropertiesField(attr='properties.geocoding.properties',
                                       display_none=False)
    lines = LineSerializer(attr='properties.geocoding.lines', many=True)

    def get_comment(self, obj):
        # To be compatible with old version, we create the "comment" field in addition.
        # This field is a simple string, so we take only one comment (In our case, the first
        # element of the list).
        comments = obj.get('properties', {}).get('geocoding',
                                                 {}).get('comments')
        if comments:
            return next(iter(comments or []), None).get('name')
Example #3
0
class AdministrativeRegionSerializer(serpy.DictSerializer):
    id = NestedPropertyField(attr='properties.geocoding.id', display_none=True)
    name = NestedPropertyField(attr='properties.geocoding.name', display_none=True)
    label = NestedPropertyField(attr='properties.geocoding.label', display_none=True)
    zip_code = NestedPropertyField(attr='properties.geocoding.postcode')
    coord = CoordField()
    insee = NestedPropertyField(attr='properties.geocoding.citycode')
    level = IntNestedPropertyField(attr='properties.geocoding.level')
    administrative_regions = AdministrativeRegionsSerializer(display_none=False)
Example #4
0
class AddressSerializer(serpy.DictSerializer):
    id = CoordId(display_none=True)
    coord = CoordField()
    house_number = jsonschema.MethodField(display_none=True)
    label = NestedPropertyField(attr='properties.geocoding.label', display_none=True)
    name = NestedPropertyField(attr='properties.geocoding.name', display_none=True)
    administrative_regions = AdministrativeRegionsSerializer(display_none=False)

    def get_house_number(self, obj):
        geocoding = obj.get('properties', {}).get('geocoding', {})
        return get_house_number(geocoding.get('housenumber'))
Example #5
0
class PlacesCommonSerializer(serpy.DictSerializer):
    '''
    Warning: This class share it's interface with PlaceSerializer (for Kraken)
    If you add/modify fields here, please reflect your changes in
    'jormungandr.jormungandr.interfaces.v1.serializer.pt.PlaceSerializer'.
    '''

    id = NestedPropertyField(attr='properties.geocoding.id', display_none=True)
    name = NestedPropertyField(attr='properties.geocoding.name', display_none=True)
    quality = LiteralField(0, deprecated=True)
    distance = StringNestedPropertyField(attr='distance', display_none=False, required=False)
    embedded_type = LiteralField("administrative_region", display_none=True)
Example #6
0
class FreeFloatingSerializer(serpy.DictSerializer):
    public_id = NestedPropertyField(attr='public_id')
    provider_name = NestedPropertyField(attr='provider_name')
    id = NestedPropertyField(attr='id')
    type = NestedPropertyField(attr='type')
    attributes = NestedPropertyField(attr='attributes')
    propulsion = NestedPropertyField(attr='propulsion')
    battery = NestedPropertyField(attr='battery')
    deeplink = NestedPropertyField(attr='deeplink')
    coord = CoordSerializer(attr='coord')
    distance = NestedPropertyField(attr='distance')
Example #7
0
class GeocodeStopAreaSerializer(PlacesCommonSerializer):
    embedded_type = LiteralField("stop_area", display_none=True)
    name = NestedPropertyField(attr='properties.geocoding.label', display_none=True)
    stop_area = jsonschema.MethodField()

    def get_stop_area(self, obj):
        return StopAreaSerializer(obj).data
Example #8
0
class GeocodePoiSerializer(PlacesCommonSerializer):
    embedded_type = LiteralField("poi", display_none=True)
    name = NestedPropertyField(attr='properties.geocoding.label', display_none=True)
    poi = jsonschema.MethodField()

    def get_poi(self, obj):
        return PoiSerializer(obj).data
Example #9
0
class GeocodeAddressSerializer(PlacesCommonSerializer):
    embedded_type = LiteralField("address", display_none=True)
    id = CoordId(display_none=True)
    name = NestedPropertyField(attr='properties.geocoding.label', display_none=True)
    address = jsonschema.MethodField()

    def get_address(self, obj):
        return AddressSerializer(obj).data
Example #10
0
class PaginationSerializer(serpy.DictSerializer):
    start_page = NestedPropertyField(attr='start_page')
    items_on_page = NestedPropertyField(attr='items_on_page')
    items_per_page = NestedPropertyField(attr='items_per_page')
    total_result = NestedPropertyField(attr='total_result')