DigitalSignage/controllers/main.py

54 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http
import logging
from odoo.http import request
_logger = logging.getLogger(__name__)
from odoo.tools.json import scriptsafe
class GoogleMap(http.Controller):
'''
This class generates on-the-fly partner maps that can be reused in every
website page. To do so, just use an ``<iframe ...>`` whose ``src``
attribute points to ``/google_map`` (this controller generates a complete
HTML5 page).
URL query parameters:
- ``partner_ids``: a comma-separated list of ids (partners to be shown)
- ``partner_url``: the base-url to display the partner
(eg: if ``partner_url`` is ``/partners/``, when the user will click on
a partner on the map, it will be redirected to <myodoo>.com/partners/<id>)
In order to resize the map, simply resize the ``iframe`` with CSS
directives ``width`` and ``height``.
'''
@http.route(['/google_map'], type='http', auth="public", website=True, sitemap=False)
def google_map(self, *arg, **post):
projects = request.env['dss.projects'].sudo().search([('standort_visible', '=', True)])
settings = (request.env['dss.settings'].search([],limit=1))
google_maps_api_key = settings.google_maps_key
_logger.info("Google Maps " + str(projects)+ " and Record : "+str(len(projects)))
projects_data = {
"counter": len(projects),
"projects": []
}
for project in projects.with_context(show_address=True):
projects_data["projects"].append({
'id': project.id,
'name': project.projektname,
'latitude': str(project.standort_lati) if project.standort_lati else False,
'longitude': str(project.standort_long) if project.standort_long else False,
})
values = {
'partner_url': partner_url,
'partner_data': scriptsafe.dumps(projects_data),
'google_maps_api_key': google_maps_api_key,
}
return request.render("DigitalSignage.google_map", values)