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.

53 lines
1.8 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2009 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. import simplejson
  22. import openerp
  23. from openerp.models import FIELDS_TO_PGTYPES
  24. from openerp.osv.fields import _column
  25. # ---------------------------------------------------------
  26. # Serialized fields
  27. # ---------------------------------------------------------
  28. class serialized(_column):
  29. """ A field able to store an arbitrary python data structure.
  30. Note: only plain components allowed.
  31. """
  32. def _symbol_set_struct(val):
  33. return simplejson.dumps(val)
  34. def _symbol_get_struct(self, val):
  35. return simplejson.loads(val or '{}')
  36. _prefetch = False
  37. _type = 'serialized'
  38. _symbol_c = '%s'
  39. _symbol_f = _symbol_set_struct
  40. _symbol_set = (_symbol_c, _symbol_f)
  41. _symbol_get = _symbol_get_struct
  42. openerp.osv.fields.serialized = serialized
  43. FIELDS_TO_PGTYPES[openerp.osv.fields.serialized] = 'text'