slugify moved to lib
This commit is contained in:
+1
-27
@@ -1,9 +1,6 @@
|
||||
# coding=UTF-8
|
||||
import json
|
||||
from flask import request, current_app, Response
|
||||
import unidecode
|
||||
import re
|
||||
|
||||
|
||||
def check_api_key():
|
||||
api_keys = current_app.config.get("API_KEYS")
|
||||
@@ -16,27 +13,4 @@ def check_api_key():
|
||||
return Response(
|
||||
response, 401,
|
||||
{'WWW-Authenticate': 'Basic realm="Login Required"'}
|
||||
)
|
||||
|
||||
|
||||
def slugify(text):
|
||||
"""Converts a string to a human-readable url"""
|
||||
|
||||
# translate
|
||||
text = unidecode.unidecode(text)
|
||||
|
||||
# lowercase
|
||||
text = text.lower()
|
||||
|
||||
# replace unwanted chars
|
||||
numbers = re.compile('(?<=\d),(?=\d)')
|
||||
text = numbers.sub('', text)
|
||||
unwanted_chars = re.compile(r'[^_a-z0-9/]+')
|
||||
text = unwanted_chars.sub('_', text)
|
||||
|
||||
# remove redundant _
|
||||
duplicated_underscores = re.compile('_{2,}')
|
||||
text = duplicated_underscores.sub('_', text)
|
||||
text = text.strip('_')
|
||||
|
||||
return text
|
||||
)
|
||||
@@ -0,0 +1,26 @@
|
||||
# coding=UTF-8
|
||||
import unidecode
|
||||
import re
|
||||
|
||||
|
||||
def slugify(text):
|
||||
"""Converts a string to a human-readable url"""
|
||||
|
||||
# translate
|
||||
text = unidecode.unidecode(text)
|
||||
|
||||
# lowercase
|
||||
text = text.lower()
|
||||
|
||||
# replace unwanted chars
|
||||
numbers = re.compile('(?<=\d),(?=\d)')
|
||||
text = numbers.sub('', text)
|
||||
unwanted_chars = re.compile(r'[^_a-z0-9/]+')
|
||||
text = unwanted_chars.sub('_', text)
|
||||
|
||||
# remove redundant _
|
||||
duplicated_underscores = re.compile('_{2,}')
|
||||
text = duplicated_underscores.sub('_', text)
|
||||
text = text.strip('_')
|
||||
|
||||
return text
|
||||
@@ -1,5 +1,5 @@
|
||||
from api import db
|
||||
from api.helpers import slugify
|
||||
from api.lib.slugify import slugify
|
||||
from api.models.locale import Locale
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from api import db
|
||||
from api.helpers import slugify
|
||||
from api.lib.slugify import slugify
|
||||
|
||||
|
||||
class Designer(db.Model):
|
||||
|
||||
Reference in New Issue
Block a user