[enh] template_oscar: show addressdata if possible
This commit is contained in:
		
							parent
							
								
									2e7723a6c1
								
							
						
					
					
						commit
						c38917bb2a
					
				| @ -15,7 +15,7 @@ categories = ['map'] | |||||||
| paging = False | paging = False | ||||||
| 
 | 
 | ||||||
| # search-url | # 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}' | result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}' | ||||||
| 
 | 
 | ||||||
| @ -47,6 +47,30 @@ def response(resp): | |||||||
|             geojson = {u'type':u'Point',  |             geojson = {u'type':u'Point',  | ||||||
|                        u'coordinates':[r['lon'],r['lat']]} |                        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 |         # append result | ||||||
|         results.append({'template': 'map.html', |         results.append({'template': 'map.html', | ||||||
|                         'title': title, |                         'title': title, | ||||||
| @ -55,6 +79,7 @@ def response(resp): | |||||||
|                         'latitude': r['lat'], |                         'latitude': r['lat'], | ||||||
|                         'boundingbox': r['boundingbox'], |                         'boundingbox': r['boundingbox'], | ||||||
|                         'geojson': geojson, |                         'geojson': geojson, | ||||||
|  |                         'address': address, | ||||||
|                         'url': url}) |                         'url': url}) | ||||||
| 
 | 
 | ||||||
|     # return results |     # return results | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								searx/static/oscar/css/oscar.min.css
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								searx/static/oscar/css/oscar.min.css
									
									
									
									
										vendored
									
									
								
							| @ -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} | 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{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_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-default{clear:both} | ||||||
| .result-images{float:left !important} | .result-images{float:left !important} | ||||||
| .img-thumbnail{margin:5px;max-height:128px;min-height:128px} | .img-thumbnail{margin:5px;max-height:128px;min-height:128px} | ||||||
|  | |||||||
| @ -17,6 +17,8 @@ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| .result-content { | .result-content { | ||||||
|  |     margin-top: 5px; | ||||||
|  | 
 | ||||||
|     .highlight { |     .highlight { | ||||||
|         font-weight:bold; |         font-weight:bold; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -8,6 +8,28 @@ | |||||||
|     <small> • <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> |     <small> • <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 %} | {% 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.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %} | ||||||
| 
 | 
 | ||||||
| {% if (result.latitude and result.longitude) or result.boundingbox %} | {% if (result.latitude and result.longitude) or result.boundingbox %} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Thomas Pointhuber
						Thomas Pointhuber