From ee85492c7df32c00ecd69d1eef181a7ee5da3557 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Tue, 30 Oct 2018 21:47:33 +0100 Subject: [PATCH] Fix #662 --- cps/helper.py | 17 +++++++++++------ cps/web.py | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index 7d67dffd..5001f5d3 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -178,13 +178,18 @@ def get_valid_filename(value, replace_whitespace=True): def get_sorted_author(value): try: - 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] + if ',' not in 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] + elif len(value) == 1: + value2 = value[0] + else: + value2 = value[-1] + ", " + " ".join(value[:-1]) else: - value2 = value[-1] + ", " + " ".join(value[:-1]) + value2 = value except Exception: web.app.logger.error("Sorting author " + str(value) + "failed") value2 = value diff --git a/cps/web.py b/cps/web.py index 28f9a05c..6bc179ee 100644 --- a/cps/web.py +++ b/cps/web.py @@ -588,7 +588,7 @@ def modify_database_object(input_elements, db_book_object, db_object, db_session # if no element is found add it # if new_element is None: if db_type == 'author': - new_element = db_object(add_element, add_element.replace('|', ','), "") + new_element = db_object(add_element, helper.get_sorted_author(add_element.replace('|', ',')), "") elif db_type == 'series': new_element = db_object(add_element, add_element) elif db_type == 'custom':