mirror of
https://github.com/sissbruecker/linkding
synced 2025-02-16 12:28:23 +00:00
Add option for marking bookmarks as unread by default (#706)
* Added new option to set Mark as unread with a default * Added additional test * tweak test a bit --------- Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
This commit is contained in:
parent
a1822e2091
commit
9dc3521d5e
6 changed files with 60 additions and 0 deletions
18
bookmarks/migrations/0033_userprofile_default_mark_unread.py
Normal file
18
bookmarks/migrations/0033_userprofile_default_mark_unread.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 5.0.3 on 2024-04-17 19:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("bookmarks", "0032_html_snapshots_hint_toast"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="userprofile",
|
||||||
|
name="default_mark_unread",
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
|
@ -399,6 +399,7 @@ class UserProfile(models.Model):
|
||||||
custom_css = models.TextField(blank=True, null=False)
|
custom_css = models.TextField(blank=True, null=False)
|
||||||
search_preferences = models.JSONField(default=dict, null=False)
|
search_preferences = models.JSONField(default=dict, null=False)
|
||||||
enable_automatic_html_snapshots = models.BooleanField(default=True, null=False)
|
enable_automatic_html_snapshots = models.BooleanField(default=True, null=False)
|
||||||
|
default_mark_unread = models.BooleanField(default=False, null=False)
|
||||||
|
|
||||||
|
|
||||||
class UserProfileForm(forms.ModelForm):
|
class UserProfileForm(forms.ModelForm):
|
||||||
|
@ -422,6 +423,7 @@ class UserProfileForm(forms.ModelForm):
|
||||||
"display_archive_bookmark_action",
|
"display_archive_bookmark_action",
|
||||||
"display_remove_bookmark_action",
|
"display_remove_bookmark_action",
|
||||||
"permanent_notes",
|
"permanent_notes",
|
||||||
|
"default_mark_unread",
|
||||||
"custom_css",
|
"custom_css",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -175,6 +175,17 @@
|
||||||
<button class="btn mt-2" name="create_missing_html_snapshots">Create missing HTML snapshots</button>
|
<button class="btn mt-2" name="create_missing_html_snapshots">Create missing HTML snapshots</button>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="{{ form.default_mark_unread.id_for_label }}" class="form-checkbox">
|
||||||
|
{{ form.default_mark_unread }}
|
||||||
|
<i class="form-icon"></i> Create bookmarks as unread by default
|
||||||
|
</label>
|
||||||
|
<div class="form-input-hint">
|
||||||
|
Sets the default state for the "Mark as unread" option when creating a new bookmark.
|
||||||
|
Setting this option will make all new bookmarks default to unread.
|
||||||
|
This can be overridden when creating each new bookmark.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<details {% if form.custom_css.value %}open{% endif %}>
|
<details {% if form.custom_css.value %}open{% endif %}>
|
||||||
<summary>Custom CSS</summary>
|
<summary>Custom CSS</summary>
|
||||||
|
|
|
@ -210,3 +210,25 @@ class BookmarkNewViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||||
response = self.client.get(reverse("bookmarks:edit", args=[bookmark.id]))
|
response = self.client.get(reverse("bookmarks:edit", args=[bookmark.id]))
|
||||||
|
|
||||||
self.assertContains(response, '<details class="notes">', count=1)
|
self.assertContains(response, '<details class="notes">', count=1)
|
||||||
|
|
||||||
|
def test_should_not_check_unread_by_default(self):
|
||||||
|
response = self.client.get(reverse("bookmarks:new"))
|
||||||
|
html = response.content.decode()
|
||||||
|
|
||||||
|
self.assertInHTML(
|
||||||
|
'<input type="checkbox" name="unread" id="id_unread">',
|
||||||
|
html,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_should_check_unread_when_configured_in_profile(self):
|
||||||
|
self.user.profile.default_mark_unread = True
|
||||||
|
self.user.profile.save()
|
||||||
|
|
||||||
|
response = self.client.get(reverse("bookmarks:new"))
|
||||||
|
html = response.content.decode()
|
||||||
|
|
||||||
|
self.assertInHTML(
|
||||||
|
'<input type="checkbox" name="unread" value="true" '
|
||||||
|
'id="id_unread" checked="">',
|
||||||
|
html,
|
||||||
|
)
|
||||||
|
|
|
@ -96,6 +96,7 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||||
"display_archive_bookmark_action": False,
|
"display_archive_bookmark_action": False,
|
||||||
"display_remove_bookmark_action": False,
|
"display_remove_bookmark_action": False,
|
||||||
"permanent_notes": True,
|
"permanent_notes": True,
|
||||||
|
"default_mark_unread": True,
|
||||||
"custom_css": "body { background-color: #000; }",
|
"custom_css": "body { background-color: #000; }",
|
||||||
}
|
}
|
||||||
response = self.client.post(reverse("bookmarks:settings.general"), form_data)
|
response = self.client.post(reverse("bookmarks:settings.general"), form_data)
|
||||||
|
@ -155,6 +156,9 @@ class SettingsGeneralViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.user.profile.permanent_notes, form_data["permanent_notes"]
|
self.user.profile.permanent_notes, form_data["permanent_notes"]
|
||||||
)
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
self.user.profile.default_mark_unread, form_data["default_mark_unread"]
|
||||||
|
)
|
||||||
self.assertEqual(self.user.profile.custom_css, form_data["custom_css"])
|
self.assertEqual(self.user.profile.custom_css, form_data["custom_css"])
|
||||||
self.assertSuccessMessage(html, "Profile updated")
|
self.assertSuccessMessage(html, "Profile updated")
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,7 @@ def new(request):
|
||||||
initial_title = request.GET.get("title")
|
initial_title = request.GET.get("title")
|
||||||
initial_description = request.GET.get("description")
|
initial_description = request.GET.get("description")
|
||||||
initial_auto_close = "auto_close" in request.GET
|
initial_auto_close = "auto_close" in request.GET
|
||||||
|
initial_mark_unread = request.user.profile.default_mark_unread
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = BookmarkForm(request.POST)
|
form = BookmarkForm(request.POST)
|
||||||
|
@ -210,6 +211,8 @@ def new(request):
|
||||||
form.initial["description"] = initial_description
|
form.initial["description"] = initial_description
|
||||||
if initial_auto_close:
|
if initial_auto_close:
|
||||||
form.initial["auto_close"] = "true"
|
form.initial["auto_close"] = "true"
|
||||||
|
if initial_mark_unread:
|
||||||
|
form.initial["unread"] = "true"
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"form": form,
|
"form": form,
|
||||||
|
|
Loading…
Add table
Reference in a new issue