From df43a8e2c52e16ba4dd63c74bd447a36f2ad5cf6 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 30 Oct 2023 19:43:39 +1100 Subject: [PATCH 1/4] Use django-file-resubmit plugin - save cover images to cache when checking author and work for existing records - fixes #2760 --- bookwyrm/forms/books.py | 5 ++--- bookwyrm/settings.py | 7 ++++++- requirements.txt | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py index 4885dc063..e28c19d79 100644 --- a/bookwyrm/forms/books.py +++ b/bookwyrm/forms/books.py @@ -3,6 +3,7 @@ from django import forms from bookwyrm import models from bookwyrm.models.fields import ClearableFileInputWithWarning +from file_resubmit.admin import AdminResubmitImageWidget from .custom_form import CustomForm from .widgets import ArrayWidget, SelectDateWidget, Select @@ -70,9 +71,7 @@ class EditionForm(CustomForm): "published_date": SelectDateWidget( attrs={"aria-describedby": "desc_published_date"} ), - "cover": ClearableFileInputWithWarning( - attrs={"aria-describedby": "desc_cover"} - ), + "cover": AdminResubmitImageWidget(attrs={"aria-describedby": "desc_cover"}), "physical_format": Select( attrs={"aria-describedby": "desc_physical_format"} ), diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 16241f9df..8c1841e2e 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -99,6 +99,7 @@ INSTALLED_APPS = [ "django.contrib.messages", "django.contrib.staticfiles", "django.contrib.humanize", + "file_resubmit", "sass_processor", "bookwyrm", "celery", @@ -252,7 +253,11 @@ else: "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", }, - } + }, + "file_resubmit": { + "BACKEND": "django.core.cache.backends.filebased.FileBasedCache", + "LOCATION": "/tmp/file_resubmit/", + }, } SESSION_ENGINE = "django.contrib.sessions.backends.cache" diff --git a/requirements.txt b/requirements.txt index 0602f8da4..f63989e1f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ celery==5.2.7 colorthief==0.2.1 Django==3.2.20 django-celery-beat==2.4.0 +django-file-resubmit==0.5.2 django-compressor==4.3.1 django-imagekit==4.1.0 django-model-utils==4.3.1 From c486b9c37e5fefd61272c1039b28e2cdae4191e2 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 30 Oct 2023 21:47:19 +1100 Subject: [PATCH 2/4] pylint fixes --- bookwyrm/forms/books.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py index e28c19d79..c65a6aaf7 100644 --- a/bookwyrm/forms/books.py +++ b/bookwyrm/forms/books.py @@ -1,9 +1,9 @@ """ using django model forms """ from django import forms -from bookwyrm import models -from bookwyrm.models.fields import ClearableFileInputWithWarning from file_resubmit.admin import AdminResubmitImageWidget + +from bookwyrm import models from .custom_form import CustomForm from .widgets import ArrayWidget, SelectDateWidget, Select From d682e55812e04b475271e8036a588cb8df4b9d25 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 5 Nov 2023 16:34:24 +1100 Subject: [PATCH 3/4] swap out django-file-resubmit - we decided to fork it, so this now uses the inaugural RC release of bw-file-resubmit (will need to be adjusted once we're confident it's ok to push a full release) - I was accidentally using the wrong widget lol --- bookwyrm/forms/books.py | 4 ++-- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py index c65a6aaf7..f73ce3f5a 100644 --- a/bookwyrm/forms/books.py +++ b/bookwyrm/forms/books.py @@ -1,7 +1,7 @@ """ using django model forms """ from django import forms -from file_resubmit.admin import AdminResubmitImageWidget +from file_resubmit.widgets import ResubmitImageWidget from bookwyrm import models from .custom_form import CustomForm @@ -71,7 +71,7 @@ class EditionForm(CustomForm): "published_date": SelectDateWidget( attrs={"aria-describedby": "desc_published_date"} ), - "cover": AdminResubmitImageWidget(attrs={"aria-describedby": "desc_cover"}), + "cover": ResubmitImageWidget(attrs={"aria-describedby": "desc_cover"}), "physical_format": Select( attrs={"aria-describedby": "desc_physical_format"} ), diff --git a/requirements.txt b/requirements.txt index f63989e1f..cda7b1967 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ celery==5.2.7 colorthief==0.2.1 Django==3.2.20 django-celery-beat==2.4.0 -django-file-resubmit==0.5.2 +bw-file-resubmit==0.6.0rc2 django-compressor==4.3.1 django-imagekit==4.1.0 django-model-utils==4.3.1 From f3fc5f6179bb81496f9c23e5a3bb9ddf11642720 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 11 Nov 2023 12:45:04 +1100 Subject: [PATCH 4/4] add file_resubmit to DUMMY caches settings --- bookwyrm/settings.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 8c1841e2e..cb5a576a2 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -243,7 +243,11 @@ if env.bool("USE_DUMMY_CACHE", False): CACHES = { "default": { "BACKEND": "django.core.cache.backends.dummy.DummyCache", - } + }, + "file_resubmit": { + "BACKEND": "django.core.cache.backends.dummy.DummyCache", + "LOCATION": "/tmp/file_resubmit_tests/", + }, } else: CACHES = {