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.

54 lines
2.3 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, context):
  27. values = {}
  28. for referential in self.browse(cr, uid, ids, context):
  29. values[referential.id] = {}
  30. for field_name in field_names:
  31. section_name = '.'.join((self._name.replace('.', '_'), referential.name))
  32. try:
  33. value = serv_config.get(section_name, field_name)
  34. values[referential.id].update({field_name: value})
  35. except:
  36. logger = logging.getLogger(__name__)
  37. logger.exception('error trying to read field %s in section %s', field_name, section_name)
  38. return values
  39. _columns = {
  40. 'location': fields.function(_get_environment_config_by_name, type='char', size=200,
  41. method=True, string='Location', multi='connection_config'),
  42. 'apiusername': fields.function(_get_environment_config_by_name, type='char', size=64,
  43. method=True, string='User Name', multi='connection_config'),
  44. 'apipass': fields.function(_get_environment_config_by_name, type='char', size=64,
  45. method=True, string='Password', multi='connection_config'),
  46. }
  47. external_referential()