Bulk create HTML snapshots (#1132)

* Add option to create HTML snapshot for bulk edit

* Add the prerequisite for displaying the "Create HTML Snapshot" bulk action option

* Add test case

This test case covers the scenario where the bulk actions panel displays the corresponding options when the HTML snapshot feature is enabled.

* Use the existing `tasks.create_html_snapshots()` instead of the for loop

* Fix the exposure of `settings.LD_ENABLE_SNAPSHOTS` within `BookmarkListContext`

* add service tests

* cleanup context

---------

Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
This commit is contained in:
thR CIrcU5
2025-08-13 05:06:23 +08:00
committed by GitHub
parent aaa0f6e119
commit c746afcf76
7 changed files with 189 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
import urllib.parse
from django.contrib.auth.models import User
from django.test import TestCase
from django.test import TestCase, override_settings
from django.urls import reverse
from bookmarks.models import BookmarkSearch, UserProfile
@@ -319,6 +319,28 @@ class BookmarkArchivedViewTestCase(
html,
)
@override_settings(LD_ENABLE_SNAPSHOTS=True)
def test_allowed_bulk_actions_with_html_snapshot_enabled(self):
url = reverse("linkding:bookmarks.archived")
response = self.client.get(url)
html = response.content.decode()
self.assertInHTML(
f"""
<select name="bulk_action" class="form-select select-sm">
<option value="bulk_unarchive">Unarchive</option>
<option value="bulk_delete">Delete</option>
<option value="bulk_tag">Add tags</option>
<option value="bulk_untag">Remove tags</option>
<option value="bulk_read">Mark as read</option>
<option value="bulk_unread">Mark as unread</option>
<option value="bulk_refresh">Refresh from website</option>
<option value="bulk_snapshot">Create HTML snapshot</option>
</select>
""",
html,
)
def test_allowed_bulk_actions_with_sharing_enabled(self):
user_profile = self.user.profile
user_profile.enable_sharing = True
@@ -345,6 +367,34 @@ class BookmarkArchivedViewTestCase(
html,
)
@override_settings(LD_ENABLE_SNAPSHOTS=True)
def test_allowed_bulk_actions_with_sharing_and_html_snapshot_enabled(self):
user_profile = self.user.profile
user_profile.enable_sharing = True
user_profile.save()
url = reverse("linkding:bookmarks.archived")
response = self.client.get(url)
html = response.content.decode()
self.assertInHTML(
f"""
<select name="bulk_action" class="form-select select-sm">
<option value="bulk_unarchive">Unarchive</option>
<option value="bulk_delete">Delete</option>
<option value="bulk_tag">Add tags</option>
<option value="bulk_untag">Remove tags</option>
<option value="bulk_read">Mark as read</option>
<option value="bulk_unread">Mark as unread</option>
<option value="bulk_share">Share</option>
<option value="bulk_unshare">Unshare</option>
<option value="bulk_refresh">Refresh from website</option>
<option value="bulk_snapshot">Create HTML snapshot</option>
</select>
""",
html,
)
def test_apply_search_preferences(self):
# no params
response = self.client.post(reverse("linkding:bookmarks.archived"))