Skip to content

Commit b304863

Browse files
authored
Allow pre-filling notes in new bookmark form (sissbruecker#812)
1 parent 1c6e590 commit b304863

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

bookmarks/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ class Meta:
169169

170170
@property
171171
def has_notes(self):
172-
return self.instance and self.instance.notes
172+
return self.initial.get("notes", None) or (
173+
self.instance and self.instance.notes
174+
)
173175

174176

175177
class BookmarkSearch:

bookmarks/tests/test_bookmark_new_view.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,29 @@ def test_should_prefill_description_from_url_parameter(self):
100100
html,
101101
)
102102

103+
def test_should_prefill_notes_from_url_parameter(self):
104+
response = self.client.get(
105+
reverse("bookmarks:new")
106+
+ "?notes=%2A%2AFind%2A%2A%20more%20info%20%5Bhere%5D%28http%3A%2F%2Fexample.com%29"
107+
)
108+
html = response.content.decode()
109+
110+
self.assertInHTML(
111+
"""
112+
<details class="notes" open="">
113+
<summary>
114+
<span class="form-label d-inline-block">Notes</span>
115+
</summary>
116+
<label for="id_notes" class="text-assistive">Notes</label>
117+
<textarea name="notes" cols="40" rows="8" class="form-input" id="id_notes">**Find** more info [here](http://example.com)</textarea>
118+
<div class="form-input-hint">
119+
Additional notes, supports Markdown.
120+
</div>
121+
</details>
122+
""",
123+
html,
124+
)
125+
103126
def test_should_enable_auto_close_when_specified_in_url_parameter(self):
104127
response = self.client.get(reverse("bookmarks:new") + "?auto_close")
105128
html = response.content.decode()

bookmarks/views/bookmarks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def new(request):
192192
initial_url = request.GET.get("url")
193193
initial_title = request.GET.get("title")
194194
initial_description = request.GET.get("description")
195+
initial_notes = request.GET.get("notes")
195196
initial_auto_close = "auto_close" in request.GET
196197
initial_mark_unread = request.user.profile.default_mark_unread
197198

@@ -214,6 +215,8 @@ def new(request):
214215
form.initial["title"] = initial_title
215216
if initial_description:
216217
form.initial["description"] = initial_description
218+
if initial_notes:
219+
form.initial["notes"] = initial_notes
217220
if initial_auto_close:
218221
form.initial["auto_close"] = "true"
219222
if initial_mark_unread:

0 commit comments

Comments
 (0)