Skip to content

Commit

Permalink
[16.0][IMP] Improvements about conciseness in code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
milleniumkid committed Dec 13, 2024
1 parent 945ba34 commit 03fe249
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
4 changes: 2 additions & 2 deletions website_catch_500/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class HttpInherit(models.AbstractModel):

@classmethod
def _get_error_html(cls, env, code, values):
if code == 500:
# if code == 500 or code == "page_500"
if code == 500 or code == "page_500":
# if code == 500 or code == "page_500"
website = request.website
if website and website.catch_500_errors:
website._catch_500_error(request.httprequest)
Expand Down
31 changes: 11 additions & 20 deletions website_catch_500/models/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,6 @@
from urllib.parse import urlparse, urlunparse


def remove_domain_and_protocol(url):
"""
Removes domain and protocol from the url.
"""
parsed_url = urlparse(url)
modified_url = urlunparse(
(
"",
"",
parsed_url.path,
parsed_url.params,
parsed_url.query,
parsed_url.fragment,
)
)
return modified_url


class Website(models.Model):
_inherit = "website"

Expand All @@ -33,14 +15,22 @@ class Website(models.Model):
)

def _catch_500_error(self, request):
url = remove_domain_and_protocol(request.url)
url = request.url
http_param = request.query_string
request_method = request.method
website_id = self.id
error = (
self.env["website.500.errors"]
.sudo()
.search([("name", "=", url), ("website_id", "=", website_id)])
.search(
[
("name", "=", url),
("website_id", "=", website_id),
("http_param", "=", http_param or ""),
]
)
)

if error:
error.hit_count += 1
else:
Expand All @@ -50,6 +40,7 @@ def _catch_500_error(self, request):
"request_method": request_method,
"hit_count": 1,
"website_id": website_id,
"http_param": http_param or "",
}
)
self.env.cr.commit()
Expand Down
1 change: 1 addition & 0 deletions website_catch_500/models/website_500_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Website500Errors(models.Model):
],
string="Request Method",
)
http_param = fields.Char(string="HTTP Request Param")
hit_count = fields.Integer(string="Hit Count")
website_id = fields.Many2one(
comodel_name="website",
Expand Down
8 changes: 4 additions & 4 deletions website_catch_500/views/website_500_errors_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<field name="model">website.500.errors</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="request_method"/>
<field name="hit_count"/>
<field name="website_id"/>
<field name="http_param"/>
<field name="hit_count"/>
</tree>
</field>
</record>
Expand All @@ -19,10 +19,10 @@
<form string="Website 500 Error">
<sheet>
<group>
<field name="name" readonly="True"/>
<field name="request_method" readonly="True"/>
<field name="hit_count" readonly="True"/>
<field name="website_id" readonly="True"/>
<field name="http_param" readonly="True"/>
<field name="hit_count"/>
</group>
</sheet>
</form>
Expand Down

0 comments on commit 03fe249

Please sign in to comment.