mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-28 19:10:35 +00:00
Remove sync fields and share fields between book and author
This commit is contained in:
parent
aac264c998
commit
cfa1a1b42c
6 changed files with 84 additions and 49 deletions
|
@ -123,7 +123,6 @@ class EditionForm(CustomForm):
|
||||||
'remote_id',
|
'remote_id',
|
||||||
'created_date',
|
'created_date',
|
||||||
'updated_date',
|
'updated_date',
|
||||||
'last_sync_date',
|
|
||||||
|
|
||||||
'authors',# TODO
|
'authors',# TODO
|
||||||
'parent_work',
|
'parent_work',
|
||||||
|
|
61
bookwyrm/migrations/0029_auto_20201221_2014.py
Normal file
61
bookwyrm/migrations/0029_auto_20201221_2014.py
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
# Generated by Django 3.0.7 on 2020-12-21 20:14
|
||||||
|
|
||||||
|
import bookwyrm.models.fields
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('bookwyrm', '0028_remove_book_author_text'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='author',
|
||||||
|
name='last_sync_date',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='author',
|
||||||
|
name='sync',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='book',
|
||||||
|
name='last_sync_date',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='book',
|
||||||
|
name='sync',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='book',
|
||||||
|
name='sync_cover',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='author',
|
||||||
|
name='goodreads_key',
|
||||||
|
field=bookwyrm.models.fields.CharField(blank=True, max_length=255, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='author',
|
||||||
|
name='last_edited_by',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='author',
|
||||||
|
name='librarything_key',
|
||||||
|
field=bookwyrm.models.fields.CharField(blank=True, max_length=255, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='book',
|
||||||
|
name='last_edited_by',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='author',
|
||||||
|
name='origin_id',
|
||||||
|
field=models.CharField(blank=True, max_length=255, null=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,21 +1,15 @@
|
||||||
''' database schema for info about authors '''
|
''' database schema for info about authors '''
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
from bookwyrm.settings import DOMAIN
|
from bookwyrm.settings import DOMAIN
|
||||||
|
|
||||||
from .base_model import ActivitypubMixin, BookWyrmModel
|
from .book import BookDataModel
|
||||||
from . import fields
|
from . import fields
|
||||||
|
|
||||||
|
|
||||||
class Author(ActivitypubMixin, BookWyrmModel):
|
class Author(BookDataModel):
|
||||||
''' basic biographic info '''
|
''' basic biographic info '''
|
||||||
origin_id = models.CharField(max_length=255, null=True)
|
|
||||||
openlibrary_key = fields.CharField(
|
|
||||||
max_length=255, blank=True, null=True, deduplication_field=True)
|
|
||||||
sync = models.BooleanField(default=True)
|
|
||||||
last_sync_date = models.DateTimeField(default=timezone.now)
|
|
||||||
wikipedia_link = fields.CharField(
|
wikipedia_link = fields.CharField(
|
||||||
max_length=255, blank=True, null=True, deduplication_field=True)
|
max_length=255, blank=True, null=True, deduplication_field=True)
|
||||||
# idk probably other keys would be useful here?
|
# idk probably other keys would be useful here?
|
||||||
|
@ -27,15 +21,6 @@ class Author(ActivitypubMixin, BookWyrmModel):
|
||||||
)
|
)
|
||||||
bio = fields.HtmlField(null=True, blank=True)
|
bio = fields.HtmlField(null=True, blank=True)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
''' handle remote vs origin ids '''
|
|
||||||
if self.id:
|
|
||||||
self.remote_id = self.get_remote_id()
|
|
||||||
else:
|
|
||||||
self.origin_id = self.remote_id
|
|
||||||
self.remote_id = None
|
|
||||||
return super().save(*args, **kwargs)
|
|
||||||
|
|
||||||
def get_remote_id(self):
|
def get_remote_id(self):
|
||||||
''' editions and works both use "book" instead of model_name '''
|
''' editions and works both use "book" instead of model_name '''
|
||||||
return 'https://%s/author/%s' % (DOMAIN, self.id)
|
return 'https://%s/author/%s' % (DOMAIN, self.id)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
|
||||||
from model_utils.managers import InheritanceManager
|
from model_utils.managers import InheritanceManager
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
|
@ -12,10 +11,9 @@ from .base_model import BookWyrmModel
|
||||||
from .base_model import ActivitypubMixin, OrderedCollectionPageMixin
|
from .base_model import ActivitypubMixin, OrderedCollectionPageMixin
|
||||||
from . import fields
|
from . import fields
|
||||||
|
|
||||||
class Book(ActivitypubMixin, BookWyrmModel):
|
class BookDataModel(ActivitypubMixin, BookWyrmModel):
|
||||||
''' a generic book, which can mean either an edition or a work '''
|
''' fields shared between editable book data (books, works, authors) '''
|
||||||
origin_id = models.CharField(max_length=255, null=True, blank=True)
|
origin_id = models.CharField(max_length=255, null=True, blank=True)
|
||||||
# these identifiers apply to both works and editions
|
|
||||||
openlibrary_key = fields.CharField(
|
openlibrary_key = fields.CharField(
|
||||||
max_length=255, blank=True, null=True, deduplication_field=True)
|
max_length=255, blank=True, null=True, deduplication_field=True)
|
||||||
librarything_key = fields.CharField(
|
librarything_key = fields.CharField(
|
||||||
|
@ -23,15 +21,28 @@ class Book(ActivitypubMixin, BookWyrmModel):
|
||||||
goodreads_key = fields.CharField(
|
goodreads_key = fields.CharField(
|
||||||
max_length=255, blank=True, null=True, deduplication_field=True)
|
max_length=255, blank=True, null=True, deduplication_field=True)
|
||||||
|
|
||||||
# info about where the data comes from and where/if to sync
|
last_edited_by = models.ForeignKey(
|
||||||
sync = models.BooleanField(default=True)
|
'User', on_delete=models.PROTECT, null=True)
|
||||||
sync_cover = models.BooleanField(default=True)
|
|
||||||
last_sync_date = models.DateTimeField(default=timezone.now)
|
class Meta:
|
||||||
|
''' can't initialize this model, that wouldn't make sense '''
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
''' ensure that the remote_id is within this instance '''
|
||||||
|
if self.id:
|
||||||
|
self.remote_id = self.get_remote_id()
|
||||||
|
else:
|
||||||
|
self.origin_id = self.remote_id
|
||||||
|
self.remote_id = None
|
||||||
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class Book(BookDataModel):
|
||||||
|
''' a generic book, which can mean either an edition or a work '''
|
||||||
connector = models.ForeignKey(
|
connector = models.ForeignKey(
|
||||||
'Connector', on_delete=models.PROTECT, null=True)
|
'Connector', on_delete=models.PROTECT, null=True)
|
||||||
|
|
||||||
# TODO: edit history
|
|
||||||
|
|
||||||
# book/work metadata
|
# book/work metadata
|
||||||
title = fields.CharField(max_length=255)
|
title = fields.CharField(max_length=255)
|
||||||
sort_title = fields.CharField(max_length=255, blank=True, null=True)
|
sort_title = fields.CharField(max_length=255, blank=True, null=True)
|
||||||
|
@ -86,12 +97,6 @@ class Book(ActivitypubMixin, BookWyrmModel):
|
||||||
''' can't be abstract for query reasons, but you shouldn't USE it '''
|
''' can't be abstract for query reasons, but you shouldn't USE it '''
|
||||||
if not isinstance(self, Edition) and not isinstance(self, Work):
|
if not isinstance(self, Edition) and not isinstance(self, Work):
|
||||||
raise ValueError('Books should be added as Editions or Works')
|
raise ValueError('Books should be added as Editions or Works')
|
||||||
|
|
||||||
if self.id:
|
|
||||||
self.remote_id = self.get_remote_id()
|
|
||||||
else:
|
|
||||||
self.origin_id = self.remote_id
|
|
||||||
self.remote_id = None
|
|
||||||
return super().save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
def get_remote_id(self):
|
def get_remote_id(self):
|
||||||
|
|
|
@ -28,20 +28,6 @@
|
||||||
|
|
||||||
<form class="block" name="edit-book" action="/edit-book/{{ book.id }}" method="post" enctype="multipart/form-data">
|
<form class="block" name="edit-book" action="/edit-book/{{ book.id }}" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="block">
|
|
||||||
<h2 class="title is-4">Data sync
|
|
||||||
<p class="subtitle is-6">If sync is enabled, any changes will be over-written</p>
|
|
||||||
</h2>
|
|
||||||
<div class="columns">
|
|
||||||
<div class="column is-narrow">
|
|
||||||
<label class="checkbox" for="id_sync"><input class="checkbox" type="checkbox" name="sync" id="id_sync"> Sync</label>
|
|
||||||
</div>
|
|
||||||
<div class="column is-narrow">
|
|
||||||
<label class="checkbox" for="id_sync_cover"><input class="checkbox" type="checkbox" name="sync_cover" id="id_sync_cover"> Sync cover</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<h2 class="title is-4">Metadata</h2>
|
<h2 class="title is-4">Metadata</h2>
|
||||||
|
|
|
@ -289,7 +289,6 @@ def upload_cover(request, book_id):
|
||||||
return redirect('/book/%d' % book.id)
|
return redirect('/book/%d' % book.id)
|
||||||
|
|
||||||
book.cover = form.files['cover']
|
book.cover = form.files['cover']
|
||||||
book.sync_cover = False
|
|
||||||
book.save()
|
book.save()
|
||||||
|
|
||||||
outgoing.handle_update_book(request.user, book)
|
outgoing.handle_update_book(request.user, book)
|
||||||
|
|
Loading…
Reference in a new issue