[IMP] website, website_{*}: Google Maps API Key
As of June 22 2016, the use of API key is required to access the following: - Google Maps JavaScript API - Google Static Maps API - Google Street View Image API https://developers.google.com/maps/pricing-and-plans/standard-plan-2016-update For domains accessing the API before June 22, it will still work without an API key. Since Google advises to use the API key, we hide the Maps if no API key is defined.
This commit is contained in:
@@ -33,3 +33,17 @@ class WebsiteConfigSettings(models.TransientModel):
|
||||
module_website_form_editor = fields.Boolean("Form builde = create and customize forms")
|
||||
module_website_version = fields.Boolean("A/B testing and versioning")
|
||||
favicon = fields.Binary('Favicon', related='website_id.favicon')
|
||||
|
||||
|
||||
class BaseConfigSettings(models.TransientModel):
|
||||
_inherit = 'base.config.settings'
|
||||
|
||||
google_maps_api_key = fields.Char(string='Google Maps API Key')
|
||||
|
||||
def set_google_maps_api_key(self):
|
||||
self.env['ir.config_parameter'].set_param(
|
||||
'google_maps_api_key', (self.google_maps_api_key or '').strip(), groups=['base.group_system'])
|
||||
|
||||
def get_default_google_maps_api_key(self, fields):
|
||||
google_maps_api_key = self.env['ir.config_parameter'].get_param('google_maps_api_key', default='')
|
||||
return dict(google_maps_api_key=google_maps_api_key)
|
||||
|
||||
@@ -16,11 +16,15 @@ class Partner(models.Model):
|
||||
|
||||
@api.multi
|
||||
def google_map_img(self, zoom=8, width=298, height=298):
|
||||
google_maps_api_key = self.env['ir.config_parameter'].sudo().get_param('google_maps_api_key')
|
||||
if not google_maps_api_key:
|
||||
return False
|
||||
params = {
|
||||
'center': '%s, %s %s, %s' % (self.street or '', self.city or '', self.zip or '', self.country_id and self.country_id.name_get()[0][1] or ''),
|
||||
'size': "%sx%s" % (height, width),
|
||||
'zoom': zoom,
|
||||
'sensor': 'false',
|
||||
'key': google_maps_api_key,
|
||||
}
|
||||
return urlplus('//maps.googleapis.com/maps/api/staticmap', params)
|
||||
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_general_configuration_inherit_website" model="ir.ui.view">
|
||||
<field name="name">general.configuration.inherit.form</field>
|
||||
<field name="model">base.config.settings</field>
|
||||
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='google']" position="inside">
|
||||
<label for="id" string="Google Maps"/>
|
||||
<div name="google_maps">
|
||||
<div>
|
||||
Follow <a href="https://console.developers.google.com/flows/enableapi?apiid=maps_backend,static_maps_backend&keyType=CLIENT_SIDE&reusekey=true">the instructions</a> to create your key.
|
||||
</div>
|
||||
<div>
|
||||
<label for="google_maps_api_key" string="API Key"/>
|
||||
<field name="google_maps_api_key" class="oe_inline"/>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_website_config_settings" model="ir.ui.view">
|
||||
<field name="name">Website settings</field>
|
||||
<field name="model">website.config.settings</field>
|
||||
|
||||
@@ -910,9 +910,14 @@ Sitemap: <t t-esc="url_root"/>sitemap.xml
|
||||
"widget": "contact",
|
||||
"fields": ["name", "address", "phone", "mobile", "fax", "email"]}'/>
|
||||
</address>
|
||||
<a t-att-href="res_company.google_map_link()" target="_BLANK">
|
||||
<img class="thumbnail img-responsive" t-att-src="res_company.google_map_img()" />
|
||||
</a>
|
||||
<t t-if="res_company.google_map_img()">
|
||||
<a t-att-href="res_company.google_map_link()" target="_BLANK">
|
||||
<img class="thumbnail img-responsive" t-att-src="res_company.google_map_img()" />
|
||||
</a>
|
||||
</t>
|
||||
<t t-else="1">
|
||||
<a t-att-href="res_company.google_map_link()" target="_BLANK">Visualize on Google Maps</a>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="contactus" name="Contact us" page="True">
|
||||
|
||||
@@ -255,6 +255,7 @@ class WebsiteCrmPartnerAssign(WebsitePartnerPage):
|
||||
partners = partners[pager['offset']:pager['offset'] + self._references_per_page]
|
||||
|
||||
google_map_partner_ids = ','.join(map(str, [p.id for p in partners]))
|
||||
google_maps_api_key = request.env['ir.config_parameter'].sudo().get_param('google_maps_api_key')
|
||||
|
||||
values = {
|
||||
'countries': countries,
|
||||
@@ -266,6 +267,7 @@ class WebsiteCrmPartnerAssign(WebsitePartnerPage):
|
||||
'pager': pager,
|
||||
'searches': post,
|
||||
'search_path': "%s" % werkzeug.url_encode(post),
|
||||
'google_maps_api_key': google_maps_api_key,
|
||||
}
|
||||
return request.render("website_crm_partner_assign.index", values, status=partners and 200 or 404)
|
||||
|
||||
|
||||
@@ -118,25 +118,27 @@
|
||||
|
||||
<template id="ref_country" inherit_id="website_crm_partner_assign.index" customize_show="True" name="Left World Map">
|
||||
<xpath expr="//ul[@id='reseller_countries']" position="after">
|
||||
<!-- modal for large map -->
|
||||
<div class="modal fade partner_map_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">World Map</h4>
|
||||
<t t-if="google_maps_api_key">
|
||||
<!-- modal for large map -->
|
||||
<div class="modal fade partner_map_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">World Map</h4>
|
||||
</div>
|
||||
<iframe t-attf-src="/google_map/?width=898&height=485&partner_ids=#{ google_map_partner_ids }&partner_url=/partners/"
|
||||
style="width:898px; height:485px; border:0; padding:0; margin:0;"></iframe>
|
||||
</div>
|
||||
<iframe t-attf-src="/google_map/?width=898&height=485&partner_ids=#{ google_map_partner_ids }&partner_url=/partners/"
|
||||
style="width:898px; height:485px; border:0; padding:0; margin:0;"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- modal end -->
|
||||
<h3>World Map<button class="btn btn-link" data-toggle="modal" data-target=".partner_map_modal"><span class="fa fa-external-link" /></button></h3>
|
||||
<ul class="nav">
|
||||
<iframe t-attf-src="/google_map?width=260&height=240&partner_ids=#{ google_map_partner_ids }&partner_url=/partners/"
|
||||
style="width:260px; height:240px; border:0; padding:0; margin:0;" scrolling="no"></iframe>
|
||||
</ul>
|
||||
<!-- modal end -->
|
||||
<h3>World Map<button class="btn btn-link" data-toggle="modal" data-target=".partner_map_modal"><span class="fa fa-external-link" /></button></h3>
|
||||
<ul class="nav">
|
||||
<iframe t-attf-src="/google_map?width=260&height=240&partner_ids=#{ google_map_partner_ids }&partner_url=/partners/"
|
||||
style="width:260px; height:240px; border:0; padding:0; margin:0;" scrolling="no"></iframe>
|
||||
</ul>
|
||||
</t>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ class WebsiteCustomer(http.Controller):
|
||||
|
||||
partners = Partner.sudo().search(domain, offset=pager['offset'], limit=self._references_per_page)
|
||||
google_map_partner_ids = ','.join(map(str, partners.ids))
|
||||
google_maps_api_key = request.env['ir.config_parameter'].sudo().get_param('google_maps_api_key')
|
||||
|
||||
tags = Tag.search([('website_published', '=', True), ('partner_ids', 'in', partners.ids)], order='classname, name ASC')
|
||||
tag = tag_id and Tag.browse(tag_id) or False
|
||||
@@ -94,6 +95,7 @@ class WebsiteCustomer(http.Controller):
|
||||
'search_path': "?%s" % werkzeug.url_encode(post),
|
||||
'tag': tag,
|
||||
'tags': tags,
|
||||
'google_maps_api_key': google_maps_api_key,
|
||||
}
|
||||
return request.render("website_customer.index", values)
|
||||
|
||||
|
||||
@@ -67,25 +67,27 @@
|
||||
<!-- Option: left column: World Map -->
|
||||
<template id="opt_country" inherit_id="website_customer.index" customize_show="True" name="Show Map">
|
||||
<xpath expr="//div[@id='ref_left_column']" position="inside">
|
||||
<!-- modal for large map -->
|
||||
<div class="modal fade customer_map_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">World Map</h4>
|
||||
<t t-if="google_maps_api_key">
|
||||
<!-- modal for large map -->
|
||||
<div class="modal fade customer_map_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">World Map</h4>
|
||||
</div>
|
||||
<iframe t-attf-src="/google_map/?width=898&height=485&partner_ids=#{ google_map_partner_ids }&partner_url=/customers/"
|
||||
style="width:898px; height:485px; border:0; padding:0; margin:0;"></iframe>
|
||||
</div>
|
||||
<iframe t-attf-src="/google_map/?width=898&height=485&partner_ids=#{ google_map_partner_ids }&partner_url=/customers/"
|
||||
style="width:898px; height:485px; border:0; padding:0; margin:0;"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- modal end -->
|
||||
<h3>World Map<button class="btn btn-link" data-toggle="modal" data-target=".customer_map_modal"><span class="fa fa-external-link" /></button></h3>
|
||||
<ul class="nav">
|
||||
<iframe t-attf-src="/google_map?width=260&height=240&partner_ids=#{ google_map_partner_ids }&partner_url=/customers/"
|
||||
style="width:260px; height:240px; border:0; padding:0; margin:0;" scrolling="no"></iframe>
|
||||
</ul>
|
||||
<!-- modal end -->
|
||||
<h3>World Map<button class="btn btn-link" data-toggle="modal" data-target=".customer_map_modal"><span class="fa fa-external-link" /></button></h3>
|
||||
<ul class="nav">
|
||||
<iframe t-attf-src="/google_map?width=260&height=240&partner_ids=#{ google_map_partner_ids }&partner_url=/customers/"
|
||||
style="width:260px; height:240px; border:0; padding:0; margin:0;" scrolling="no"></iframe>
|
||||
</ul>
|
||||
</t>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -334,9 +334,14 @@
|
||||
<h4>Where</h4>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<a t-att-href="event.google_map_link()" target="_BLANK">
|
||||
<img t-att-src="event.google_map_img()" width="100%%"/>
|
||||
</a>
|
||||
<t t-if="event.google_map_img()">
|
||||
<a t-att-href="event.google_map_link()" target="_BLANK">
|
||||
<img t-att-src="event.google_map_img()" width="100%%"/>
|
||||
</a>
|
||||
</t>
|
||||
<t t-else="1">
|
||||
<a t-att-href="event.google_map_link()" target="_BLANK">Visualize on Google Maps</a>
|
||||
</t>
|
||||
<div itemprop="location" class="mt16 mb8" t-field="event.address_id" t-options='{
|
||||
"widget": "contact",
|
||||
"fields": ["address", "phone", "mobile", "fax", "email"]
|
||||
|
||||
@@ -52,8 +52,10 @@ class GoogleMap(http.Controller):
|
||||
else:
|
||||
partner_url = '/partners/'
|
||||
|
||||
google_maps_api_key = request.env['ir.config_parameter'].sudo().get_param('google_maps_api_key')
|
||||
values = {
|
||||
'partner_url': partner_url,
|
||||
'partner_data': json.dumps(partner_data)
|
||||
'partner_data': json.dumps(partner_data),
|
||||
'google_maps_api_key': google_maps_api_key,
|
||||
}
|
||||
return request.render("website_google_map.google_map", values)
|
||||
|
||||
@@ -14,7 +14,12 @@
|
||||
var odoo_partner_data = <t t-raw="partner_data"/>;
|
||||
</script>
|
||||
<div id="odoo-google-map"></div>
|
||||
<script src="//maps.google.com/maps/api/js?sensor=false"></script>
|
||||
<t t-if="google_maps_api_key">
|
||||
<script t-attf-src="//maps.google.com/maps/api/js?key=#{google_maps_api_key}"></script>
|
||||
</t>
|
||||
<t t-else="1">
|
||||
<script src="//maps.google.com/maps/api/js"></script>
|
||||
</t>
|
||||
<script type="text/javascript" src="/website_google_map/static/src/lib/markerclusterer.js"></script>
|
||||
<script type="text/javascript" src="/website_google_map/static/src/js/website_google_map.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -134,6 +134,7 @@ class WebsiteMembership(http.Controller):
|
||||
count_members += len(free_partner_ids)
|
||||
|
||||
google_map_partner_ids = ",".join(map(str, google_map_partner_ids))
|
||||
google_maps_api_key = request.env['ir.config_parameter'].sudo().get_param('google_maps_api_key')
|
||||
|
||||
partners = {p.id: p for p in Partner.sudo().browse(list(page_partner_ids))}
|
||||
|
||||
@@ -155,7 +156,8 @@ class WebsiteMembership(http.Controller):
|
||||
'pager': pager,
|
||||
'post': post,
|
||||
'search': "?%s" % werkzeug.url_encode(post),
|
||||
'search_count': count_members
|
||||
'search_count': count_members,
|
||||
'google_maps_api_key': google_maps_api_key,
|
||||
}
|
||||
return request.render("website_membership.index", values)
|
||||
|
||||
|
||||
@@ -103,25 +103,27 @@
|
||||
<template id="opt_index_google_map" name="Left World Map"
|
||||
customize_show="True" inherit_id="website_membership.index">
|
||||
<xpath expr="//div[@id='left_column']/ul[last()]" position="after">
|
||||
<!-- modal for large map -->
|
||||
<div class="modal fade partner_map_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">World Map</h4>
|
||||
<t t-if="google_maps_api_key">
|
||||
<!-- modal for large map -->
|
||||
<div class="modal fade partner_map_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">World Map</h4>
|
||||
</div>
|
||||
<iframe t-attf-src="/google_map/?width=898&height=485&partner_ids=#{ google_map_partner_ids }&partner_url=/members/"
|
||||
style="width:898px; height:485px; border:0; padding:0; margin:0;"></iframe>
|
||||
</div>
|
||||
<iframe t-attf-src="/google_map/?width=898&height=485&partner_ids=#{ google_map_partner_ids }&partner_url=/members/"
|
||||
style="width:898px; height:485px; border:0; padding:0; margin:0;"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- modal end -->
|
||||
<h3>World Map<button class="btn btn-link" data-toggle="modal" data-target=".partner_map_modal"><span class="fa fa-external-link" /></button></h3>
|
||||
<ul class="nav">
|
||||
<iframe t-attf-src="/google_map/?width=260&height=240&partner_ids=#{ google_map_partner_ids }&partner_url=/members/"
|
||||
style="width:260px; height:240px; border:0; padding:0; margin:0;"></iframe>
|
||||
</ul>
|
||||
<!-- modal end -->
|
||||
<h3>World Map<button class="btn btn-link" data-toggle="modal" data-target=".partner_map_modal"><span class="fa fa-external-link" /></button></h3>
|
||||
<ul class="nav">
|
||||
<iframe t-attf-src="/google_map/?width=260&height=240&partner_ids=#{ google_map_partner_ids }&partner_url=/members/"
|
||||
style="width:260px; height:240px; border:0; padding:0; margin:0;"></iframe>
|
||||
</ul>
|
||||
</t>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user