Allow pre-filling tags in new bookmark form (#1060)

* feat - Allow tag_string as query for BookmarkForm in order to set tags via bookmark snippets

* add test

---------

Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
This commit is contained in:
Bastian
2025-05-17 10:13:07 +02:00
committed by GitHub
parent 9a00ae4b93
commit f2800efc1a
2 changed files with 14 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ class BookmarkForm(forms.ModelForm):
"title": request.GET.get("title"), "title": request.GET.get("title"),
"description": request.GET.get("description"), "description": request.GET.get("description"),
"notes": request.GET.get("notes"), "notes": request.GET.get("notes"),
"tag_string": request.GET.get("tags"),
"auto_close": "auto_close" in request.GET, "auto_close": "auto_close" in request.GET,
"unread": request.user_profile.default_mark_unread, "unread": request.user_profile.default_mark_unread,
} }

View File

@@ -110,6 +110,19 @@ class BookmarkNewViewTestCase(TestCase, BookmarkFactoryMixin):
html, html,
) )
def test_should_prefill_tags_from_url_parameter(self):
response = self.client.get(
reverse("linkding:bookmarks.new") + "?tags=tag1%20tag2%20tag3"
)
html = response.content.decode()
self.assertInHTML(
'<input type="text" name="tag_string" value="tag1 tag2 tag3" '
'class="form-input" autocomplete="off" autocapitalize="off" '
'id="id_tag_string">',
html,
)
def test_should_prefill_notes_from_url_parameter(self): def test_should_prefill_notes_from_url_parameter(self):
response = self.client.get( response = self.client.get(
reverse("linkding:bookmarks.new") reverse("linkding:bookmarks.new")