2021-03-08 08:49:10 -08:00
|
|
|
""" database schema for info about authors """
|
2021-12-05 12:28:17 -08:00
|
|
|
import re
|
2021-06-23 16:14:59 -07:00
|
|
|
from django.contrib.postgres.indexes import GinIndex
|
2020-11-27 14:54:08 -08:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from bookwyrm import activitypub
|
2020-11-28 13:40:09 -08:00
|
|
|
from bookwyrm.settings import DOMAIN
|
2020-11-27 14:54:08 -08:00
|
|
|
|
2020-12-21 12:17:18 -08:00
|
|
|
from .book import BookDataModel
|
2020-11-30 14:40:26 -08:00
|
|
|
from . import fields
|
2020-11-27 14:54:08 -08:00
|
|
|
|
|
|
|
|
2020-12-21 12:17:18 -08:00
|
|
|
class Author(BookDataModel):
|
2021-04-26 09:15:42 -07:00
|
|
|
"""basic biographic info"""
|
2021-03-08 08:49:10 -08:00
|
|
|
|
2020-12-12 18:06:48 -08:00
|
|
|
wikipedia_link = fields.CharField(
|
2021-03-08 08:49:10 -08:00
|
|
|
max_length=255, blank=True, null=True, deduplication_field=True
|
|
|
|
)
|
2021-04-06 17:46:06 -07:00
|
|
|
isni = fields.CharField(
|
2023-01-11 19:21:40 -08:00
|
|
|
max_length=255, blank=True, null=True, deduplication_field=True
|
2021-04-06 17:46:06 -07:00
|
|
|
)
|
|
|
|
gutenberg_id = fields.CharField(
|
|
|
|
max_length=255, blank=True, null=True, deduplication_field=True
|
|
|
|
)
|
2022-12-11 20:33:33 +01:00
|
|
|
isfdb = fields.CharField(
|
|
|
|
max_length=255, blank=True, null=True, deduplication_field=True
|
|
|
|
)
|
2023-01-15 09:41:39 +01:00
|
|
|
|
|
|
|
website = fields.CharField(
|
|
|
|
max_length=255, blank=True, null=True, deduplication_field=True
|
|
|
|
)
|
2020-11-27 14:54:08 -08:00
|
|
|
# idk probably other keys would be useful here?
|
2020-11-30 14:40:26 -08:00
|
|
|
born = fields.DateTimeField(blank=True, null=True)
|
|
|
|
died = fields.DateTimeField(blank=True, null=True)
|
2021-11-22 08:47:12 +11:00
|
|
|
name = fields.CharField(max_length=255)
|
2020-11-30 14:40:26 -08:00
|
|
|
aliases = fields.ArrayField(
|
2020-11-27 14:54:08 -08:00
|
|
|
models.CharField(max_length=255), blank=True, default=list
|
|
|
|
)
|
2020-12-16 16:47:05 -08:00
|
|
|
bio = fields.HtmlField(null=True, blank=True)
|
2020-11-27 14:54:08 -08:00
|
|
|
|
2022-01-05 14:33:10 -08:00
|
|
|
def save(self, *args, **kwargs):
|
2022-12-20 21:48:14 +01:00
|
|
|
"""normalize isni format"""
|
2022-10-09 19:36:24 -04:00
|
|
|
if self.isni:
|
|
|
|
self.isni = re.sub(r"\s", "", self.isni)
|
|
|
|
|
2022-01-05 14:33:10 -08:00
|
|
|
return super().save(*args, **kwargs)
|
|
|
|
|
2021-12-05 12:28:17 -08:00
|
|
|
@property
|
|
|
|
def isni_link(self):
|
|
|
|
"""generate the url from the isni id"""
|
|
|
|
clean_isni = re.sub(r"\s", "", self.isni)
|
2021-12-05 13:24:40 -08:00
|
|
|
return f"https://isni.org/isni/{clean_isni}"
|
2021-12-05 12:28:17 -08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def openlibrary_link(self):
|
|
|
|
"""generate the url from the openlibrary id"""
|
|
|
|
return f"https://openlibrary.org/authors/{self.openlibrary_key}"
|
|
|
|
|
2022-12-11 20:33:33 +01:00
|
|
|
@property
|
|
|
|
def isfdb_link(self):
|
|
|
|
"""generate the url from the isni id"""
|
|
|
|
return f"https://www.isfdb.org/cgi-bin/ea.cgi?{self.isfdb}"
|
|
|
|
|
2020-11-28 13:40:09 -08:00
|
|
|
def get_remote_id(self):
|
2021-04-26 09:15:42 -07:00
|
|
|
"""editions and works both use "book" instead of model_name"""
|
2021-09-18 11:32:00 -07:00
|
|
|
return f"https://{DOMAIN}/author/{self.id}"
|
2020-11-28 13:40:09 -08:00
|
|
|
|
2020-11-27 14:54:08 -08:00
|
|
|
activity_serializer = activitypub.Author
|
2021-06-23 16:14:59 -07:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
"""sets up postgres GIN index field"""
|
|
|
|
|
|
|
|
indexes = (GinIndex(fields=["search_vector"]),)
|