diff --git a/web_favicon/README.rst b/web_favicon/README.rst new file mode 100644 index 00000000..c9bb1ddb --- /dev/null +++ b/web_favicon/README.rst @@ -0,0 +1,68 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +==================== +Custom shortcut icon +==================== + +This module was written to allow you to customize your Odoo instance's shortcut +icon (aka favicon). This is useful for branding purposes, but also for +integrators who have many different Odoo instances running and need to see at a +glance which browser tab does what. + +Configuration +============= + +Upload your favicon (16x16, 32x32 or 64x64 pixels, 16 colors) on the company +form. The file format whould be ico, gif or png with 16x16, 32x32 or 64x64 +pixels and 16 colors. + +Note that most browsers cache favicons basically forever, so if you want your +icon to show up, you'll most probably have to delete you browser cache. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/162/8.0 + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== + +* allow to upload some big icon (preferrably SVG or the like) and generate icons suitable for mobile devices + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ + +* Holger Brunn + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/web_favicon/__init__.py b/web_favicon/__init__.py new file mode 100644 index 00000000..d8724ec7 --- /dev/null +++ b/web_favicon/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import models +from . import controllers diff --git a/web_favicon/__openerp__.py b/web_favicon/__openerp__.py new file mode 100644 index 00000000..10d18800 --- /dev/null +++ b/web_favicon/__openerp__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + "name": "Custom shortcut icon", + "version": "8.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Website", + "summary": "Allows to set a custom shortcut icon", + "depends": [ + 'web', + ], + "data": [ + "views/res_company.xml", + 'views/templates.xml', + ], + "qweb": [ + ], + "test": [ + ], + "auto_install": False, + "installable": True, + "application": False, + "external_dependencies": { + 'python': [], + }, +} diff --git a/web_favicon/controllers/__init__.py b/web_favicon/controllers/__init__.py new file mode 100644 index 00000000..5c319aec --- /dev/null +++ b/web_favicon/controllers/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import web_favicon diff --git a/web_favicon/controllers/web_favicon.py b/web_favicon/controllers/web_favicon.py new file mode 100644 index 00000000..f9212ce4 --- /dev/null +++ b/web_favicon/controllers/web_favicon.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import StringIO +import base64 +from openerp import http +from openerp.tools.misc import file_open + + +class WebFavicon(http.Controller): + + @http.route('/web_favicon/favicon', type='http', auth="none") + def icon(self): + request = http.request + if 'uid' in request.env.context: + user = request.env['res.users'].browse(request.env.context['uid']) + company = user.sudo(user.id).company_id + else: + company = request.env['res.company'].search([], limit=1) + favicon = company.favicon_backend + favicon_mimetype = company.favicon_backend_mimetype + if not favicon: + favicon = file_open('web/static/src/img/favicon.ico') + favicon_mimetype = 'image/x-icon' + else: + favicon = StringIO.StringIO(base64.b64decode(favicon)) + return request.make_response( + favicon.read(), [('Content-Type', favicon_mimetype)]) diff --git a/web_favicon/models/__init__.py b/web_favicon/models/__init__.py new file mode 100644 index 00000000..6c860e44 --- /dev/null +++ b/web_favicon/models/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import res_company diff --git a/web_favicon/models/res_company.py b/web_favicon/models/res_company.py new file mode 100644 index 00000000..6f54bb46 --- /dev/null +++ b/web_favicon/models/res_company.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp import models, fields + + +class ResCompany(models.Model): + _inherit = 'res.company' + + favicon_backend = fields.Binary() + favicon_backend_mimetype = fields.Char( + help='Set the mimetype of your file. Usually, that\'s one of\n' + 'image/x-icon, image/gif, image/png') diff --git a/web_favicon/static/description/icon.png b/web_favicon/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/web_favicon/static/description/icon.png differ diff --git a/web_favicon/tests/__init__.py b/web_favicon/tests/__init__.py new file mode 100644 index 00000000..15f22fca --- /dev/null +++ b/web_favicon/tests/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import test_web_favicon diff --git a/web_favicon/tests/test_web_favicon.py b/web_favicon/tests/test_web_favicon.py new file mode 100644 index 00000000..0301639c --- /dev/null +++ b/web_favicon/tests/test_web_favicon.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import base64 +from openerp.tests.common import TransactionCase +from openerp.tools.misc import file_open +from openerp import http + + +class FakeRequest(object): + def __init__(self, env): + self.env = env + + def make_response(self, data, headers): + return FakeResponse(data, headers) + + +class FakeResponse(object): + def __init__(self, data, headers): + self.data = data + self.headers = dict(headers) + + +class TestWebFavicon(TransactionCase): + def test_web_favicon(self): + original_request = http.request + http.request = FakeRequest(self.env) + from openerp.addons.web_favicon.controllers.web_favicon import\ + WebFavicon + company = self.env['res.company'].search([], limit=1) + # default icon + company.write({ + 'favicon_backend': False, + 'favicon_backend_mimetype': False, + }) + data = WebFavicon().icon() + self.assertEqual(data.headers['Content-Type'], 'image/x-icon') + # our own icon + company.write({ + 'favicon_backend': base64.b64encode(file_open( + 'web_favicon/static/description/icon.png').read()), + 'favicon_backend_mimetype': 'image/png', + }) + data = WebFavicon().icon() + self.assertEqual(data.headers['Content-Type'], + company.favicon_backend_mimetype) + http.request = original_request diff --git a/web_favicon/views/res_company.xml b/web_favicon/views/res_company.xml new file mode 100644 index 00000000..fa06e47d --- /dev/null +++ b/web_favicon/views/res_company.xml @@ -0,0 +1,17 @@ + + + + + res.company + + + + + + + + + + + + diff --git a/web_favicon/views/templates.xml b/web_favicon/views/templates.xml new file mode 100644 index 00000000..ed80510a --- /dev/null +++ b/web_favicon/views/templates.xml @@ -0,0 +1,10 @@ + + + + + +