summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeXofLeviafan <lexofleviafan@gmail.com>2024-11-08 02:44:49 +0100
committerLeXofLeviafan <lexofleviafan@gmail.com>2024-11-08 02:45:02 +0100
commit2677eadce2788172c5ff60bfe89b633dc4bf33b2 (patch)
treef2c237af278d858ab0c96d565b05e351b9317d7b
parent48bf29e0f03b754c5d2810a101911e02708b277f (diff)
added support for all form parameters in bookmarklet endpoint
-rw-r--r--bukuserver/api.py4
-rw-r--r--bukuserver/templates/bukuserver/bookmark_create.html2
-rw-r--r--bukuserver/templates/bukuserver/bookmark_create_modal.html2
-rw-r--r--bukuserver/views.py4
-rw-r--r--tests/test_views.py12
5 files changed, 15 insertions, 9 deletions
diff --git a/bukuserver/api.py b/bukuserver/api.py
index b36e30a..d102abf 100644
--- a/bukuserver/api.py
+++ b/bukuserver/api.py
@@ -277,9 +277,11 @@ class BookmarkletView(MethodView): # pylint: disable=too-few-public-methods
url = request.args.get('url')
title = request.args.get('title')
description = request.args.get('description')
+ tags = request.args.get('tags')
+ fetch = request.args.get('fetch')
bukudb = getattr(flask.g, 'bukudb', get_bukudb())
rec_id = bukudb.get_rec_id(url)
if rec_id:
return redirect(url_for('bookmark.edit_view', id=rec_id))
- return redirect(url_for('bookmark.create_view', link=url, title=title, description=description))
+ return redirect(url_for('bookmark.create_view', link=url, title=title, description=description, tags=tags, fetch=fetch))
diff --git a/bukuserver/templates/bukuserver/bookmark_create.html b/bukuserver/templates/bukuserver/bookmark_create.html
index d344a27..d3fc5ec 100644
--- a/bukuserver/templates/bukuserver/bookmark_create.html
+++ b/bukuserver/templates/bukuserver/bookmark_create.html
@@ -6,7 +6,7 @@
{{ buku.set_lang() }}
{{ buku.limit_navigation_if_popup() }}
{{ buku.script('bookmark.js') }}
- {{ buku.fetch_checkbox() }}
+ {{ buku.fetch_checkbox(form.fetch.data) }}
{{ buku.focus() }}
{{ buku.link_saved() }}
{% endblock %}
diff --git a/bukuserver/templates/bukuserver/bookmark_create_modal.html b/bukuserver/templates/bukuserver/bookmark_create_modal.html
index 30c6e45..e263b2f 100644
--- a/bukuserver/templates/bukuserver/bookmark_create_modal.html
+++ b/bukuserver/templates/bukuserver/bookmark_create_modal.html
@@ -10,6 +10,6 @@
{% block tail %}
{{ super() }}
{{ buku.script('bookmark.js') }}
- {{ buku.fetch_checkbox() }}
+ {{ buku.fetch_checkbox(form.fetch.data) }}
{{ buku.focus('.modal-body') }}
{% endblock %}
diff --git a/bukuserver/views.py b/bukuserver/views.py
index 733de6e..3c9c1ee 100644
--- a/bukuserver/views.py
+++ b/bukuserver/views.py
@@ -209,11 +209,13 @@ class BookmarkModelView(BaseModelView, ApplyFiltersMixin):
form.url.data = request.args.get('link', form.url.data)
form.title.data = request.args.get('title', form.title.data)
form.description.data = request.args.get('description', form.description.data)
+ form.tags.data = request.args.get('tags', form.tags.data)
+ form.fetch.data = request.args.get('fetch', request.data.get('fetch', True))
return form
def create_model(self, form):
try:
- model = types.SimpleNamespace(id=None, url=None, title=None, tags=None, description=None, fetch=True)
+ model = types.SimpleNamespace(id=None, url=None, title=None, tags=None, description=None, fetch=None)
form.populate_obj(model)
vars(model).pop("id")
self._on_model_change(form, model, True)
diff --git a/tests/test_views.py b/tests/test_views.py
index 2434432..274a729 100644
--- a/tests/test_views.py
+++ b/tests/test_views.py
@@ -168,12 +168,14 @@ def test_bookmarklet_view(bukudb, client, exists, uri, tab, args):
(True, '', 'Some description'),
(False, 'Some title', ''),
(False, '', 'Some description'),
+ (None, 'Some title', ''),
+ (None, '', 'Some description'),
])
def test_create_and_fetch(bukudb, monkeypatch, client, fetch, title, desc):
query = {'link': 'http://example.com', 'title': title, 'description': desc, 'tags': 'foo, bar, baz'}
- _title, _desc = 'Sample site', 'Foo bar baz'
- if fetch:
- query['fetch'] = 'on'
+ _title, _desc = 'Fetched title', 'Fetched description'
+ if fetch is not None:
+ query['fetch'] = 'on' if fetch else ''
with mock_fetch(title=_title, desc=_desc):
response = client.post('/bookmark/new/', data=query, follow_redirects=True)
@@ -182,8 +184,8 @@ def test_create_and_fetch(bukudb, monkeypatch, client, fetch, title, desc):
[bookmark] = bukudb.get_rec_all()
assert_bookmark(bookmark, {
'link': query['link'], 'tags': ',bar,baz,foo,',
- 'title': (title or _title) if fetch else title,
- 'description': (desc or _desc) if fetch else desc,
+ 'title': (title or _title) if fetch or fetch is None else title, # defaults to True
+ 'description': (desc or _desc) if fetch or fetch is None else desc,
})