diff --git a/fedireads/forms.py b/fedireads/forms.py index bddef528f..87dc5dfd1 100644 --- a/fedireads/forms.py +++ b/fedireads/forms.py @@ -75,5 +75,34 @@ class TagForm(ModelForm): labels = {'name': 'Add a tag'} +class CoverForm(ModelForm): + class Meta: + model = models.Book + fields = ['cover'] + help_texts = {f: None for f in fields} + + +class BookForm(ModelForm): + class Meta: + model = models.Book + exclude = [ + 'created_date', + 'updated_date', + 'last_sync_date', + + 'authors', + 'parent_work', + 'shelves', + 'misc_identifiers', + + 'subjects', + 'subject_places', + + 'source_url', + 'connector', + ] + + class ImportForm(forms.Form): csv_file = forms.FileField() + diff --git a/fedireads/migrations/0023_auto_20200328_2203.py b/fedireads/migrations/0023_auto_20200328_2203.py new file mode 100644 index 000000000..1ce169f6a --- /dev/null +++ b/fedireads/migrations/0023_auto_20200328_2203.py @@ -0,0 +1,114 @@ +# Generated by Django 3.0.3 on 2020-03-28 22:03 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('fedireads', '0022_auto_20200328_2001'), + ] + + operations = [ + migrations.AddField( + model_name='book', + name='sync_cover', + field=models.BooleanField(default=True), + ), + migrations.AlterField( + model_name='author', + name='born', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='author', + name='died', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='author', + name='fedireads_key', + field=models.CharField(default=uuid.uuid4, max_length=255, unique=True), + ), + migrations.AlterField( + model_name='author', + name='first_name', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='author', + name='last_name', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='author', + name='openlibrary_key', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='book', + name='first_published_date', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='book', + name='goodreads_key', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='book', + name='language', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='book', + name='librarything_key', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='book', + name='openlibrary_key', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='book', + name='published_date', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='book', + name='sort_title', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='book', + name='subtitle', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='edition', + name='isbn', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='edition', + name='oclc_number', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='edition', + name='pages', + field=models.IntegerField(blank=True, null=True), + ), + migrations.AlterField( + model_name='edition', + name='physical_format', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AlterField( + model_name='work', + name='lccn', + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/fedireads/models/book.py b/fedireads/models/book.py index e9aefa0fd..f6f6ea046 100644 --- a/fedireads/models/book.py +++ b/fedireads/models/book.py @@ -47,15 +47,16 @@ class Connector(FedireadsModel): class Book(FedireadsModel): ''' a generic book, which can mean either an edition or a work ''' # these identifiers apply to both works and editions - openlibrary_key = models.CharField(max_length=255, unique=True, null=True) - librarything_key = models.CharField(max_length=255, unique=True, null=True) fedireads_key = models.CharField(max_length=255, unique=True, default=uuid4) - goodreads_key = models.CharField(max_length=255, unique=True, null=True) + openlibrary_key = models.CharField(max_length=255, blank=True, null=True) + librarything_key = models.CharField(max_length=255, blank=True, null=True) + goodreads_key = models.CharField(max_length=255, blank=True, null=True) misc_identifiers = JSONField(null=True) # info about where the data comes from and where/if to sync source_url = models.CharField(max_length=255, unique=True, null=True) sync = models.BooleanField(default=True) + sync_cover = models.BooleanField(default=True) last_sync_date = models.DateTimeField(default=datetime.now) connector = models.ForeignKey( 'Connector', on_delete=models.PROTECT, null=True) @@ -64,10 +65,10 @@ class Book(FedireadsModel): # book/work metadata title = models.CharField(max_length=255) - sort_title = models.CharField(max_length=255, null=True) - subtitle = models.TextField(blank=True, null=True) + sort_title = models.CharField(max_length=255, blank=True, null=True) + subtitle = models.CharField(max_length=255, blank=True, null=True) description = models.TextField(blank=True, null=True) - language = models.CharField(max_length=255, null=True) + language = models.CharField(max_length=255, blank=True, null=True) series = models.CharField(max_length=255, blank=True, null=True) series_number = models.CharField(max_length=255, blank=True, null=True) subjects = ArrayField( @@ -78,10 +79,9 @@ class Book(FedireadsModel): ) # TODO: include an annotation about the type of authorship (ie, translator) authors = models.ManyToManyField('Author') - # TODO: also store cover thumbnail cover = models.ImageField(upload_to='covers/', blank=True, null=True) - first_published_date = models.DateTimeField(null=True) - published_date = models.DateTimeField(null=True) + first_published_date = models.DateTimeField(blank=True, null=True) + published_date = models.DateTimeField(blank=True, null=True) shelves = models.ManyToManyField( 'Shelf', symmetrical=False, @@ -109,16 +109,16 @@ class Book(FedireadsModel): class Work(Book): ''' a work (an abstract concept of a book that manifests in an edition) ''' # library of congress catalog control number - lccn = models.CharField(max_length=255, unique=True, null=True) + lccn = models.CharField(max_length=255, blank=True, null=True) class Edition(Book): ''' an edition of a book ''' # these identifiers only apply to work - isbn = models.CharField(max_length=255, unique=True, null=True) - oclc_number = models.CharField(max_length=255, unique=True, null=True) - pages = models.IntegerField(null=True) - physical_format = models.CharField(max_length=255, null=True) + isbn = models.CharField(max_length=255, blank=True, null=True) + oclc_number = models.CharField(max_length=255, blank=True, null=True) + pages = models.IntegerField(blank=True, null=True) + physical_format = models.CharField(max_length=255, blank=True, null=True) publishers = ArrayField( models.CharField(max_length=255), blank=True, default=list ) @@ -126,15 +126,15 @@ class Edition(Book): class Author(FedireadsModel): ''' copy of an author from OL ''' - openlibrary_key = models.CharField(max_length=255, null=True, unique=True) - fedireads_key = models.CharField(max_length=255, null=True, unique=True) + fedireads_key = models.CharField(max_length=255, unique=True, default=uuid4) + openlibrary_key = models.CharField(max_length=255, blank=True, null=True) wikipedia_link = models.CharField(max_length=255, blank=True, null=True) # idk probably other keys would be useful here? - born = models.DateTimeField(null=True) - died = models.DateTimeField(null=True) + born = models.DateTimeField(blank=True, null=True) + died = models.DateTimeField(blank=True, null=True) name = models.CharField(max_length=255) - last_name = models.CharField(max_length=255, null=True) - first_name = models.CharField(max_length=255, null=True) + last_name = models.CharField(max_length=255, blank=True, null=True) + first_name = models.CharField(max_length=255, blank=True, null=True) aliases = ArrayField( models.CharField(max_length=255), blank=True, default=list ) diff --git a/fedireads/static/format.css b/fedireads/static/format.css index 5be550027..8278f2558 100644 --- a/fedireads/static/format.css +++ b/fedireads/static/format.css @@ -281,12 +281,12 @@ button.warning { height: 5em; } -.user-profile h2 a { +h2 .edit-link { text-decoration: none; font-size: 0.9em; float: right; } -.user-profile h2 .icon { +h2 .edit-link .icon { font-size: 1.2em; } .user-profile .row > * { diff --git a/fedireads/templates/book.html b/fedireads/templates/book.html index b337f5526..d42533882 100644 --- a/fedireads/templates/book.html +++ b/fedireads/templates/book.html @@ -1,9 +1,18 @@ {% extends 'layout.html' %} {% load fr_display %} {% block content %} -
+

