Skip to content

Commit

Permalink
Added ability to set title and description sissbruecker#118
Browse files Browse the repository at this point in the history
  • Loading branch information
acbgbca committed May 30, 2023
1 parent d87611d commit d2a9501
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions bookmarks/tests/test_bookmark_new_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ def test_should_prefill_url_from_url_parameter(self):
'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(
'<input type="text" name="title" value="Example Title" '
'class="form-input" maxlength="512" autocomplete="off" '
'id="id_title">',
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(
'<textarea name="description" class="form-input" cols="40" '
'rows="2" id="id_description">Example Site Description</textarea>',
html)

def test_should_enable_auto_close_when_specified_in_url_parameter(self):
response = self.client.get(
Expand Down
6 changes: 6 additions & 0 deletions bookmarks/views/bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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'

Expand Down

0 comments on commit d2a9501

Please sign in to comment.