Fixes field causing form invalidation when editing books

This commit is contained in:
Mouse Reeve 2020-11-24 13:25:28 -08:00
parent 56638f79cf
commit 9bbedc5d9a
4 changed files with 31 additions and 2 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-11-24 21:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookwyrm', '0011_auto_20201113_1727'),
]
operations = [
migrations.AlterField(
model_name='book',
name='origin_id',
field=models.CharField(blank=True, max_length=255, null=True),
),
]

View file

@ -15,7 +15,7 @@ from .base_model import ActivitypubMixin, OrderedCollectionPageMixin
class Book(ActivitypubMixin, BookWyrmModel): class Book(ActivitypubMixin, BookWyrmModel):
''' a generic book, which can mean either an edition or a work ''' ''' a generic book, which can mean either an edition or a work '''
origin_id = models.CharField(max_length=255, null=True) origin_id = models.CharField(max_length=255, null=True, blank=True)
# these identifiers apply to both works and editions # these identifiers apply to both works and editions
openlibrary_key = models.CharField(max_length=255, blank=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) librarything_key = models.CharField(max_length=255, blank=True, null=True)

View file

@ -20,6 +20,11 @@
</div> </div>
</div> </div>
{% if login_form.non_field_errors %}
<div class="block">
<p class="notification is-danger">{{ login_form.non_field_errors }}</p>
</div>
{% endif %}
<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"> <div class="block">

View file

@ -235,7 +235,13 @@ def edit_book(request, book_id):
form = forms.EditionForm(request.POST, request.FILES, instance=book) form = forms.EditionForm(request.POST, request.FILES, instance=book)
if not form.is_valid(): if not form.is_valid():
return redirect(request.headers.get('Referer', '/')) data = {
'title': 'Edit Book',
'book': book,
'form': form
}
print(form.errors)
return TemplateResponse(request, 'edit_book.html', data)
form.save() form.save()
outgoing.handle_update_book(request.user, book) outgoing.handle_update_book(request.user, book)