grandlyon: add custom scripts to check and display similar demands

This commit is contained in:
Frédéric Péters 2017-09-22 17:33:02 +02:00
parent 798fe826c5
commit e8332700cf
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,23 @@
import json
import os
from quixote import get_publisher
from wcs.wf.geolocate import GeolocateWorkflowStatusItem
result = False
coords = None
if 'form_var_numero' in vars():
geolocate = GeolocateWorkflowStatusItem()
geolocate.method = 'address_string'
geolocate.address_string = '[form_var_numero] [form_var_voie], [form_var_commune], France'
coords = geolocate.geolocate_address_string(None)
if coords:
lat, lon = coords['lat'], coords['lon']
lat1, lat2 = lat - 0.008, lat + 0.008
lon1, lon2 = lon - 0.006, lon + 0.006
geojson_file = os.path.join(get_publisher().app_dir, 'geojsons', form_slug + '.json')
for feature in json.load(open(geojson_file))['features']:
lon, lat = feature['geometry']['coordinates']
if lon > lon1 and lon < lon2 and lat > lat1 and lat < lat2:
result = True
break

View File

@ -0,0 +1,14 @@
from wcs.wf.geolocate import GeolocateWorkflowStatusItem
from qommon.form import MapWidget
result = ''
if 'form_var_numero' in vars():
geolocate = GeolocateWorkflowStatusItem()
geolocate.method = 'address_string'
geolocate.address_string = '[form_var_numero] [form_var_voie], [form_var_commune], France'
coords = geolocate.geolocate_address_string(None)
map_widget = MapWidget('geo', readonly=True, value='%(lat)s;%(lon)s' % coords,
initial_zoom=16)
result = '<div id="similar" data-geojson-url="%s">%s</div>' % (
'/geojsons/%s.json' % form_slug, map_widget.render())