Skip to content

Commit

Permalink
[FIX] Adapted to pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
milleniumkid committed Jan 6, 2025
1 parent fda153c commit c4c879a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
4 changes: 2 additions & 2 deletions short_url_yourls/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 23 additions & 15 deletions short_url_yourls/models/short_url_yourls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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",
Expand All @@ -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(
_(
Expand All @@ -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,
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion short_url_yourls/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
short_url_yourls_line,short.url.yourls.line,model_short_url_yourls_line,base.group_no_one,1,1,1,1
26 changes: 14 additions & 12 deletions short_url_yourls/view/short_url_yourls_view.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0"?>
<?xml version="1.0" ?>
<odoo>
<data>
<record id="view_short_url_yourls_tree" model="ir.ui.view">
<field name="name">view.short.url.yourls.tree</field>
<field name="model">short.url.yourls</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="total_shortened_urls"/>
<field name="name" />
<field name="total_shortened_urls" />
</tree>
</field>
</record>
Expand All @@ -18,17 +17,17 @@
<form>
<sheet>
<group col="4">
<field name="hostname"/>
<field name="username"/>
<field name="password"/>
<field name="hostname" />
<field name="username" />
<field name="password" />
</group>

<notebook>
<page name="urls" string="Shortened URLs">
<field name="shortened_urls" widget="many2many">
<tree>
<field name="short_url" widget="url"/>
<field name="long_url" widget="url"/>
<field name="short_url" widget="url" />
<field name="long_url" widget="url" />
</tree>
</field>
</page>
Expand All @@ -50,8 +49,11 @@
</p>
</field>
</record>
<menuitem id="short_url_yourls_menu" action="action_short_url_yourls"
parent="iap.iap_root_menu" sequence="1"/>
<menuitem
id="short_url_yourls_menu"
action="action_short_url_yourls"
parent="iap.iap_root_menu"
sequence="1"
/>

</data>
</odoo>

0 comments on commit c4c879a

Please sign in to comment.