diff --git a/website_catch_500/models/ir_http.py b/website_catch_500/models/ir_http.py
index 965feadf..9349d571 100644
--- a/website_catch_500/models/ir_http.py
+++ b/website_catch_500/models/ir_http.py
@@ -10,7 +10,6 @@ class HttpInherit(models.AbstractModel):
@classmethod
def _get_error_html(cls, env, code, values):
if code == 500:
- # if code == 500 or code == "page_500"
website = request.website
if website and website.catch_500_errors:
website._catch_500_error(request.httprequest)
diff --git a/website_catch_500/models/website.py b/website_catch_500/models/website.py
index c67b748f..15eda61d 100644
--- a/website_catch_500/models/website.py
+++ b/website_catch_500/models/website.py
@@ -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"
@@ -33,23 +15,32 @@ class Website(models.Model):
)
def _catch_500_error(self, request):
- url = remove_domain_and_protocol(request.url)
+ url = request.url
+ form_data_str = "\n".join("%s: %s" % (k,v) for k,v in dict(request.form).items())
request_method = request.method
website_id = self.id
error = (
self.env["website.500.errors"]
.sudo()
- .search([("name", "=", url), ("website_id", "=", website_id)])
+ .search(
+ [
+ ("url", "=", url),
+ ("website_id", "=", website_id),
+ ("form_data", "=", form_data_str or ""),
+ ]
+ )
)
+
if error:
error.hit_count += 1
else:
self.env["website.500.errors"].sudo().create(
{
- "name": url,
+ "url": url,
"request_method": request_method,
"hit_count": 1,
"website_id": website_id,
+ "form_data": form_data_str or "",
}
)
self.env.cr.commit()
diff --git a/website_catch_500/models/website_500_errors.py b/website_catch_500/models/website_500_errors.py
index 8e52dd56..6f1dc80e 100644
--- a/website_catch_500/models/website_500_errors.py
+++ b/website_catch_500/models/website_500_errors.py
@@ -7,8 +7,9 @@
class Website500Errors(models.Model):
_name = "website.500.errors"
_description = "Base Model for Website 500 Errors"
+ _rec_name = "url"
- name = fields.Char(string="URL")
+ url = fields.Char(string="URL")
request_method = fields.Selection(
selection=[
("GET", "GET"),
@@ -21,6 +22,7 @@ class Website500Errors(models.Model):
],
string="Request Method",
)
+ form_data = fields.Text(string="Form Data")
hit_count = fields.Integer(string="Hit Count")
website_id = fields.Many2one(
comodel_name="website",
@@ -28,8 +30,3 @@ class Website500Errors(models.Model):
ondelete="cascade",
)
- @api.constrains("url")
- def _check_url(self):
- for record in self:
- if self.search_count([("name", "=", record.name)]) > 1:
- raise ValidationError("URL must be unique.")
diff --git a/website_catch_500/views/website_500_errors_views.xml b/website_catch_500/views/website_500_errors_views.xml
index 73fff738..abda2269 100644
--- a/website_catch_500/views/website_500_errors_views.xml
+++ b/website_catch_500/views/website_500_errors_views.xml
@@ -5,10 +5,11 @@