From 45ac13a7fffe00337127b5b82d6a569cc2703ed3 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 30 Jan 2021 18:30:07 -0800 Subject: [PATCH 1/8] Clear unused editions with poor metadata --- .../management/commands/remove_editions.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 bookwyrm/management/commands/remove_editions.py diff --git a/bookwyrm/management/commands/remove_editions.py b/bookwyrm/management/commands/remove_editions.py new file mode 100644 index 00000000..c5153f44 --- /dev/null +++ b/bookwyrm/management/commands/remove_editions.py @@ -0,0 +1,34 @@ +''' PROCEED WITH CAUTION: this permanently deletes book data ''' +from django.core.management.base import BaseCommand +from django.db.models import Count, Q +from bookwyrm import models + + +def remove_editions(): + ''' combine duplicate editions and update related models ''' + # not in use + filters = {'%s__isnull' % r.name: True \ + for r in models.Edition._meta.related_objects} + # no cover, no identifying fields + filters['cover'] = '' + null_fields = {'%s__isnull' % f: True for f in \ + ['isbn_10', 'isbn_13', 'oclc_number']} + + editions = models.Edition.objects.filter( + Q(languages=[]) | Q(languages__contains=['English']), + **filters, **null_fields + ).annotate(Count('parent_work__editions')).filter( + # mustn't be the only edition for the work + parent_work__editions__count__gt=1 + ) + print(editions.count()) + editions.delete() + + +class Command(BaseCommand): + ''' dedplucate allllll the book data models ''' + help = 'merges duplicate book data' + # pylint: disable=no-self-use,unused-argument + def handle(self, *args, **options): + ''' run deudplications ''' + remove_editions() From 6ce4be74067f1d842d0588a19e561ad47884a282 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 3 Feb 2021 12:25:33 -0800 Subject: [PATCH 2/8] Adds inline form component --- .../templates/components/inline_form.html | 13 ++++++++ bookwyrm/templates/lists/create_form.html | 11 +++++++ bookwyrm/templates/lists/edit_form.html | 11 +++++++ bookwyrm/templates/lists/list_layout.html | 12 ++------ bookwyrm/templates/lists/lists.html | 30 ++++++++----------- 5 files changed, 50 insertions(+), 27 deletions(-) create mode 100644 bookwyrm/templates/components/inline_form.html create mode 100644 bookwyrm/templates/lists/create_form.html create mode 100644 bookwyrm/templates/lists/edit_form.html diff --git a/bookwyrm/templates/components/inline_form.html b/bookwyrm/templates/components/inline_form.html new file mode 100644 index 00000000..6a244ffd --- /dev/null +++ b/bookwyrm/templates/components/inline_form.html @@ -0,0 +1,13 @@ + diff --git a/bookwyrm/templates/lists/create_form.html b/bookwyrm/templates/lists/create_form.html new file mode 100644 index 00000000..706dff08 --- /dev/null +++ b/bookwyrm/templates/lists/create_form.html @@ -0,0 +1,11 @@ +{% extends 'components/inline_form.html' %} + +{% block header %} +Create List +{% endblock %} + +{% block form %} +
+ {% include 'lists/form.html' %} +
+{% endblock %} diff --git a/bookwyrm/templates/lists/edit_form.html b/bookwyrm/templates/lists/edit_form.html new file mode 100644 index 00000000..55723b72 --- /dev/null +++ b/bookwyrm/templates/lists/edit_form.html @@ -0,0 +1,11 @@ +{% extends 'components/inline_form.html' %} + +{% block header %} +Edit List +{% endblock %} + +{% block form %} +
+ {% include 'lists/form.html' %} +
+{% endblock %} diff --git a/bookwyrm/templates/lists/list_layout.html b/bookwyrm/templates/lists/list_layout.html index 1887cd82..d3ff2c48 100644 --- a/bookwyrm/templates/lists/list_layout.html +++ b/bookwyrm/templates/lists/list_layout.html @@ -15,15 +15,9 @@ {% endif %} - +
+ {% include 'lists/edit_form.html' with controls_text="edit-list" %} +
{% block panel %}{% endblock %} diff --git a/bookwyrm/templates/lists/lists.html b/bookwyrm/templates/lists/lists.html index a0e18933..ad2dfbaf 100644 --- a/bookwyrm/templates/lists/lists.html +++ b/bookwyrm/templates/lists/lists.html @@ -5,26 +5,20 @@

Lists

{% if request.user.is_authenticated and not lists.has_previous %} -
-
-
-

Your lists

-
-
- {% include 'snippets/toggle/open_button.html' with controls_text="create-list" icon="plus" text="Create new list" focus="create-list-header" %} -
-
+
+
+

Your lists

+
+
+ {% include 'snippets/toggle/open_button.html' with controls_text="create-list" icon="plus" text="Create new list" focus="create-list-header" %} +
+
- +
+ {% include 'lists/create_form.html' with controls_text="create-list" %} +
+
{% if request.user.list_set.exists %} {% include 'lists/list_items.html' with lists=request.user.list_set.all|slice:4 %} {% endif %} From bcbcdd5b3b070c35537b7aa4089c79cc724a8956 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 3 Feb 2021 12:36:20 -0800 Subject: [PATCH 3/8] Uses component for create shelf form --- .../templates/user/create_shelf_form.html | 26 +++++++++++++++++++ bookwyrm/templates/user/shelf.html | 23 +++------------- bookwyrm/urls.py | 2 +- 3 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 bookwyrm/templates/user/create_shelf_form.html diff --git a/bookwyrm/templates/user/create_shelf_form.html b/bookwyrm/templates/user/create_shelf_form.html new file mode 100644 index 00000000..89f41fd8 --- /dev/null +++ b/bookwyrm/templates/user/create_shelf_form.html @@ -0,0 +1,26 @@ +{% extends 'components/inline_form.html' %} + +{% block header %} +Create New Shelf +{% endblock %} + +{% block form %} +
+ {% csrf_token %} + +
+ + +
+ +
+
+ {% include 'snippets/privacy_select.html' %} +
+
+ +
+
+
+{% endblock %} + diff --git a/bookwyrm/templates/user/shelf.html b/bookwyrm/templates/user/shelf.html index add5e5db..07b4f30b 100644 --- a/bookwyrm/templates/user/shelf.html +++ b/bookwyrm/templates/user/shelf.html @@ -29,30 +29,13 @@ {% if is_self %}
- {% include 'snippets/toggle/open_button.html' with text="Create shelf" icon="plus" class="is-clickable" controls_text="create-shelf-form" %} + {% include 'snippets/toggle/open_button.html' with text="Create shelf" icon="plus" controls_text="create-shelf-form" focus="create-shelf-form-header" %}
{% endif %}
- -