Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add User setting to set bookmark archive link in Bookmark list page to locally archived snapshot #902

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bookmarks/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,6 @@ class Meta:
"enable_favicons",
"display_url",
"permanent_notes",
"locally_archived_snapshot_link",
"search_preferences",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.1 on 2024-11-01 17:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("bookmarks", "0042_userprofile_custom_css_hash"),
]

operations = [
migrations.AddField(
model_name="userprofile",
name="locally_archived_snapshot_link",
field=models.BooleanField(default=False),
),
]
2 changes: 2 additions & 0 deletions bookmarks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ class UserProfile(models.Model):
display_archive_bookmark_action = models.BooleanField(default=True, null=False)
display_remove_bookmark_action = models.BooleanField(default=True, null=False)
permanent_notes = models.BooleanField(default=False, null=False)
locally_archived_snapshot_link = models.BooleanField(default=False, null=False)
custom_css = models.TextField(blank=True, null=False)
custom_css_hash = models.CharField(blank=True, null=False, max_length=32)
auto_tagging_rules = models.TextField(blank=True, null=False)
Expand Down Expand Up @@ -474,6 +475,7 @@ class Meta:
"display_archive_bookmark_action",
"display_remove_bookmark_action",
"permanent_notes",
"locally_archived_snapshot_link",
"default_mark_unread",
"custom_css",
"auto_tagging_rules",
Expand Down
9 changes: 8 additions & 1 deletion bookmarks/templates/bookmarks/bookmark_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@
{% endif %}
<div class="actions">
{% if bookmark_item.display_date %}
{% if bookmark_item.web_archive_snapshot_url %}
{% if bookmark_item.show_locally_archived_link and bookmark_item.local_snapshot_url %}
<a href="{{ bookmark_item.local_snapshot_url }}/read"
title="View local snapshot"
target="{{ bookmark_list.link_target }}"
rel="noopener">
{{ bookmark_item.display_date }}
</a>
{% elif bookmark_item.web_archive_snapshot_url %}
<a href="{{ bookmark_item.web_archive_snapshot_url }}"
title="Show snapshot on the Internet Archive Wayback Machine"
target="{{ bookmark_list.link_target }}"
Expand Down
10 changes: 10 additions & 0 deletions bookmarks/templates/settings/general.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ <h2>Profile</h2>
Alternatively the keyboard shortcut <code>e</code> can be used to temporarily show all notes.
</div>
</div>
<div class="form-group">
<label for="{{ form.locally_archived_snapshot_link.id_for_label }}" class="form-checkbox">
{{ form.locally_archived_snapshot_link }}
<i class="form-icon"></i> Set bookmark archive link to locally archived snapshot
</label>
<div class="form-input-hint">
When enabled, the bookmark archive link sets to the most recent locally archived snapshot.
By default, it will set to the Web Archive link.
</div>
</div>
<div class="form-group">
<label class="form-label">Bookmark actions</label>
<label for="{{ form.display_view_bookmark_action.id_for_label }}" class="form-checkbox">
Expand Down
2 changes: 2 additions & 0 deletions bookmarks/tests/test_bookmarks_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ def assertUserProfile(self, response: Response, profile: UserProfile):
self.assertEqual(response.data["enable_favicons"], profile.enable_favicons)
self.assertEqual(response.data["display_url"], profile.display_url)
self.assertEqual(response.data["permanent_notes"], profile.permanent_notes)
self.assertEqual(response.data["locally_archived_snapshot_link"], profile.locally_archived_snapshot_link)
self.assertEqual(
response.data["search_preferences"], profile.search_preferences
)
Expand All @@ -1096,6 +1097,7 @@ def test_user_profile(self):
profile.enable_favicons = True
profile.display_url = True
profile.permanent_notes = True
profile.locally_archived_snapshot_link = True
profile.search_preferences = {
"sort": BookmarkSearch.SORT_TITLE_ASC,
"shared": BookmarkSearch.FILTER_SHARED_OFF,
Expand Down
5 changes: 5 additions & 0 deletions bookmarks/tests/test_settings_general_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def create_profile_form_data(self, overrides=None):
"display_archive_bookmark_action": True,
"display_remove_bookmark_action": True,
"permanent_notes": False,
"locally_archived_snapshot_link": False,
"custom_css": "",
"auto_tagging_rules": "",
"items_per_page": "30",
Expand Down Expand Up @@ -112,6 +113,7 @@ def test_update_profile(self):
"display_archive_bookmark_action": False,
"display_remove_bookmark_action": False,
"permanent_notes": True,
"locally_archived_snapshot_link": True,
"default_mark_unread": True,
"custom_css": "body { background-color: #000; }",
"auto_tagging_rules": "example.com tag",
Expand Down Expand Up @@ -181,6 +183,9 @@ def test_update_profile(self):
self.assertEqual(
self.user.profile.permanent_notes, form_data["permanent_notes"]
)
self.assertEqual(
self.user.profile.locally_archived_snapshot_link, form_data["locally_archived_snapshot_link"]
)
self.assertEqual(
self.user.profile.default_mark_unread, form_data["default_mark_unread"]
)
Expand Down
6 changes: 6 additions & 0 deletions bookmarks/views/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ def __init__(
self.owner = bookmark.owner
self.details_url = context.details(bookmark.id)

assets = list(bookmark.bookmarkasset_set.filter(status=BookmarkAsset.STATUS_COMPLETE))
if assets:
latest_snapshot = assets[0]
self.local_snapshot_url = reverse('bookmarks:assets.view', args=[latest_snapshot.id])

css_classes = []
if bookmark.unread:
css_classes.append("unread")
Expand All @@ -159,6 +164,7 @@ def __init__(
self.show_notes_button = bookmark.notes and not profile.permanent_notes
self.show_mark_as_read = is_editable and bookmark.unread
self.show_unshare = is_editable and bookmark.shared and profile.enable_sharing
self.show_locally_archived_link = profile.locally_archived_snapshot_link

self.has_extra_actions = (
self.show_notes_button or self.show_mark_as_read or self.show_unshare
Expand Down