1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2011 OpenERP SA (<http://www.openerp.com>).
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.
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.
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/>.
20 ##############################################################################
22 Store database-specific configuration parameters
25 from osv import osv,fields
28 from tools import misc, config
31 A dictionary holding some configuration parameters to be initialized when the database is created.
33 _default_parameters = {
34 "database.uuid": lambda: str(uuid.uuid1()),
35 "database.create_date": lambda: datetime.datetime.now().strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT),
36 "web.base.url": lambda: "http://localhost:%s" % config.get('xmlrpc_port'),
39 class ir_config_parameter(osv.osv):
40 """Per-database storage of configuration key-value pairs."""
42 _name = 'ir.config_parameter'
45 'key': fields.char('Key', size=256, required=True, select=1),
46 'value': fields.text('Value', required=True),
50 ('key_uniq', 'unique (key)', 'Key must be unique.')
55 Initializes the parameters listed in _default_parameters.
57 for key, func in _default_parameters.iteritems():
58 ids = self.search(cr, 1, [('key','=',key)])
60 self.set_param(cr, 1, key, func())
62 def get_param(self, cr, uid, key, default=False, context=None):
63 """Retrieve the value for a given key.
65 :param string key: The key of the parameter value to retrieve.
66 :param string default: default value if parameter is missing.
67 :return: The value of the parameter, or ``default`` if it does not exist.
70 ids = self.search(cr, uid, [('key','=',key)], context=context)
73 param = self.browse(cr, uid, ids[0], context=context)
77 def set_param(self, cr, uid, key, value, context=None):
78 """Sets the value of a parameter.
80 :param string key: The key of the parameter value to set.
81 :param string value: The value to set.
82 :return: the previous value of the parameter or False if it did
86 ids = self.search(cr, uid, [('key','=',key)], context=context)
88 param = self.browse(cr, uid, ids[0], context=context)
90 self.write(cr, uid, ids, {'value': value}, context=context)
93 self.create(cr, uid, {'key': key, 'value': value}, context=context)
96 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: