From feb347c0ffd9b506d449794160a0c342a32a83cd Mon Sep 17 00:00:00 2001 From: cleverson Date: Sat, 20 Apr 2024 23:38:19 -0300 Subject: [PATCH] =?UTF-8?q?add=20python-slugify=20para=20a=20gera=C3=A7?= =?UTF-8?q?=C3=A3o=20de=20slugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api.py | 10 +++------- requirements.txt | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/api.py b/app/api.py index 06bb454..4463f04 100644 --- a/app/api.py +++ b/app/api.py @@ -3,6 +3,8 @@ from unidecode import unidecode from flask import Blueprint, request, redirect, session, render_template, flash, jsonify from typing import Tuple, Union +from slugify import slugify as slug + from app.models import Contents, db @@ -22,12 +24,6 @@ def data_valid(self, title: str, content: str) -> bool: def update_content(self, id:str, title: str, body: str, description:str, status:str) -> None: Contents.query.filter_by(id=id).update({Contents.title:title, Contents.body:body, Contents.status:status, Contents.description:description}) db.session.commit() - - def generate_slug(self, title:str) -> str: - title = unidecode(title) - slug = re.sub(r'[^\w\s-]', '', title.lower()) - slug = re.sub(r'\s', '-', slug) - return slug def extract_json_data(self, request:request, keys:list) -> dict: """ @@ -64,7 +60,7 @@ def insert_content(self, title: str, body: str, status: str, description:str, ac id=str(uuid4()), title=title, body=body, - slug=self.generate_slug(title), + slug=slug(title), status=status, accessType=accessType, description=description diff --git a/requirements.txt b/requirements.txt index dccb116..35fdd24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ unidecode >= 1.3.8 pytz>=2024.1 cachelib>=0.12.0 gunicorn>=21.2.0 +python-slugify>=8.0.4 \ No newline at end of file