diff --git a/bookwyrm/activitypub/book.py b/bookwyrm/activitypub/book.py index e6a01b359..745aa3aab 100644 --- a/bookwyrm/activitypub/book.py +++ b/bookwyrm/activitypub/book.py @@ -19,6 +19,8 @@ class BookData(ActivityObject): viaf: str = None wikidata: str = None asin: str = None + aasin: str = None + isfdb: str = None lastEditedBy: str = None links: List[str] = field(default_factory=lambda: []) fileLinks: List[str] = field(default_factory=lambda: []) diff --git a/bookwyrm/forms/author.py b/bookwyrm/forms/author.py index ca59426de..a7811180f 100644 --- a/bookwyrm/forms/author.py +++ b/bookwyrm/forms/author.py @@ -21,6 +21,7 @@ class AuthorForm(CustomForm): "inventaire_id", "librarything_key", "goodreads_key", + "isfdb", "isni", ] widgets = { diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py index 177339f53..67b044f05 100644 --- a/bookwyrm/forms/books.py +++ b/bookwyrm/forms/books.py @@ -89,6 +89,8 @@ class EditionForm(CustomForm): attrs={"aria-describedby": "desc_oclc_number"} ), "ASIN": forms.TextInput(attrs={"aria-describedby": "desc_ASIN"}), + "AASIN": forms.TextInput(attrs={"aria-describedby": "desc_AASIN"}), + "isfdb": forms.TextInput(attrs={"aria-describedby": "desc_isfdb"}), } diff --git a/bookwyrm/migrations/0168_auto_20221205_1701.py b/bookwyrm/migrations/0168_auto_20221205_1701.py new file mode 100644 index 000000000..45d6c30e7 --- /dev/null +++ b/bookwyrm/migrations/0168_auto_20221205_1701.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.16 on 2022-12-05 17:01 + +import bookwyrm.models.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0167_auto_20221125_1900"), + ] + + operations = [ + migrations.AddField( + model_name="author", + name="aasin", + field=bookwyrm.models.fields.CharField( + blank=True, max_length=255, null=True + ), + ), + migrations.AddField( + model_name="book", + name="aasin", + field=bookwyrm.models.fields.CharField( + blank=True, max_length=255, null=True + ), + ), + ] diff --git a/bookwyrm/migrations/0169_auto_20221206_0902.py b/bookwyrm/migrations/0169_auto_20221206_0902.py new file mode 100644 index 000000000..7235490eb --- /dev/null +++ b/bookwyrm/migrations/0169_auto_20221206_0902.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.16 on 2022-12-06 09:02 + +import bookwyrm.models.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0168_auto_20221205_1701"), + ] + + operations = [ + migrations.AddField( + model_name="author", + name="isfdb", + field=bookwyrm.models.fields.CharField( + blank=True, max_length=255, null=True + ), + ), + migrations.AddField( + model_name="book", + name="isfdb", + field=bookwyrm.models.fields.CharField( + blank=True, max_length=255, null=True + ), + ), + ] diff --git a/bookwyrm/models/author.py b/bookwyrm/models/author.py index 7d2a0e62b..de0c6483f 100644 --- a/bookwyrm/models/author.py +++ b/bookwyrm/models/author.py @@ -24,6 +24,9 @@ class Author(BookDataModel): gutenberg_id = fields.CharField( max_length=255, blank=True, null=True, deduplication_field=True ) + isfdb = fields.CharField( + max_length=255, blank=True, null=True, deduplication_field=True + ) # idk probably other keys would be useful here? born = fields.DateTimeField(blank=True, null=True) died = fields.DateTimeField(blank=True, null=True) @@ -60,6 +63,11 @@ class Author(BookDataModel): """generate the url from the openlibrary id""" return f"https://openlibrary.org/authors/{self.openlibrary_key}" + @property + def isfdb_link(self): + """generate the url from the isni id""" + return f"https://www.isfdb.org/cgi-bin/ea.cgi?{self.isfdb}" + 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 5bef5c1ee..e990b6d64 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -55,6 +55,12 @@ class BookDataModel(ObjectMixin, BookWyrmModel): asin = fields.CharField( max_length=255, blank=True, null=True, deduplication_field=True ) + aasin = fields.CharField( + max_length=255, blank=True, null=True, deduplication_field=True + ) + isfdb = fields.CharField( + max_length=255, blank=True, null=True, deduplication_field=True + ) search_vector = SearchVectorField(null=True) last_edited_by = fields.ForeignKey( @@ -73,6 +79,11 @@ class BookDataModel(ObjectMixin, BookWyrmModel): """generate the url from the inventaire id""" return f"https://inventaire.io/entity/{self.inventaire_id}" + @property + def isfdb_link(self): + """generate the url from the isfdb id""" + return f"https://www.isfdb.org/cgi-bin/title.cgi?{self.isfdb}" + 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 fe34736cf..ade654568 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -28,7 +28,7 @@ {% firstof author.aliases author.born author.died as details %} - {% firstof author.wikipedia_link author.openlibrary_key author.inventaire_id author.isni as links %} + {% firstof author.wikipedia_link author.openlibrary_key author.inventaire_id author.isni author.isfdb as links %} {% if details or links %}
{% if details %} @@ -81,6 +81,14 @@
{% endif %} + {% if author.isfdb %} +
+ + {% trans "View on ISFDB" %} + +
+ {% endif %} + {% trans "Load data" as button_text %} {% if author.openlibrary_key %}
@@ -128,6 +136,14 @@
{% endif %} + + {% if author.isfdb %} +
+ + {% trans "View ISFDB entry" %} + +
+ {% endif %} {% endif %} diff --git a/bookwyrm/templates/author/edit_author.html b/bookwyrm/templates/author/edit_author.html index b0727c43b..1916df6be 100644 --- a/bookwyrm/templates/author/edit_author.html +++ b/bookwyrm/templates/author/edit_author.html @@ -101,6 +101,13 @@ {% include 'snippets/form_errors.html' with errors_list=form.goodreads_key.errors id="desc_goodreads_key" %} +
+ + {{ form.isfdb }} + + {% include 'snippets/form_errors.html' with errors_list=form.isfdb.errors id="desc_isfdb" %} +
+
{{ form.isni }} diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index dd5201268..6a8d4d794 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -158,6 +158,13 @@ {% endif %}

