Browse Source

Module 'auditlog' - 'display_name' fields added for the user session and HTTP requests models

pull/707/head
sebalix 9 years ago
committed by Frédéric Garbely
parent
commit
54edaafc68
  1. 12
      auditlog/models/http_request.py
  2. 12
      auditlog/models/http_session.py
  3. 6
      auditlog/views/http_request_view.xml
  4. 4
      auditlog/views/http_session_view.xml

12
auditlog/models/http_request.py

@ -27,7 +27,9 @@ class AuditlogHTTPRequest(models.Model):
_name = 'auditlog.http.request' _name = 'auditlog.http.request'
_description = u"Auditlog - HTTP request log" _description = u"Auditlog - HTTP request log"
_order = "create_date DESC" _order = "create_date DESC"
_rec_name = 'display_name'
display_name = fields.Char(u"Name", compute="_display_name")
name = fields.Char(u"Path") name = fields.Char(u"Path")
root_url = fields.Char(u"Root URL") root_url = fields.Char(u"Root URL")
user_id = fields.Many2one( user_id = fields.Many2one(
@ -38,6 +40,16 @@ class AuditlogHTTPRequest(models.Model):
log_ids = fields.One2many( log_ids = fields.One2many(
'auditlog.log', 'http_request_id', string=u"Logs") '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 @api.model
def current_http_request(self): def current_http_request(self):
"""Create a log corresponding to the current HTTP request, and returns """Create a log corresponding to the current HTTP request, and returns

12
auditlog/models/http_session.py

@ -27,13 +27,25 @@ class AuditlogtHTTPSession(models.Model):
_name = 'auditlog.http.session' _name = 'auditlog.http.session'
_description = u"Auditlog - HTTP User session log" _description = u"Auditlog - HTTP User session log"
_order = "create_date DESC" _order = "create_date DESC"
_rec_name = 'display_name'
display_name = fields.Char(u"Name", compute="_display_name")
name = fields.Char(u"Session ID") name = fields.Char(u"Session ID")
user_id = fields.Many2one( user_id = fields.Many2one(
'res.users', string=u"User") 'res.users', string=u"User")
http_request_ids = fields.One2many( http_request_ids = fields.One2many(
'auditlog.http.request', 'http_session_id', string=u"HTTP Requests") '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 @api.model
def current_http_session(self): def current_http_session(self):
"""Create a log corresponding to the current HTTP user session, and """Create a log corresponding to the current HTTP user session, and

6
auditlog/views/http_request_view.xml

@ -12,11 +12,8 @@
<field name="root_url"/> <field name="root_url"/>
<field name="name"/> <field name="name"/>
<field name="create_date"/> <field name="create_date"/>
</group>
<group string="User session">
<field name="user_id"/>
<field name="http_session_id"/>
<field name="user_context"/> <field name="user_context"/>
<field name="http_session_id"/>
</group> </group>
<group string="Logs"> <group string="Logs">
<field name="log_ids" nolabel="1"/> <field name="log_ids" nolabel="1"/>
@ -33,7 +30,6 @@
<tree string="HTTP Requests"> <tree string="HTTP Requests">
<field name="name"/> <field name="name"/>
<field name="create_date"/> <field name="create_date"/>
<field name="user_id"/>
<field name="http_session_id"/> <field name="http_session_id"/>
</tree> </tree>
</field> </field>

4
auditlog/views/http_session_view.xml

@ -10,8 +10,8 @@
<sheet> <sheet>
<group string="User session"> <group string="User session">
<field name="user_id"/> <field name="user_id"/>
<field name="name"/>
<field name="create_date"/> <field name="create_date"/>
<field name="name"/>
</group> </group>
<group string="HTTP Requests"> <group string="HTTP Requests">
<field name="http_request_ids" nolabel="1"/> <field name="http_request_ids" nolabel="1"/>
@ -27,8 +27,8 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="User sessions"> <tree string="User sessions">
<field name="user_id"/> <field name="user_id"/>
<field name="name"/>
<field name="create_date"/> <field name="create_date"/>
<field name="name"/>
</tree> </tree>
</field> </field>
</record> </record>

Loading…
Cancel
Save