{{ book.title }} by - {% include 'snippets/authors.html' with book=book %}

+ {% include 'snippets/authors.html' with book=book %} + + {% if request.user.is_authenticated %} + edit + + Edit Book + + + {% endif %} +
{% if book.parent_work %}

Edition of {{ book.parent_work.title }}

{% endif %}
@@ -24,6 +33,15 @@ {% include 'snippets/shelve_button.html' %}
+
+ {% if request.user.is_authenticated and not book.cover %} +
+ {% csrf_token %} + {{ cover_form.as_p }} + +
+ {% endif %} +
diff --git a/fedireads/templates/edit_book.html b/fedireads/templates/edit_book.html new file mode 100644 index 000000000..529a2f0c5 --- /dev/null +++ b/fedireads/templates/edit_book.html @@ -0,0 +1,15 @@ +{% extends 'layout.html' %} +{% block content %} +
+

Edit "{{ book.title }}"

+ +

{% include 'snippets/book_cover.html' with book=book %}

+ +
+ {% csrf_token %} + {{ form.as_p }} + +
+
+{% endblock %} + diff --git a/fedireads/templates/edit_user.html b/fedireads/templates/edit_user.html index 832aac28d..c4972f94f 100644 --- a/fedireads/templates/edit_user.html +++ b/fedireads/templates/edit_user.html @@ -1,8 +1,11 @@ {% extends 'layout.html' %} {% block content %} -
+