on master help sign in
[enh] template_oscar: show addressdata if possible
commitc38917bb2a472429f78cd00fffb5e7057ceecc02 authorThomas Pointhuber <thomas.pointhuber@gmx.at> dateMon 3 Nov 2014, 18:46 (12 years ago) parent2e7723a
4 files changed+52−3
searx/engines/openstreetmap.py+26−1 searx/static/oscar/css/oscar.min.css+1−1 searx/static/oscar/less/oscar/results.less+2 searx/templates/oscar/result_templates/map.html+23−1
searx/engines/openstreetmap.py+26−1
@@ -15,7 +15,7 @@ categories = ['map']
1515paging = False
1616
1717# search-url
18−url = 'https://nominatim.openstreetmap.org/search/{query}?format=json&polygon_geojson=1'
18+url = 'https://nominatim.openstreetmap.org/search/{query}?format=json&polygon_geojson=1&addressdetails=1'
1919
2020result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
2121
@@ -47,6 +47,30 @@ def response(resp):
4747 geojson = {u'type':u'Point',
4848 u'coordinates':[r['lon'],r['lat']]}
4949
50+ address_raw = r.get('address')
51+ address = {}
52+
53+ # get name
54+ if r['class'] == 'amenity' or\
55+ r['class'] == 'shop' or\
56+ r['class'] == 'tourism' or\
57+ r['class'] == 'leisure':
58+ if address_raw.get('address29'):
59+ address = {'name':address_raw.get('address29')}
60+ else:
61+ address = {'name':address_raw.get(r['type'])}
62+
63+ # add rest of adressdata, if something is already found
64+ if address.get('name'):
65+ address.update({'house_number':address_raw.get('house_number'),
66+ 'road':address_raw.get('road'),
67+ 'locality':address_raw.get('town', address_raw.get('village')),
68+ 'postcode':address_raw.get('postcode'),
69+ 'country':address_raw.get('country'),
70+ 'country_code':address_raw.get('country_code')})
71+ else:
72+ address = None
73+
5074 # append result
5175 results.append({'template': 'map.html',
5276 'title': title,
@@ -55,6 +79,7 @@ def response(resp):
5579 'latitude': r['lat'],
5680 'boundingbox': r['boundingbox'],
5781 'geojson': geojson,
82+ 'address': address,
5883 'url': url})
5984
6085 # return results
searx/static/oscar/css/oscar.min.css+1−1
@@ -5,7 +5,7 @@ input[type=checkbox]:checked~.label_hide_if_checked{display:none}
55input[type=checkbox]:not(:checked)~.label_hide_if_not_checked{display:none}
66.result_header{margin-bottom:5px;margin-top:20px}.result_header .favicon{margin-bottom:-3px}
77.result_header a{vertical-align:bottom}.result_header a .highlight{font-weight:bold}
8−.result-content .highlight{font-weight:bold}
8+.result-content{margin-top:5px}.result-content .highlight{font-weight:bold}
99.result-default{clear:both}
1010.result-images{float:left !important}
1111.img-thumbnail{margin:5px;max-height:128px;min-height:128px}
searx/static/oscar/less/oscar/results.less+2
@@ -17,6 +17,8 @@
1717}
1818
1919.result-content {
20+ margin-top: 5px;
21+
2022 .highlight {
2123 font-weight:bold;
2224 }
searx/templates/oscar/result_templates/map.html+23−1
@@ -7,7 +7,29 @@
77{% if (result.latitude and result.longitude) or result.boundingbox %}
88 <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>
99{% endif %}
10−
10+
11+{% if result.address %}
12+<p class="result-content result-adress" itemscope itemtype="http://schema.org/PostalAddress">
13+ {% if result.address.name %}
14+ <strong itemprop="name">{{ result.address.name }}</strong><br/>
15+ {% endif %}
16+ {% if result.address.road %}
17+ <span itemprop="streetAddress">
18+ {% if result.address.house_number %}{{ result.address.house_number }}, {% endif %}
19+ {{ result.address.road }}
20+ </span><br/>
21+ {% endif %}
22+ {% if result.address.locality %}
23+ <span itemprop="addressLocality">{{ result.address.locality }}</span>,
24+ {% if result.address.postcode %} <span itemprop="postalCode">{{ result.address.postcode }}</span>{% endif %}
25+ <br/>
26+ {% endif %}
27+ {% if result.address.country %}
28+ <span itemprop="addressCountry">{{ result.address.country }}</span>
29+ {% endif %}
30+</p><div class="clearfix"></div>
31+{% endif %}
32+
1133{% if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %}
1234
1335{% if (result.latitude and result.longitude) or result.boundingbox %}