{% endif %} + {% if book.isfdb %} +

+ + {% trans "View on ISFDB" %} + +

+ {% endif %}
diff --git a/bookwyrm/templates/book/book_identifiers.html b/bookwyrm/templates/book/book_identifiers.html index 431c3075f..ff5aad0bb 100644 --- a/bookwyrm/templates/book/book_identifiers.html +++ b/bookwyrm/templates/book/book_identifiers.html @@ -1,7 +1,7 @@ {% spaceless %} {% load i18n %} -{% if book.isbn_13 or book.oclc_number or book.asin %} +{% if book.isbn_13 or book.oclc_number or book.asin or book.aasin or book.isfdb %}
{% if book.isbn_13 %}
@@ -23,6 +23,21 @@
{{ book.asin }}
{% endif %} + + {% if book.aasin %} +
+
{% trans "Audible ASIN:" %}
+
{{ book.aasin }}
+
+ {% endif %} + + {% if book.isfdb %} +
+
{% trans "ISFDB ID:" %}
+
{{ book.isfdb }}
+
+ {% endif %} + {% if book.goodreads_key %}
{% trans "Goodreads:" %}
diff --git a/bookwyrm/templates/book/edit/edit_book_form.html b/bookwyrm/templates/book/edit/edit_book_form.html index b98e32182..728b4819d 100644 --- a/bookwyrm/templates/book/edit/edit_book_form.html +++ b/bookwyrm/templates/book/edit/edit_book_form.html @@ -353,6 +353,24 @@ {% include 'snippets/form_errors.html' with errors_list=form.ASIN.errors id="desc_ASIN" %}
+ +
+ + {{ form.aasin }} + + {% include 'snippets/form_errors.html' with errors_list=form.AASIN.errors id="desc_AASIN" %} +
+ +
+ + {{ form.isfdb }} + + {% include 'snippets/form_errors.html' with errors_list=form.isfdb.errors id="desc_isfdb" %} +
diff --git a/bookwyrm/tests/data/bw_edition.json b/bookwyrm/tests/data/bw_edition.json index 6194e4090..b61ceb1c1 100644 --- a/bookwyrm/tests/data/bw_edition.json +++ b/bookwyrm/tests/data/bw_edition.json @@ -21,6 +21,7 @@ "openlibrary_key": "OL29486417M", "librarything_key": null, "goodreads_key": null, + "isfdb": null, "attachment": [ { "url": "https://bookwyrm.social/images/covers/50202953._SX318_.jpg", diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index 7b13989f3..a3d930f6c 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -63,7 +63,7 @@ class ExportViews(TestCase): # pylint: disable=line-too-long self.assertEqual( result[0], - b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,isbn_10,isbn_13,oclc_number,rating,review_name,review_cw,review_content\r\n", + b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,rating,review_name,review_cw,review_content\r\n", ) - expected = f"Test Book,,{self.book.remote_id},,,,,beep,,,,123456789X,9781234567890,,,,,\r\n" + expected = f"Test Book,,{self.book.remote_id},,,,,beep,,,,,,123456789X,9781234567890,,,,,\r\n" self.assertEqual(result[1].decode("utf-8"), expected) diff --git a/bookwyrm/views/books/editions.py b/bookwyrm/views/books/editions.py index 8044f78e4..54d1bd84c 100644 --- a/bookwyrm/views/books/editions.py +++ b/bookwyrm/views/books/editions.py @@ -49,6 +49,8 @@ class Editions(View): "isbn_13", "oclc_number", "asin", + "aasin", + "isfdb", ] search_filter_entries = [ {f"{f}__icontains": query} for f in searchable_fields