From 424df155d8ba40302aee9f512c2c7743a390bdc7 Mon Sep 17 00:00:00 2001 From: acbgbca <60839662+acbgbca@users.noreply.github.com> Date: Tue, 30 May 2023 17:19:17 +1000 Subject: [PATCH] Allow passing title and description to new bookmark form (#479) * Added ability to set title and description #118 * Updated bookmarklet to pass site title #118 * Revert "Updated bookmarklet to pass site title #118" This reverts commit 873d90130bbb82f4eade926158cc726527a26d52. --- bookmarks/tests/test_bookmark_new_view.py | 19 +++++++++++++++++++ bookmarks/views/bookmarks.py | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/bookmarks/tests/test_bookmark_new_view.py b/bookmarks/tests/test_bookmark_new_view.py index 83ec706..eb416d9 100644 --- a/bookmarks/tests/test_bookmark_new_view.py +++ b/bookmarks/tests/test_bookmark_new_view.py @@ -75,6 +75,25 @@ class BookmarkNewViewTestCase(TestCase, BookmarkFactoryMixin): 'placeholder=" " autofocus class="form-input" required ' 'id="id_url">', html) + + def test_should_prefill_title_from_url_parameter(self): + response = self.client.get(reverse('bookmarks:new') + '?title=Example%20Title') + html = response.content.decode() + + self.assertInHTML( + '', + html) + + def test_should_prefill_description_from_url_parameter(self): + response = self.client.get(reverse('bookmarks:new') + '?description=Example%20Site%20Description') + html = response.content.decode() + + self.assertInHTML( + '', + html) def test_should_enable_auto_close_when_specified_in_url_parameter(self): response = self.client.get( diff --git a/bookmarks/views/bookmarks.py b/bookmarks/views/bookmarks.py index c11c9a9..b541a1e 100644 --- a/bookmarks/views/bookmarks.py +++ b/bookmarks/views/bookmarks.py @@ -114,6 +114,8 @@ def convert_tag_string(tag_string: str): @login_required def new(request): initial_url = request.GET.get('url') + initial_title = request.GET.get('title') + initial_description = request.GET.get('description') initial_auto_close = 'auto_close' in request.GET if request.method == 'POST': @@ -131,6 +133,10 @@ def new(request): form = BookmarkForm() if initial_url: form.initial['url'] = initial_url + if initial_title: + form.initial['title'] = initial_title + if initial_description: + form.initial['description'] = initial_description if initial_auto_close: form.initial['auto_close'] = 'true'