1
0
mirror of https://github.com/janeczku/calibre-web synced 2025-10-19 17:47:39 +00:00

make pretty filenames for downloads; remove random books section on most pages

This commit is contained in:
Jan Broer
2016-03-26 16:12:29 +01:00
parent 2b846b1e6b
commit f163ef2202
4 changed files with 56 additions and 15 deletions

View File

@@ -8,6 +8,8 @@ import smtplib
import sys
import os
import traceback
import re
import unicodedata
from StringIO import StringIO
from email import encoders
from email.MIMEBase import MIMEBase
@@ -125,3 +127,25 @@ def get_attachment(file_path):
message = ('The requested file could not be read. Maybe wrong '
'permissions?')
return None
def get_valid_filename(value):
"""
Returns the given string converted to a string that can be used for a clean
filename. Limits num characters to 128 max.
"""
value = value[:128]
re_slugify = re.compile('[^\w\s-]', re.UNICODE)
value = unicodedata.normalize('NFKD', value)
re_slugify = re.compile('[^\w\s-]', re.UNICODE)
value = unicode(re_slugify.sub('', value).strip())
value = re.sub('[\s]+', '_', value, flags=re.U)
return value
def get_normalized_author(value):
"""
Normalizes sorted author name
"""
value = unicodedata.normalize('NFKD', value)
value = re.sub('[^\w,\s]', '', value, flags=re.U)
value = " ".join(value.split(", ")[::-1])
return value