From 775470a852e46298d1e6b3c35a558d1fcb801c54 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 1 Nov 2021 15:48:52 +1100 Subject: [PATCH] normalise isnis Some isnis are imported with spaces and some not. This normalises them for comparison and creating URLs --- bookwyrm/templates/author/author.html | 3 ++- bookwyrm/templatetags/utilities.py | 11 ++++++++++- bookwyrm/views/books/edit_book.py | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index e1b884ac..682687f4 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -2,6 +2,7 @@ {% load i18n %} {% load markdown %} {% load humanize %} +{% load utilities %} {% block title %}{{ author.name }}{% endblock %} @@ -65,7 +66,7 @@ {% if author.isni %}

- + {% trans "View ISNI record" %}

diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py index 7376c049..229a3d0b 100644 --- a/bookwyrm/templatetags/utilities.py +++ b/bookwyrm/templatetags/utilities.py @@ -1,8 +1,10 @@ """ template filters for really common utilities """ import os +import re from uuid import uuid4 from django import template from django.utils.translation import gettext_lazy as _ +from django.template.defaultfilters import stringfilter from django.templatetags.static import static @@ -71,10 +73,17 @@ def get_book_cover_thumbnail(book, size="medium", ext="jpg"): @register.filter(name="get_isni_bio") def get_isni_bio(existing, author): """Returns the isni bio string if an existing author has an isni listed""" + auth_isni = re.sub("\D","",str(author.isni)) if len(existing) == 0: return "" for value in existing: - if "bio" in value and author.isni == value["isni"]: + if "bio" in value and auth_isni == re.sub("\D","",str(value["isni"])): return value["bio"] return "" + +@register.filter(name="remove_spaces") +@stringfilter +def remove_spaces(arg): + """Removes spaces from argument passed in""" + return re.sub("\s","",str(arg)) diff --git a/bookwyrm/views/books/edit_book.py b/bookwyrm/views/books/edit_book.py index a505c175..939d99d0 100644 --- a/bookwyrm/views/books/edit_book.py +++ b/bookwyrm/views/books/edit_book.py @@ -1,5 +1,6 @@ """ the good stuff! the books! """ from dateutil.parser import parse as dateparse +from re import sub from django.contrib.auth.decorators import login_required, permission_required from django.contrib.postgres.search import SearchRank, SearchVector from django.db import transaction @@ -74,7 +75,7 @@ class EditBook(View): i for i in isni_authors for a in author_matches - if i["isni"] == a.isni + if sub("\D","",str(i["isni"])) == sub("\D","",str(a.isni)) ] # pylint: disable=cell-var-from-loop