[IMP] make res.log persistent objects
bzr revid: xmo@openerp.com-20101012171515-55e0mj6o4w632vu1
This commit is contained in:
@@ -23,7 +23,7 @@ from osv import fields, osv
|
||||
import tools
|
||||
import time
|
||||
|
||||
class res_log(osv.osv_memory):
|
||||
class res_log(osv.osv):
|
||||
_name = 'res.log'
|
||||
_columns = {
|
||||
'name': fields.char('Message', size=128, help='The logging message.', required=True),
|
||||
@@ -33,20 +33,34 @@ class res_log(osv.osv_memory):
|
||||
'res_id': fields.integer('Object ID'),
|
||||
'secondary': fields.boolean('Secondary Log', help='Do not display this log if it belongs to the same object the user is working on'),
|
||||
'create_date': fields.datetime('Created Date', readonly=True),
|
||||
'read': fields.boolean('Read', help="If this log item has been read, get() should not send it to the client")
|
||||
}
|
||||
_defaults = {
|
||||
'user_id': lambda self,cr,uid,ctx: uid,
|
||||
'create_date': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'context': lambda *args: "{}"
|
||||
'context': "{}",
|
||||
'read': False
|
||||
}
|
||||
_order='create_date desc'
|
||||
|
||||
_index_name = 'res_log_uid_read'
|
||||
def _auto_init(self, cr, context={}):
|
||||
super(res_log, self)._auto_init(cr, context)
|
||||
cr.execute('SELECT 1 FROM pg_indexes WHERE indexname=%s',
|
||||
(self._index_name,))
|
||||
if not cr.fetchone():
|
||||
cr.execute('CREATE INDEX %s ON res_log (user_id, read)' %
|
||||
self._index_name)
|
||||
|
||||
# TODO: do not return secondary log if same object than in the model (but unlink it)
|
||||
def get(self, cr, uid, context={}):
|
||||
ids = self.search(cr, uid, [('user_id','=',uid)], context=context)
|
||||
result = self.read(cr, uid, ids, ['name','res_model','res_id'], context=context)
|
||||
self.unlink(cr, uid, ids, context=context)
|
||||
return result
|
||||
def get(self, cr, uid, context=None):
|
||||
unread_log_ids = self.search(cr, uid, [('user_id','=',uid),
|
||||
('read', '=', False)],
|
||||
context=context)
|
||||
unread_logs = self.read(cr, uid, unread_log_ids,
|
||||
['name','res_model','res_id'],
|
||||
context=context)
|
||||
self.write(cr, uid, unread_log_ids, {'read': True}, context=context)
|
||||
return unread_logs
|
||||
|
||||
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
|
||||
res = []
|
||||
@@ -58,6 +72,4 @@ class res_log(osv.osv_memory):
|
||||
logs.update({log.res_model: res_dict})
|
||||
res = map(lambda x: x.values(), logs.values())
|
||||
return tools.flatten(res)
|
||||
|
||||
res_log()
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<field name="user_id"/>
|
||||
<field name="res_model"/>
|
||||
<field name="create_date"/>
|
||||
<field name="read"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
@@ -22,9 +23,10 @@
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Logs">
|
||||
<field name="create_date"/>
|
||||
<field name="name"/>
|
||||
<field name="create_date"/>
|
||||
<field name="user_id"/>
|
||||
<field name="read"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -34,8 +36,11 @@
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Logs">
|
||||
<group colspan="4" col="6">
|
||||
<field name="name"/>
|
||||
<field name="create_date"/>
|
||||
<field name="read" readonly="1"/>
|
||||
</group>
|
||||
<group colspan="4" col="6">
|
||||
<field name="user_id" />
|
||||
<field name="res_model"/>
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
# size
|
||||
#
|
||||
from collections import defaultdict
|
||||
import datetime as DT
|
||||
import string
|
||||
import netsvc
|
||||
import sys
|
||||
@@ -189,14 +190,42 @@ class float(_column):
|
||||
|
||||
class date(_column):
|
||||
_type = 'date'
|
||||
@staticmethod
|
||||
def today(*args):
|
||||
""" Returns the current date in a format fit for being a
|
||||
default value to a ``date`` field.
|
||||
|
||||
This method should be provided as is to the _defaults dict, it
|
||||
should not be called.
|
||||
"""
|
||||
return DT.date.today().strftime(
|
||||
tools.DEFAULT_SERVER_DATE_FORMAT)
|
||||
|
||||
class datetime(_column):
|
||||
_type = 'datetime'
|
||||
@staticmethod
|
||||
def now(*args):
|
||||
""" Returns the current datetime in a format fit for being a
|
||||
default value to a ``datetime`` field.
|
||||
|
||||
This method should be provided as is to the _defaults dict, it
|
||||
should not be called.
|
||||
"""
|
||||
return DT.datetime.now().strftime(
|
||||
tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
|
||||
class time(_column):
|
||||
_type = 'time'
|
||||
@staticmethod
|
||||
def now( *args):
|
||||
""" Returns the current time in a format fit for being a
|
||||
default value to a ``time`` field.
|
||||
|
||||
This method should be proivided as is to the _defaults dict,
|
||||
it should not be called.
|
||||
"""
|
||||
return DT.datetime.now().strftime(
|
||||
tools.DEFAULT_SERVER_TIME_FORMAT)
|
||||
|
||||
class binary(_column):
|
||||
_type = 'binary'
|
||||
|
||||
+4
-1
@@ -1323,7 +1323,10 @@ def get_server_timezone():
|
||||
|
||||
|
||||
DEFAULT_SERVER_DATE_FORMAT = "%Y-%m-%d"
|
||||
DEFAULT_SERVER_DATETIME_FORMAT = DEFAULT_SERVER_DATE_FORMAT + " %H:%M:%S"
|
||||
DEFAULT_SERVER_TIME_FORMAT = "%H:%M:%S"
|
||||
DEFAULT_SERVER_DATETIME_FORMAT = "%s %s" % (
|
||||
DEFAULT_SERVER_DATE_FORMAT,
|
||||
DEFAULT_SERVER_TIME_FORMAT)
|
||||
|
||||
def server_to_local_timestamp(src_tstamp_str, src_format, dst_format, dst_tz_name,
|
||||
tz_offset=True, ignore_unparsable_time=True):
|
||||
|
||||
Reference in New Issue
Block a user