Skip to content

Commit

Permalink
rest_log: store collection ID when available
Browse files Browse the repository at this point in the history
Allows to filter on specific collections record when possible.
  • Loading branch information
simahawk committed May 13, 2022
1 parent 9d04d4e commit b019557
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rest_log/components/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ def _log_call_in_db_values(self, _request, *args, params=None, **kw):
if hasattr(orig_exception, "__module__"):
exception_name = orig_exception.__module__ + "." + exception_name
exception_message = self._get_exception_message(orig_exception)
collection = self.work.collection
return {
"collection": self._collection,
"collection": collection._name,
"collection_id": collection.id,
"request_url": httprequest.url,
"request_method": httprequest.method,
"params": json_dump(params),
Expand Down
17 changes: 17 additions & 0 deletions rest_log/models/rest_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class RESTLog(models.Model):
}

collection = fields.Char(index=True)
collection_id = fields.Integer(index=True, string="Collection ID")
request_url = fields.Char(readonly=True, string="Request URL")
request_method = fields.Char(readonly=True)
params = fields.Text(readonly=True)
Expand Down Expand Up @@ -177,3 +178,19 @@ def _get_matching_active_conf(self, collection, usage, method_name):
for candidate in candidates:
if conf.get(candidate):
return conf.get(candidate)

def action_view_collection(self):
"""Open collection if we have a real record.
NOTE: use an action instead of a `Reference` field with computed method
because it would force use to have glue modules to provide a selection
for every model we want to support.
"""
# TODO: on the next round, compute the collection name
# to be used for the button label.
# No ID or no real model
if self.collection not in self.env or not self.collection_id:
return
action = self.env[self.collection].get_formview_action()
action["res_id"] = self.collection_id
return action
17 changes: 17 additions & 0 deletions rest_log/views/rest_log_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<field name="arch" type="xml">
<tree decoration-danger="state == 'failed'">
<field name="collection" optional="hide" />
<field name="collection_id" optional="hide" />
<field name="create_uid" />
<field name="create_date" />
<field name="request_method" />
Expand All @@ -22,10 +23,25 @@
<field name="model">rest.log</field>
<field name="arch" type="xml">
<form>
<field name="collection_id" invisible="1" />
<header>
<field name="state" widget="statusbar" />
</header>
<sheet>
<div
class="oe_button_box"
name="button_box"
attrs="{'invisible': ['|', ('id','=',False), ('collection_id', '=', False)]}"
>
<button
type="object"
name="action_view_collection"
icon="fa-eye"
attrs="{'invisible': [('collection_id', '=', False)]}"
>
View collection
</button>
</div>
<group>
<group>
<field name="collection" />
Expand Down Expand Up @@ -79,6 +95,7 @@
<field name="arch" type="xml">
<search>
<field name="collection" />
<field name="collection_id" />
<field name="state" />
<field name="request_url" />
<field name="request_method" />
Expand Down

0 comments on commit b019557

Please sign in to comment.