You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.5 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Guewen Baconnier
  5. # Copyright 2011-2012 Camptocamp SA
  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 osv import fields, osv
  22. from server_environment import serv_config
  23. import logging
  24. class external_referential(osv.osv):
  25. _inherit = 'external.referential'
  26. def _get_environment_config_by_name(self, cr, uid, ids, field_names, arg,
  27. context):
  28. values = {}
  29. for referential in self.browse(cr, uid, ids, context):
  30. values[referential.id] = {}
  31. for field_name in field_names:
  32. section_name = '.'.join((self._name.replace('.', '_'),
  33. referential.name))
  34. try:
  35. value = serv_config.get(section_name, field_name)
  36. values[referential.id].update({field_name: value})
  37. except:
  38. logger = logging.getLogger(__name__)
  39. logger.exception(
  40. 'error trying to read field %s in section %s',
  41. field_name, section_name)
  42. return values
  43. _columns = {
  44. 'location': fields.function(
  45. _get_environment_config_by_name, type='char', size=200,
  46. method=True, string='Location', multi='connection_config'),
  47. 'apiusername': fields.function(
  48. _get_environment_config_by_name, type='char', size=64,
  49. method=True, string='User Name', multi='connection_config'),
  50. 'apipass': fields.function(
  51. _get_environment_config_by_name, type='char', size=64,
  52. method=True, string='Password', multi='connection_config'),
  53. }
  54. external_referential()