[IMP] Improved res_log handling

bzr revid: nicolas.vanhoren@openerp.com-20101123095738-tm5pkm6d81t8i6iv
This commit is contained in:
nvi-openerp 2010-11-23 10:57:38 +01:00
parent e98ba5b6fd
commit ca18012c17
5 changed files with 37 additions and 54 deletions

View File

@ -23,11 +23,22 @@ A module to store some configuration parameters relative to a whole database.
"""
from osv import osv,fields
import uuid
import datetime
from tools import misc
"""
A dictionary holding some configuration parameters to be initialized when the database is created.
"""
_default_parameters = {
"database.uuid": lambda: str(uuid.uuid1()),
"database.create_date": lambda: datetime.datetime.now().strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT),
}
class ir_config_parameter(osv.osv):
""" An osv to old configuration parameters for a given database.
To be short, it's just a global dictionnary of strings stored in a table. """
To be short, it's just a global dictionary of strings stored in a table. """
_name = 'ir.config_parameter'
@ -41,6 +52,15 @@ class ir_config_parameter(osv.osv):
_sql_constraints = [
('key_uniq', 'unique (key)', 'Key must be unique.')
]
def init(self, cr):
"""
Initializes the parameters listed in _default_parameters.
"""
for key, func in _default_parameters.iteritems():
ids = self.search(cr, 1, [('key','=',key)])
if not ids:
self.set_param(cr, 1, key, func())
def get_param(self, cr, uid, key, context=None):
""" Get the value of a parameter.

View File

@ -20,7 +20,6 @@
##############################################################################
import publisher_warranty
import dbuuid
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,45 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
"""
A module to handle a database UUID. That uuid will be stored in the osv
"ir.config_parameter" with key "database.uuid".
"""
from osv import osv
import uuid
class uuid_saver(osv.osv_memory):
""" An empty osv memory to init the uuid of the database the first it is
used. """
_name = 'pw.database_uuid_saver'
def init(self, cr):
""" Checks that the database uuid was already created and create it if
it not the case. """
params = self.pool.get('ir.config_parameter')
uniq = params.get_param(cr, 1, 'database.uuid')
if not uniq:
uniq = str(uuid.uuid1())
params.set_param(cr, 1, 'database.uuid', uniq)
uuid_saver()

View File

@ -31,6 +31,7 @@ from tools.safe_eval import safe_eval
import pooler
from tools.config import config
import release
import datetime
_logger = logging.getLogger(__name__)
@ -71,6 +72,7 @@ class publisher_warranty_contract(osv.osv):
try:
origin = 'client'
dbuuid = self.pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid')
db_create_date = self.pool.get('ir.config_parameter').get_param(cr, uid, 'database.create_date')
msg = {'contract_name': valid_contract.name,
'tb': tb,
@ -78,7 +80,8 @@ class publisher_warranty_contract(osv.osv):
'remarks': remarks,
'origin': origin,
'dbname': cr.dbname,
'dbuuid': dbuuid}
'dbuuid': dbuuid,
'db_create_date': db_create_date}
uo = urllib.urlopen(config.get("publisher_warranty_url"),
urllib.urlencode({'arg0': msg, "action": "send",}))
@ -161,6 +164,7 @@ class publisher_warranty_contract(osv.osv):
{
'name': result["message"],
'res_model': "Maintenance Notifications",
"read": True,
},
context=context
)
@ -172,6 +176,14 @@ class publisher_warranty_contract(osv.osv):
raise
return True
def get_last_user_message(self, cr, uid, context={}):
ids = self.pool.get('res.log').search(cr, uid, [("res_model", "=", "Maintenance Notifications")]
, order="create_date desc", limit=1)
if not ids:
return False
to_return = self.pool.get('res.log').browse(cr, uid, ids[0]).name
return to_return
_columns = {
'name' : fields.char('Contract Name', size=384, required=True),
@ -253,6 +265,7 @@ def send_ping(cr, uid):
pool = pooler.get_pool(cr.dbname)
dbuuid = pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid')
db_create_date = pool.get('ir.config_parameter').get_param(cr, uid, 'database.create_date')
nbr_users = pool.get("res.users").search(cr, uid, [], count=True)
contractosv = pool.get('publisher_warranty.contract')
contracts = contractosv.browse(cr, uid, contractosv.search(cr, uid, []))
@ -260,6 +273,7 @@ def send_ping(cr, uid):
"dbuuid": dbuuid,
"nbr_users": nbr_users,
"dbname": cr.dbname,
"db_create_date": db_create_date,
"version": release.version,
"contracts": [c.name for c in contracts],
}

View File

@ -91,15 +91,10 @@ class configmanager(object):
'static_http_url_prefix': None,
'secure_cert_file': 'server.cert',
'secure_pkey_file': 'server.pkey',
'maintenance_server': 'http://tiny.my.odoo.com:8069/xmlrpc/',
'maintenance_db': 'tiny_belgium',
'maintenance_login': 'maintenance',
'maintenance_password': 'maintenance',
'publisher_warranty_url': 'http://www.openerp.com/publisher-warranty',
}
self.blacklist_for_save = set(['maintenance_server', 'maintenance_db',
'maintenance_login', 'maintenance_password', "publisher_warranty_url"])
self.blacklist_for_save = set(["publisher_warranty_url"])
self.misc = {}
self.config_file = fname