0001-misc-add-support-for-a-country-to-use-as-default-in-.patch
tests/form_pages/test_all.py | ||
---|---|---|
3942 | 3942 |
formdef.data_class().wipe() |
3943 | 3943 |
assert 'qommon.map.js' in resp.text |
3944 | 3944 |
assert 'qommon.geolocation.js' in resp.text |
3945 |
assert 'WCS_DEFAULT_GEOCODING_COUNTRY' not in resp.text |
|
3946 | ||
3947 |
# check page has default geocoding country in a javascript variable if set |
|
3948 |
if not pub.site_options.has_section('options'): |
|
3949 |
pub.site_options.add_section('options') |
|
3950 |
pub.site_options.set('options', 'default-geocoding-country', 'France') |
|
3951 |
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd: |
|
3952 |
pub.site_options.write(fd) |
|
3953 | ||
3954 |
resp = get_app(pub).get('/test/') |
|
3955 |
assert 'WCS_DEFAULT_GEOCODING_COUNTRY' in resp.text |
|
3945 | 3956 | |
3946 | 3957 | |
3947 | 3958 |
def test_form_map_field_prefill_address(pub): |
wcs/qommon/http_response.py | ||
---|---|---|
125 | 125 |
self.add_javascript_code( |
126 | 126 |
'var WCS_ROOT_URL = "%s";\n' % get_publisher().get_frontoffice_url() |
127 | 127 |
) |
128 |
default_geocoding_country = get_publisher().get_site_option('default-geocoding-country') |
|
129 |
if default_geocoding_country: |
|
130 |
self.add_javascript_code( |
|
131 |
'var WCS_DEFAULT_GEOCODING_COUNTRY = "%s";' % default_geocoding_country |
|
132 |
) |
|
128 | 133 |
if script_name == 'wcs.listing.js': |
129 | 134 |
self.add_javascript(['../../i18n.js', 'jquery.js', 'jquery-ui.js']) |
130 | 135 |
if script_name == 'qommon.admin.js': |
wcs/qommon/static/js/qommon.geolocation.js | ||
---|---|---|
129 | 129 |
$form[0].wait_for_changes = true; |
130 | 130 |
var address = ''; |
131 | 131 |
var found_city = false; |
132 |
var found_country = false; |
|
132 | 133 |
$(['number-and-street', 'house', 'road', 'postcode', 'city', 'country']).each(function(idx, elem) { |
133 | 134 |
var part = $('div[data-geolocation="' + elem + '"]').find('input, textarea, select').val(); |
134 | 135 |
if (part) { |
... | ... | |
139 | 140 |
if (elem == 'postcode' || elem == 'city') { |
140 | 141 |
found_city = true; |
141 | 142 |
} |
143 |
if (elem == 'country') { |
|
144 |
found_country = true; |
|
145 |
} |
|
142 | 146 |
} |
143 | 147 |
}); |
144 | 148 |
if (found_city) { |
149 |
if (!found_country && typeof(WCS_DEFAULT_GEOCODING_COUNTRY) !== 'undefined') { |
|
150 |
address += WCS_DEFAULT_GEOCODING_COUNTRY; |
|
151 |
} |
|
145 | 152 |
$.getJSON(WCS_ROOT_URL + '/api/geocoding?q=' + address, function(data) { |
146 | 153 |
if (data && $(data).length > 0) { |
147 | 154 |
var coords = {lat: data[0].lat, lng: data[0].lon}; |
148 |
- |