diff --git a/res_users_with_gravatar/README.rst b/res_users_with_gravatar/README.rst new file mode 100644 index 000000000..ad13f8117 --- /dev/null +++ b/res_users_with_gravatar/README.rst @@ -0,0 +1,33 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Synchronize Gravatar image +========================== + +Use you Gravatar image in to your Odoo + + +License +======= + +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 . + + +Credits +======= + +Contributors +------------ + +* Endika Iglesias diff --git a/res_users_with_gravatar/__init__.py b/res_users_with_gravatar/__init__.py new file mode 100644 index 000000000..054c8853d --- /dev/null +++ b/res_users_with_gravatar/__init__.py @@ -0,0 +1,6 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from . import models diff --git a/res_users_with_gravatar/__openerp__.py b/res_users_with_gravatar/__openerp__.py new file mode 100644 index 000000000..cac8e92e7 --- /dev/null +++ b/res_users_with_gravatar/__openerp__.py @@ -0,0 +1,34 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright : +# Endika Iglesias +# +# 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': 'Synchronize Gravatar image', + 'version': '1', + 'author': 'Endika Iglesias', + 'category': 'Tools', + 'website': 'http://www.endikaiglesias.com', + 'depends': ['base'], + 'data': [ + 'views/res_users_view.xml', + ], + 'installable': True, +} diff --git a/res_users_with_gravatar/i18n/es.po b/res_users_with_gravatar/i18n/es.po new file mode 100644 index 000000000..c99a1e31a --- /dev/null +++ b/res_users_with_gravatar/i18n/es.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * res_users_with_gravatar +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-09-18 10:53+0000\n" +"PO-Revision-Date: 2015-09-18 10:53+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: res_users_with_gravatar +#: view:res.users:res_users_with_gravatar.view_users_form_gravatar +#: view:res.users:res_users_with_gravatar.view_users_form_simple_modif_gravatar +msgid "Get Gravatar image" +msgstr "Obtener imagen de Gravatar" + +#. module: res_users_with_gravatar +#: code:addons/res_users_with_gravatar/models/res_users.py:25 +#, python-format +msgid "Sorry Gravatar not found." +msgstr "Lo siento, Gravatar no funciona." + +#. module: res_users_with_gravatar +#: model:ir.model,name:res_users_with_gravatar.model_res_users +msgid "Users" +msgstr "Usuarios" + +#. module: res_users_with_gravatar +#: code:addons/res_users_with_gravatar/models/res_users.py:36 +#, python-format +msgid "You don't have Gravatar image to this %s email." +msgstr "No tiene imagen de Gravatar para este %s email." + diff --git a/res_users_with_gravatar/i18n/res_users_with_gravatar.pot b/res_users_with_gravatar/i18n/res_users_with_gravatar.pot new file mode 100644 index 000000000..59a83f6dc --- /dev/null +++ b/res_users_with_gravatar/i18n/res_users_with_gravatar.pot @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * res_users_with_gravatar +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-09-18 10:53+0000\n" +"PO-Revision-Date: 2015-09-18 10:53+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: res_users_with_gravatar +#: view:res.users:res_users_with_gravatar.view_users_form_gravatar +#: view:res.users:res_users_with_gravatar.view_users_form_simple_modif_gravatar +msgid "Get Gravatar image" +msgstr "" + +#. module: res_users_with_gravatar +#: code:addons/res_users_with_gravatar/models/res_users.py:25 +#, python-format +msgid "Sorry Gravatar not found." +msgstr "" + +#. module: res_users_with_gravatar +#: model:ir.model,name:res_users_with_gravatar.model_res_users +msgid "Users" +msgstr "" + +#. module: res_users_with_gravatar +#: code:addons/res_users_with_gravatar/models/res_users.py:36 +#, python-format +msgid "You don't have Gravatar image to this %s email." +msgstr "" + diff --git a/res_users_with_gravatar/models/__init__.py b/res_users_with_gravatar/models/__init__.py new file mode 100644 index 000000000..b7b7a6689 --- /dev/null +++ b/res_users_with_gravatar/models/__init__.py @@ -0,0 +1,6 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from . import res_users diff --git a/res_users_with_gravatar/models/res_users.py b/res_users_with_gravatar/models/res_users.py new file mode 100644 index 000000000..12c2bdfb5 --- /dev/null +++ b/res_users_with_gravatar/models/res_users.py @@ -0,0 +1,38 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from openerp import models, api +from openerp.exceptions import Warning +from openerp.tools.translate import _ +import base64 +import hashlib +import urllib2 + + +class ResUsers(models.Model): + _inherit = 'res.users' + + def _get_gravatar_base64(self, email=''): + url = 'http://www.gravatar.com/avatar/{}?s=200' + _hash = hashlib.md5(email).hexdigest() + try: + res = urllib2.urlopen(url.format(_hash)) + raw_image = res.read() + return base64.encodestring(raw_image) + except urllib2.HTTPError: + raise Warning(_('Sorry Gravatar not found.')) + + @api.one + def get_gravatar_image(self): + email = str(self.email) or '' + fail_example = self._get_gravatar_base64('fail@email.gravatar') + user_gravatar = self._get_gravatar_base64(email) + if fail_example != user_gravatar: + self.write({'image': user_gravatar}) + else: + raise Warning( + _("You don't have Gravatar image to this %s email." % ( + email))) + return True diff --git a/res_users_with_gravatar/static/description/icon.png b/res_users_with_gravatar/static/description/icon.png new file mode 100644 index 000000000..871a69c18 Binary files /dev/null and b/res_users_with_gravatar/static/description/icon.png differ diff --git a/res_users_with_gravatar/views/res_users_view.xml b/res_users_with_gravatar/views/res_users_view.xml new file mode 100644 index 000000000..5687268f2 --- /dev/null +++ b/res_users_with_gravatar/views/res_users_view.xml @@ -0,0 +1,28 @@ + + + + + + res.users.form.gravatar + res.users + + + +