[enh] template_oscar: show addressdata if possible

This commit is contained in:
Thomas Pointhuber 2014-11-03 18:46:58 +01:00
parent 2e7723a6c1
commit c38917bb2a
4 changed files with 52 additions and 3 deletions

View file

@ -15,7 +15,7 @@ categories = ['map']
paging = False
# search-url
url = 'https://nominatim.openstreetmap.org/search/{query}?format=json&polygon_geojson=1'
url = 'https://nominatim.openstreetmap.org/search/{query}?format=json&polygon_geojson=1&addressdetails=1'
result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
@ -47,6 +47,30 @@ def response(resp):
geojson = {u'type':u'Point',
u'coordinates':[r['lon'],r['lat']]}
address_raw = r.get('address')
address = {}
# get name
if r['class'] == 'amenity' or\
r['class'] == 'shop' or\
r['class'] == 'tourism' or\
r['class'] == 'leisure':
if address_raw.get('address29'):
address = {'name':address_raw.get('address29')}
else:
address = {'name':address_raw.get(r['type'])}
# add rest of adressdata, if something is already found
if address.get('name'):
address.update({'house_number':address_raw.get('house_number'),
'road':address_raw.get('road'),
'locality':address_raw.get('town', address_raw.get('village')),
'postcode':address_raw.get('postcode'),
'country':address_raw.get('country'),
'country_code':address_raw.get('country_code')})
else:
address = None
# append result
results.append({'template': 'map.html',
'title': title,
@ -55,6 +79,7 @@ def response(resp):
'latitude': r['lat'],
'boundingbox': r['boundingbox'],
'geojson': geojson,
'address': address,
'url': url})
# return results

View file

@ -5,7 +5,7 @@ input[type=checkbox]:checked~.label_hide_if_checked{display:none}
input[type=checkbox]:not(:checked)~.label_hide_if_not_checked{display:none}
.result_header{margin-bottom:5px;margin-top:20px}.result_header .favicon{margin-bottom:-3px}
.result_header a{vertical-align:bottom}.result_header a .highlight{font-weight:bold}
.result-content .highlight{font-weight:bold}
.result-content{margin-top:5px}.result-content .highlight{font-weight:bold}
.result-default{clear:both}
.result-images{float:left !important}
.img-thumbnail{margin:5px;max-height:128px;min-height:128px}

View file

@ -17,6 +17,8 @@
}
.result-content {
margin-top: 5px;
.highlight {
font-weight:bold;
}

View file

@ -8,6 +8,28 @@
<small> &bull; <a class="text-info btn-collapse collapsed searx_init_map cursor-pointer" data-toggle="collapse" data-target="#result-map-{{ index }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %} data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}">{{ icon('globe') }} {{ _('show map') }}</a></small>
{% endif %}
{% if result.address %}
<p class="result-content result-adress" itemscope itemtype="http://schema.org/PostalAddress">
{% if result.address.name %}
<strong itemprop="name">{{ result.address.name }}</strong><br/>
{% endif %}
{% if result.address.road %}
<span itemprop="streetAddress">
{% if result.address.house_number %}{{ result.address.house_number }}, {% endif %}
{{ result.address.road }}
</span><br/>
{% endif %}
{% if result.address.locality %}
<span itemprop="addressLocality">{{ result.address.locality }}</span>,
{% if result.address.postcode %} <span itemprop="postalCode">{{ result.address.postcode }}</span>{% endif %}
<br/>
{% endif %}
{% if result.address.country %}
<span itemprop="addressCountry">{{ result.address.country }}</span>
{% endif %}
</p><div class="clearfix"></div>
{% endif %}
{% if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %}
{% if (result.latitude and result.longitude) or result.boundingbox %}