From c4c879a054602dd4a65c46018b70db88afd53a81 Mon Sep 17 00:00:00 2001
From: Ismail Cagan Yilmaz
Date: Mon, 6 Jan 2025 16:36:47 +0300
Subject: [PATCH] [FIX] Adapted to pre-commit
---
short_url_yourls/__manifest__.py | 4 +-
short_url_yourls/models/short_url_yourls.py | 38 +++++++++++--------
short_url_yourls/security/ir.model.access.csv | 2 +-
.../view/short_url_yourls_view.xml | 26 +++++++------
4 files changed, 40 insertions(+), 30 deletions(-)
diff --git a/short_url_yourls/__manifest__.py b/short_url_yourls/__manifest__.py
index 92c880298..e4524e0b0 100644
--- a/short_url_yourls/__manifest__.py
+++ b/short_url_yourls/__manifest__.py
@@ -10,8 +10,8 @@
"version": "16.0.1.0.0",
"development_status": "Mature",
"category": "Tools",
- "website": "https://github.com/yibudak",
- "author": "Yiğit Budak",
+ "website": "https://github.com/altinkaya-opensource/odoo-addons",
+ "author": "Yiğit Budak, Altinkaya Enclosures",
"license": "LGPL-3",
"application": False,
"installable": True,
diff --git a/short_url_yourls/models/short_url_yourls.py b/short_url_yourls/models/short_url_yourls.py
index 2db74594a..05e34ba8c 100644
--- a/short_url_yourls/models/short_url_yourls.py
+++ b/short_url_yourls/models/short_url_yourls.py
@@ -4,20 +4,27 @@
# Copyright 2024 Ismail Cagan Yilmaz (https://github.com/milleniumkid)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
-from odoo import models, fields, api, _
-from odoo.exceptions import ValidationError
-import requests
-import re
import logging
+import re
+
+import requests
+
+from odoo import _, api, fields, models
+from odoo.exceptions import ValidationError
_logger = logging.getLogger(__name__)
http_regex = re.compile(
- r"^(?:http|ftp)s?://" # http:// or https://
- r"(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|" # domain...
- r"localhost|" # localhost...
- r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})" # ...or ip
- r"(?::\d+)?" # optional port
+ # http:// or https://
+ r"^(?:http|ftp)s?://"
+ # domain...
+ r"(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|"
+ # localhost...
+ r"localhost|"
+ # ...or ip
+ r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
+ # optional port
+ r"(?::\d+)?"
r"(?:/?|[/?]\S+)$",
re.IGNORECASE,
)
@@ -39,10 +46,10 @@ def _compute_total_shortened_urls(self):
if record.shortened_urls:
record.total_shortened_urls = len(record.shortened_urls)
- name = fields.Char(string="Name")
+ name = fields.Char()
hostname = fields.Char(string="URL", required=True, help="Example: https://6sn.de")
- username = fields.Char(string="Username")
- password = fields.Char(string="Password")
+ username = fields.Char()
+ password = fields.Char()
shortened_urls = fields.One2many(
string="Shortened URLs",
comodel_name="short.url.yourls.line",
@@ -55,7 +62,7 @@ def _compute_total_shortened_urls(self):
@api.model
def create(self, vals):
- res = super(ShortURLYourls, self).create(vals)
+ res = super().create(vals)
if re.match(http_regex, res.hostname) is None:
raise ValidationError(
_(
@@ -73,7 +80,7 @@ def shorten_url(self, url):
:return: Shortened URL
"""
line_obj = self.env["short.url.yourls.line"]
- service_url = "%s/yourls-api.php" % self.hostname
+ service_url = f"{'self.hostname'}/yourls-api.php"
vals = {
"username": self.username,
"password": self.password,
@@ -86,7 +93,8 @@ def shorten_url(self, url):
exist_shortened_url = line_obj.search([("long_url", "=", url)], limit=1)
if exist_shortened_url:
return exist_shortened_url.short_url
- retries = 0 # Will attempt to get a response from the server 3 times, if fails then returns False
+ retries = 0 # Will attempt to get a response from the server 3 times,
+ # if it fails, it will return False
is_shortened = False
response = False
while not is_shortened and retries < 3:
diff --git a/short_url_yourls/security/ir.model.access.csv b/short_url_yourls/security/ir.model.access.csv
index 9189e4754..a7861779c 100644
--- a/short_url_yourls/security/ir.model.access.csv
+++ b/short_url_yourls/security/ir.model.access.csv
@@ -1,3 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
short_url_yourls,short.url.yourls,model_short_url_yourls,,1,1,1,1
-short_url_yourls_line,short.url.yourls.line,model_short_url_yourls_line,base.group_no_one,1,1,1,1
\ No newline at end of file
+short_url_yourls_line,short.url.yourls.line,model_short_url_yourls_line,base.group_no_one,1,1,1,1
diff --git a/short_url_yourls/view/short_url_yourls_view.xml b/short_url_yourls/view/short_url_yourls_view.xml
index 410a32495..9e241e6e2 100644
--- a/short_url_yourls/view/short_url_yourls_view.xml
+++ b/short_url_yourls/view/short_url_yourls_view.xml
@@ -1,13 +1,12 @@
-
+
-
view.short.url.yourls.tree
short.url.yourls
-
-
+
+
@@ -18,17 +17,17 @@
-
+
-