pull/702/head^2
Ozzieisaacs 6 years ago
parent 5fc742c9c4
commit ee85492c7d

@ -178,13 +178,18 @@ def get_valid_filename(value, replace_whitespace=True):
def get_sorted_author(value): def get_sorted_author(value):
try: try:
regexes = ["^(JR|SR)\.?$", "^I{1,3}\.?$", "^IV\.?$"] if ',' not in value:
combined = "(" + ")|(".join(regexes) + ")" regexes = ["^(JR|SR)\.?$", "^I{1,3}\.?$", "^IV\.?$"]
value = value.split(" ") combined = "(" + ")|(".join(regexes) + ")"
if re.match(combined, value[-1].upper()): value = value.split(" ")
value2 = value[-2] + ", " + " ".join(value[:-2]) + " " + value[-1] 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: else:
value2 = value[-1] + ", " + " ".join(value[:-1]) value2 = value
except Exception: except Exception:
web.app.logger.error("Sorting author " + str(value) + "failed") web.app.logger.error("Sorting author " + str(value) + "failed")
value2 = value value2 = value

@ -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 no element is found add it
# if new_element is None: # if new_element is None:
if db_type == 'author': 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': elif db_type == 'series':
new_element = db_object(add_element, add_element) new_element = db_object(add_element, add_element)
elif db_type == 'custom': elif db_type == 'custom':

Loading…
Cancel
Save