partner_social_extends.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import osv, fields
  22. class res_partner(osv.osv):
  23. _name = 'res.partner'
  24. _inherit = 'res.partner'
  25. _columns = {
  26. 'instagram':fields.char('Instagram', size=64),
  27. 'linkedin':fields.char('LinkedIn', size=64),
  28. }
  29. def goto_instagram(self, cr, uid, ids, context=None):
  30. partner_obj = self.pool.get('res.partner')
  31. partner = partner_obj.browse(cr, uid, ids, context=context)[0]
  32. if partner.instagram:
  33. good_starting_urls = ['https://instagram.com/', 'https://www.instagram.com/', \
  34. 'http://instagram.com/', 'http://www.instagram.com/']
  35. non_protocol_starting_urls = ['instagram.com/', 'www.instagram.com/']
  36. if any(map(lambda x: partner.instagram.startswith(x), good_starting_urls)):
  37. url = partner.instagram
  38. elif any(map(lambda x: partner.instagram.startswith(x), non_protocol_starting_urls)):
  39. url = 'https://' + partner.instagram
  40. else:
  41. url = 'https://www.instagram.com/' + partner.instagram
  42. return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'}
  43. def goto_linkedin(self, cr, uid, ids, context=None):
  44. partner_obj = self.pool.get('res.partner')
  45. partner = partner_obj.browse(cr, uid, ids, context=context)[0]
  46. if partner.linkedin:
  47. good_starting_urls = ['https://linkedin.com/', 'https://www.linkedin.com/', \
  48. 'http://linkedin.com/', 'http://www.linkedin.com/']
  49. non_protocol_starting_urls = ['linkedin.com/', 'www.linkedin.com/']
  50. if any(map(lambda x: partner.linkedin.startswith(x), good_starting_urls)):
  51. url = partner.linkedin
  52. elif any(map(lambda x: partner.linkedin.startswith(x), non_protocol_starting_urls)):
  53. url = 'https://' + partner.linkedin
  54. else:
  55. url = 'https://www.linkedin.com/' + partner.linkedin
  56. return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'}