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

Added polish in readme to supported UI languages

Handling of missing tags in fb import
naming of path is more imitating calibre (replacement of special characters, "pinyining" of author names if unidecode is available )
Sorting of authors (similar to calibre for jr./sr./I..IV endings)
bugfix pathseparator on windows and linux during upload
bugfix os.rename for authordir
publishing date on detailview is formated according to slected locale
filename on downloading from web ui is now correct displayed
added ids to html for testing
This commit is contained in:
OzzieIsaacs
2017-02-15 18:09:17 +01:00
parent 13caa54aad
commit 93b19165cf
18 changed files with 141 additions and 138 deletions

View File

@@ -22,6 +22,11 @@ from email.generator import Generator
from flask_babel import gettext as _
import subprocess
import shutil
try:
import unidecode
use_unidecode=True
except:
use_unidecode=False
def update_download(book_id, user_id):
check = ub.session.query(ub.Downloads).filter(ub.Downloads.user_id == user_id).filter(ub.Downloads.book_id ==
@@ -203,7 +208,7 @@ def get_attachment(file_path):
return attachment
except IOError:
traceback.print_exc()
message = (_('The requested file could not be read. Maybe wrong permissions?')) # ToDo: What is this?
app.logger.error = (u'The requested file could not be read. Maybe wrong permissions?')
return None
@@ -212,47 +217,54 @@ def get_valid_filename(value, replace_whitespace=True):
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())
if value[-1:] ==u'.':
value = value[:-1]+u'_'
if use_unidecode:
value=(unidecode.unidecode(value)).strip()
else:
value=value.replace('§','SS')
value=value.replace('ß','ss')
value = unicodedata.normalize('NFKD', value)
re_slugify = re.compile('[\W\s-]', re.UNICODE)
value = unicode(re_slugify.sub('', value).strip())
if replace_whitespace:
value = re.sub('[\s]+', '_', value, flags=re.U)
value = value.replace(u"\u00DF", "ss")
#*+:\"/<>? werden durch _ ersetzt
value = re.sub('[\*\+:\\\"/<>\?]+', '_', value, flags=re.U)
value = value[:128]
return value
def get_sorted_author(value):
regexes = ["^(JR|SR)\.?$","^I{1,3}\.?$","^IV\.?$"]
combined = "(" + ")|(".join(regexes) + ")"
value = value.split(" ")
if re.match(combined,value[-1].upper()):
value2 = value[-2] + ", " + " ".join(value[:-2]) + " " + value[-1]
else:
value2 = value[-1] + ", " + " ".join(value[:-1])
return value2
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
def update_dir_stucture(book_id, calibrepath):
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
path = os.path.join(calibrepath, book.path)
path = os.path.join(calibrepath, book.path)#.replace('/',os.path.sep)).replace('\\',os.path.sep)
authordir = book.path.split(os.sep)[0]
new_authordir = get_valid_filename(book.authors[0].name, False)
titledir = book.path.split(os.sep)[1]
new_titledir = get_valid_filename(book.title, False) + " (" + str(book_id) + ")"
authordir = book.path.split('/')[0]
new_authordir = get_valid_filename(book.authors[0].name)
titledir = book.path.split('/')[1]
new_titledir = get_valid_filename(book.title) + " (" + str(book_id) + ")"
if titledir != new_titledir:
new_title_path = os.path.join(os.path.dirname(path), new_titledir)
os.rename(path, new_title_path)
path = new_title_path
book.path = book.path.split(os.sep)[0] + os.sep + new_titledir
book.path = book.path.split('/')[0] + '/' + new_titledir
if authordir != new_authordir:
new_author_path = os.path.join(os.path.join(calibrepath, new_authordir), os.path.basename(path))
os.renames(path, new_author_path)
book.path = new_authordir + os.sep + book.path.split(os.sep)[1]
os.rename(path, new_author_path)
book.path = new_authordir + '/' + book.path.split('/')[1]
db.session.commit()