Skip to content

Commit 4a55347

Browse files
committed
feat(url_slug): add new module for generating URL slugs from record names
1 parent 0f16ee6 commit 4a55347

File tree

12 files changed

+1403
-8
lines changed

12 files changed

+1403
-8
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,3 @@ repos:
131131
- --rcfile=.pylintrc
132132
- --exit-zero
133133
verbose: true
134-
- repo: local
135-
hooks:
136-
- id: coding-guidelines
137-
name: Check Coding Guidelines
138-
entry: ./coding-guidelines.py
139-
language: system
140-
types: [python]
141-
pass_filenames: false

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ git clone git@github.com:Mint-System/Odoo-Apps-Server-Tools.git ./addons/server_
2626
| [mail_service_users](mail_service_users) | Exclude service users from warranty contract. |
2727
| [prometheus_exporter](prometheus_exporter) | Monitor Odoo metrics with Prometheus. |
2828
| [server_config_environment](server_config_environment) | Define environments for server configurations. |
29+
| [url_slug](url_slug) | Generate slug from record name for web urls. |

url_slug/LICENSE

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

url_slug/README.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.. image:: https://img.shields.io/badge/licence-GPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/gpl-3.0-standalone.html
3+
:alt: License: GPL-3
4+
5+
6+
========
7+
Url Slug
8+
========
9+
10+
Generate slug from record name for web urls.
11+
12+
For a detailed documentation have a look at https://www.odoo-wiki.org/url-slug.html
13+
14+
Configuration
15+
~~~~~~~~~~~~~
16+
17+
* Inherit the slug mixin in your module:
18+
19+
.. code-block:: python
20+
21+
class Note(models.Model):
22+
_name = "note.note"
23+
_inherit = ['url.slug.mixin']
24+
25+
* Optionally overwrite the compute slug method:
26+
27+
.. code-block:: python
28+
29+
@api.depends("title")
30+
def _compute_slug(self):
31+
for record in self:
32+
record.slug = slugify(record.title)
33+
34+
Maintainer
35+
~~~~~~~~~~
36+
37+
.. image:: https://raw.githubusercontent.com/Mint-System/Wiki/main/attachments/mint-system-logo.png
38+
:target: https://www.mint-system.ch
39+
40+
This module is maintained by Mint System GmbH.
41+
42+
For support and more information, please visit `our Website <https://www.mint-system.ch>`__.

url_slug/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

url_slug/__manifest__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "Url Slug",
3+
"summary": """
4+
Generate slug from record name for web urls.
5+
""",
6+
"author": "Mint System GmbH",
7+
"website": "https://www.mint-system.ch/",
8+
"category": "Hidden",
9+
"version": "18.0.1.0.0",
10+
"license": "AGPL-3",
11+
"depends": ["base"],
12+
"installable": True,
13+
"application": False,
14+
"auto_install": False,
15+
"images": ["images/screen.png"],
16+
"qweb": ["static/src/xml/board.xml"],
17+
}

url_slug/images/screen.png

1.01 MB
Loading

url_slug/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import url_slug_mixin

url_slug/models/url_slug_mixin.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import logging
2+
import slugify
3+
4+
from odoo import api, fields, models
5+
6+
_logger = logging.getLogger(__name__)
7+
8+
9+
class UrlSlugMixin(models.AbstractModel):
10+
_name = "url.slug.mixin"
11+
_description = "Url Slug Mix"
12+
13+
slug = fields.Char("Url Slug", copy=False, compute="_compute_slug", store=True)
14+
15+
@api.depends("name")
16+
def _compute_slug(self):
17+
for record in self:
18+
record.slug = slugify(record.name)

url_slug/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"

0 commit comments

Comments
 (0)