From 2d875b5575c580f1da2c40051c6952992f52e8c8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Dec 2021 12:28:17 -0800 Subject: [PATCH] Add link properties for remotes --- bookwyrm/models/author.py | 12 ++++++++++++ bookwyrm/models/book.py | 10 ++++++++++ bookwyrm/templates/author/author.html | 10 +++++----- bookwyrm/templates/book/book.html | 4 ++-- bookwyrm/templatetags/utilities.py | 8 -------- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/bookwyrm/models/author.py b/bookwyrm/models/author.py index 6c29ac05..ce0d027c 100644 --- a/bookwyrm/models/author.py +++ b/bookwyrm/models/author.py @@ -1,4 +1,5 @@ """ database schema for info about authors """ +import re from django.contrib.postgres.indexes import GinIndex from django.db import models @@ -33,6 +34,17 @@ class Author(BookDataModel): ) bio = fields.HtmlField(null=True, blank=True) + @property + def isni_link(self): + """generate the url from the isni id""" + clean_isni = re.sub(r"\s", "", self.isni) + return f"https://insi.org/isni/{clean_isni}" + + @property + def openlibrary_link(self): + """generate the url from the openlibrary id""" + return f"https://openlibrary.org/authors/{self.openlibrary_key}" + def get_remote_id(self): """editions and works both use "book" instead of model_name""" return f"https://{DOMAIN}/author/{self.id}" diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index d97a1b8a..0a551bf2 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -52,6 +52,16 @@ class BookDataModel(ObjectMixin, BookWyrmModel): null=True, ) + @property + def openlibrary_link(self): + """generate the url from the openlibrary id""" + return f"https://openlibrary.org/books/{self.openlibrary_key}" + + @property + def inventaire_link(self): + """generate the url from the inventaire id""" + return f"https://inventaire.io/entity/{self.inventaire_id}" + class Meta: """can't initialize this model, that wouldn't make sense""" diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index b066c6ca..fb682176 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -66,23 +66,23 @@ {% if author.isni %}

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

{% endif %} {% if author.openlibrary_key %} -

- +

+ {% trans "View on OpenLibrary" %}

{% endif %} {% if author.inventaire_id %} -

- +

+ {% trans "View on Inventaire" %}

diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 7d4df76f..cbca31b5 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -91,10 +91,10 @@ {% endwith %} {% if book.openlibrary_key %} -

{% trans "View on OpenLibrary" %}

+

{% trans "View on OpenLibrary" %}

{% endif %} {% if book.inventaire_id %} -

{% trans "View on Inventaire" %}

+

{% trans "View on Inventaire" %}

{% endif %} diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py index 5cc25fed..2246fab1 100644 --- a/bookwyrm/templatetags/utilities.py +++ b/bookwyrm/templatetags/utilities.py @@ -5,7 +5,6 @@ from uuid import uuid4 from django import template from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ -from django.template.defaultfilters import stringfilter from django.templatetags.static import static @@ -98,10 +97,3 @@ def get_isni(existing, author, autoescape=True): f'' ) return "" - - -@register.filter(name="remove_spaces") -@stringfilter -def remove_spaces(arg): - """Removes spaces from argument passed in""" - return re.sub(r"\s", "", str(arg))