mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-16 13:16:33 +00:00
normalise isnis
Some isnis are imported with spaces and some not. This normalises them for comparison and creating URLs
This commit is contained in:
parent
55ac80cc16
commit
775470a852
3 changed files with 14 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
|||
{% load i18n %}
|
||||
{% load markdown %}
|
||||
{% load humanize %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block title %}{{ author.name }}{% endblock %}
|
||||
|
||||
|
@ -65,7 +66,7 @@
|
|||
|
||||
{% if author.isni %}
|
||||
<p class="my-1">
|
||||
<a itemprop="sameAs" href="https://isni.org/isni/{{ author.isni }}" rel="noopener" target="_blank">
|
||||
<a itemprop="sameAs" href="https://isni.org/isni/{{ author.isni|remove_spaces }}" rel="noopener" target="_blank">
|
||||
{% trans "View ISNI record" %}
|
||||
</a>
|
||||
</p>
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue