From a89f278f12347cb516df9182f48dbbcb141052a0 Mon Sep 17 00:00:00 2001 From: sebalix Date: Sat, 31 Oct 2015 11:39:18 +0100 Subject: [PATCH] [FIX] Module 'auditlog' - 'display_name' fields added for the user session and HTTP requests models --- auditlog/models/http_request.py | 12 ++++++++++++ auditlog/models/http_session.py | 12 ++++++++++++ auditlog/views/http_request_view.xml | 6 +----- auditlog/views/http_session_view.xml | 4 ++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/auditlog/models/http_request.py b/auditlog/models/http_request.py index 77f9aa09f..7d6b19d48 100644 --- a/auditlog/models/http_request.py +++ b/auditlog/models/http_request.py @@ -27,7 +27,9 @@ class AuditlogHTTPRequest(models.Model): _name = 'auditlog.http.request' _description = u"Auditlog - HTTP request log" _order = "create_date DESC" + _rec_name = 'display_name' + display_name = fields.Char(u"Name", compute="_display_name") name = fields.Char(u"Path") root_url = fields.Char(u"Root URL") user_id = fields.Many2one( @@ -38,6 +40,16 @@ class AuditlogHTTPRequest(models.Model): log_ids = fields.One2many( 'auditlog.log', 'http_request_id', string=u"Logs") + @api.multi + def _display_name(self): + for httprequest in self: + create_date = fields.Datetime.from_string(httprequest.create_date) + tz_create_date = fields.Datetime.context_timestamp( + httprequest, create_date) + httprequest.display_name = u"%s (%s)" % ( + httprequest.name or '?', + fields.Datetime.to_string(tz_create_date)) + @api.model def current_http_request(self): """Create a log corresponding to the current HTTP request, and returns diff --git a/auditlog/models/http_session.py b/auditlog/models/http_session.py index 2bbf736e6..046a10fa7 100644 --- a/auditlog/models/http_session.py +++ b/auditlog/models/http_session.py @@ -27,13 +27,25 @@ class AuditlogtHTTPSession(models.Model): _name = 'auditlog.http.session' _description = u"Auditlog - HTTP User session log" _order = "create_date DESC" + _rec_name = 'display_name' + display_name = fields.Char(u"Name", compute="_display_name") name = fields.Char(u"Session ID") user_id = fields.Many2one( 'res.users', string=u"User") http_request_ids = fields.One2many( 'auditlog.http.request', 'http_session_id', string=u"HTTP Requests") + @api.multi + def _display_name(self): + for httpsession in self: + create_date = fields.Datetime.from_string(httpsession.create_date) + tz_create_date = fields.Datetime.context_timestamp( + httpsession, create_date) + httpsession.display_name = u"%s (%s)" % ( + httpsession.user_id and httpsession.user_id.name or '?', + fields.Datetime.to_string(tz_create_date)) + @api.model def current_http_session(self): """Create a log corresponding to the current HTTP user session, and diff --git a/auditlog/views/http_request_view.xml b/auditlog/views/http_request_view.xml index 0011eb55d..2169ed0f9 100644 --- a/auditlog/views/http_request_view.xml +++ b/auditlog/views/http_request_view.xml @@ -12,11 +12,8 @@ - - - - + @@ -33,7 +30,6 @@ - diff --git a/auditlog/views/http_session_view.xml b/auditlog/views/http_session_view.xml index 4fc2e3bdc..942da68af 100644 --- a/auditlog/views/http_session_view.xml +++ b/auditlog/views/http_session_view.xml @@ -10,8 +10,8 @@ - + @@ -27,8 +27,8 @@ - +