forked from mirrors/bookwyrm
Adds remote ID to authors
This commit is contained in:
parent
4741ada418
commit
e9393ede28
3 changed files with 24 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
''' using another fedireads instance as a source of book data '''
|
''' using another fedireads instance as a source of book data '''
|
||||||
|
import re
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
@ -32,6 +33,9 @@ class Connector(AbstractConnector):
|
||||||
|
|
||||||
def get_or_create_book(self, remote_id):
|
def get_or_create_book(self, remote_id):
|
||||||
''' pull up a book record by whatever means possible '''
|
''' pull up a book record by whatever means possible '''
|
||||||
|
# re-construct a remote id from the int and books_url
|
||||||
|
if re.match(r'^\d+$', remote_id):
|
||||||
|
remote_id = self.books_url + '/' + remote_id
|
||||||
book = models.Book.objects.select_subclasses().filter(
|
book = models.Book.objects.select_subclasses().filter(
|
||||||
remote_id=remote_id
|
remote_id=remote_id
|
||||||
).first()
|
).first()
|
||||||
|
@ -146,7 +150,7 @@ class Connector(AbstractConnector):
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
resp = requests.get('%s/authors/%s.json' % (self.url, remote_id))
|
resp = requests.get('%s/authors/%s.json' % (self.base_url, remote_id))
|
||||||
if not resp.ok:
|
if not resp.ok:
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
||||||
|
|
18
fedireads/migrations/0038_author_remote_id.py
Normal file
18
fedireads/migrations/0038_author_remote_id.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.0.3 on 2020-05-09 19:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('fedireads', '0037_auto_20200504_0154'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='author',
|
||||||
|
name='remote_id',
|
||||||
|
field=models.CharField(max_length=255, null=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -150,6 +150,7 @@ class Edition(Book):
|
||||||
|
|
||||||
class Author(FedireadsModel):
|
class Author(FedireadsModel):
|
||||||
''' copy of an author from OL '''
|
''' copy of an author from OL '''
|
||||||
|
remote_id = models.CharField(max_length=255, null=True)
|
||||||
openlibrary_key = models.CharField(max_length=255, blank=True, null=True)
|
openlibrary_key = models.CharField(max_length=255, blank=True, null=True)
|
||||||
sync = models.BooleanField(default=True)
|
sync = models.BooleanField(default=True)
|
||||||
last_sync_date = models.DateTimeField(default=timezone.now)
|
last_sync_date = models.DateTimeField(default=timezone.now)
|
||||||
|
|
Loading…
Reference in a new issue