Skip to content

Commit

Permalink
add python-slugify para a geração de slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
thisiscleverson committed Apr 21, 2024
1 parent 447b750 commit feb347c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
10 changes: 3 additions & 7 deletions app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
"""
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ unidecode >= 1.3.8
pytz>=2024.1
cachelib>=0.12.0
gunicorn>=21.2.0
python-slugify>=8.0.4

0 comments on commit feb347c

Please sign in to comment.