mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-08 03:08:29 +02:00
Load missing thumbnails after enabling the feature (#725)
This commit is contained in:
@@ -245,7 +245,7 @@ def _load_preview_image_task(bookmark_id: int):
|
|||||||
new_preview_image_file = preview_image_loader.load_preview_image(bookmark.url)
|
new_preview_image_file = preview_image_loader.load_preview_image(bookmark.url)
|
||||||
|
|
||||||
if new_preview_image_file != bookmark.preview_image_file:
|
if new_preview_image_file != bookmark.preview_image_file:
|
||||||
bookmark.preview_image_file = new_preview_image_file
|
bookmark.preview_image_file = new_preview_image_file or ""
|
||||||
bookmark.save(update_fields=["preview_image_file"])
|
bookmark.save(update_fields=["preview_image_file"])
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Successfully updated preview image for bookmark. url={bookmark.url} preview_image_file={new_preview_image_file}"
|
f"Successfully updated preview image for bookmark. url={bookmark.url} preview_image_file={new_preview_image_file}"
|
||||||
|
@@ -117,6 +117,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<div class="form-input-hint">
|
<div class="form-input-hint">
|
||||||
Automatically loads favicons for bookmarked websites and displays them next to each bookmark.
|
Automatically loads favicons for bookmarked websites and displays them next to each bookmark.
|
||||||
|
Enabling this feature automatically downloads all missing favicons.
|
||||||
By default, this feature uses a <b>Google service</b> to download favicons.
|
By default, this feature uses a <b>Google service</b> to download favicons.
|
||||||
If you don't want to use this service, check the <a
|
If you don't want to use this service, check the <a
|
||||||
href="https://github.com/sissbruecker/linkding/blob/master/docs/Options.md#ld_favicon_provider"
|
href="https://github.com/sissbruecker/linkding/blob/master/docs/Options.md#ld_favicon_provider"
|
||||||
@@ -134,6 +135,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<div class="form-input-hint">
|
<div class="form-input-hint">
|
||||||
Automatically loads preview images for bookmarked websites and displays them next to each bookmark.
|
Automatically loads preview images for bookmarked websites and displays them next to each bookmark.
|
||||||
|
Enabling this feature automatically downloads all missing preview images.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@@ -537,6 +537,19 @@ class BookmarkTasksTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.mock_load_preview_image.assert_called_once()
|
self.mock_load_preview_image.assert_called_once()
|
||||||
self.assertEqual(bookmark.preview_image_file, "preview_image_upd.png")
|
self.assertEqual(bookmark.preview_image_file, "preview_image_upd.png")
|
||||||
|
|
||||||
|
def test_load_preview_image_should_set_blank_when_none_is_returned(self):
|
||||||
|
bookmark = self.setup_bookmark(
|
||||||
|
preview_image_file="preview_image.png",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.mock_load_preview_image.return_value = None
|
||||||
|
|
||||||
|
tasks.load_preview_image(self.get_or_create_test_user(), bookmark)
|
||||||
|
|
||||||
|
bookmark.refresh_from_db()
|
||||||
|
self.mock_load_preview_image.assert_called_once()
|
||||||
|
self.assertEqual(bookmark.preview_image_file, "")
|
||||||
|
|
||||||
def test_load_preview_image_should_handle_missing_bookmark(self):
|
def test_load_preview_image_should_handle_missing_bookmark(self):
|
||||||
tasks._load_preview_image_task(123)
|
tasks._load_preview_image_task(123)
|
||||||
|
|
||||||
|
@@ -31,6 +31,7 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
"enable_sharing": False,
|
"enable_sharing": False,
|
||||||
"enable_public_sharing": False,
|
"enable_public_sharing": False,
|
||||||
"enable_favicons": False,
|
"enable_favicons": False,
|
||||||
|
"enable_preview_images": False,
|
||||||
"enable_automatic_html_snapshots": True,
|
"enable_automatic_html_snapshots": True,
|
||||||
"tag_search": UserProfile.TAG_SEARCH_STRICT,
|
"tag_search": UserProfile.TAG_SEARCH_STRICT,
|
||||||
"display_url": False,
|
"display_url": False,
|
||||||
@@ -88,6 +89,7 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
"enable_sharing": True,
|
"enable_sharing": True,
|
||||||
"enable_public_sharing": True,
|
"enable_public_sharing": True,
|
||||||
"enable_favicons": True,
|
"enable_favicons": True,
|
||||||
|
"enable_preview_images": True,
|
||||||
"enable_automatic_html_snapshots": False,
|
"enable_automatic_html_snapshots": False,
|
||||||
"tag_search": UserProfile.TAG_SEARCH_LAX,
|
"tag_search": UserProfile.TAG_SEARCH_LAX,
|
||||||
"display_url": True,
|
"display_url": True,
|
||||||
@@ -131,6 +133,9 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.user.profile.enable_favicons, form_data["enable_favicons"]
|
self.user.profile.enable_favicons, form_data["enable_favicons"]
|
||||||
)
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
self.user.profile.enable_preview_images, form_data["enable_preview_images"]
|
||||||
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.user.profile.enable_automatic_html_snapshots,
|
self.user.profile.enable_automatic_html_snapshots,
|
||||||
form_data["enable_automatic_html_snapshots"],
|
form_data["enable_automatic_html_snapshots"],
|
||||||
@@ -291,6 +296,39 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
count=0,
|
count=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_enable_preview_image_should_schedule_preview_update(self):
|
||||||
|
with patch.object(
|
||||||
|
tasks, "schedule_bookmarks_without_previews"
|
||||||
|
) as mock_schedule_bookmarks_without_previews:
|
||||||
|
# Enabling favicons schedules update
|
||||||
|
form_data = self.create_profile_form_data(
|
||||||
|
{
|
||||||
|
"update_profile": "",
|
||||||
|
"enable_preview_images": True,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.client.post(reverse("bookmarks:settings.general"), form_data)
|
||||||
|
|
||||||
|
mock_schedule_bookmarks_without_previews.assert_called_once_with(self.user)
|
||||||
|
|
||||||
|
# No update scheduled if favicons are already enabled
|
||||||
|
mock_schedule_bookmarks_without_previews.reset_mock()
|
||||||
|
|
||||||
|
self.client.post(reverse("bookmarks:settings.general"), form_data)
|
||||||
|
|
||||||
|
mock_schedule_bookmarks_without_previews.assert_not_called()
|
||||||
|
|
||||||
|
# No update scheduled when disabling favicons
|
||||||
|
form_data = self.create_profile_form_data(
|
||||||
|
{
|
||||||
|
"enable_preview_images": False,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.client.post(reverse("bookmarks:settings.general"), form_data)
|
||||||
|
|
||||||
|
mock_schedule_bookmarks_without_previews.assert_not_called()
|
||||||
|
|
||||||
def test_automatic_html_snapshots_should_be_hidden_when_snapshots_not_supported(
|
def test_automatic_html_snapshots_should_be_hidden_when_snapshots_not_supported(
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
|
@@ -70,11 +70,16 @@ def update_profile(request):
|
|||||||
user = request.user
|
user = request.user
|
||||||
profile = user.profile
|
profile = user.profile
|
||||||
favicons_were_enabled = profile.enable_favicons
|
favicons_were_enabled = profile.enable_favicons
|
||||||
|
previews_were_enabled = profile.enable_preview_images
|
||||||
form = UserProfileForm(request.POST, instance=profile)
|
form = UserProfileForm(request.POST, instance=profile)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
|
# Load missing favicons if the feature was just enabled
|
||||||
if profile.enable_favicons and not favicons_were_enabled:
|
if profile.enable_favicons and not favicons_were_enabled:
|
||||||
tasks.schedule_bookmarks_without_favicons(request.user)
|
tasks.schedule_bookmarks_without_favicons(request.user)
|
||||||
|
# Load missing preview images if the feature was just enabled
|
||||||
|
if profile.enable_preview_images and not previews_were_enabled:
|
||||||
|
tasks.schedule_bookmarks_without_previews(request.user)
|
||||||
return form
|
return form
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user