#23 Prevent bookmark duplicates

* Show hint if URL is already bookmarked

* Remove hint if URL belongs to edited bookmark

* Fix query param encoding

* Update bookmark instead of duplicating it

Co-authored-by: Sascha Ißbrücker <sissbruecker@lyska.io>
This commit is contained in:
Sascha Ißbrücker
2020-09-13 08:46:07 +02:00
committed by GitHub
parent 10fd3d89be
commit 348a536aa3
8 changed files with 67 additions and 14 deletions

View File

@@ -7,6 +7,14 @@ from bookmarks.services.website_loader import load_website_metadata
def create_bookmark(form: BookmarkForm, current_user: User):
# If URL is already bookmarked, then update it
existing_bookmark = Bookmark.objects.filter(owner=current_user, url=form.data['url']).first()
if existing_bookmark is not None:
update_form = BookmarkForm(data=form.data, instance=existing_bookmark)
update_bookmark(update_form, current_user)
return
bookmark = form.save(commit=False)
# Update website info
_update_website_metadata(bookmark)