From ff68d2591fed4663eb74f8b02d7e1a803c20e848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Sun, 30 Jun 2019 19:54:33 +0200 Subject: [PATCH] Implement tag search --- bookmarks/queries.py | 22 +++++++++++++------- bookmarks/styles/bookmarks.scss | 7 +++++++ bookmarks/templates/bookmarks/index.html | 6 +++--- bookmarks/templates/bookmarks/tag_cloud.html | 2 +- bookmarks/templatetags/shared.py | 5 +++++ 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/bookmarks/queries.py b/bookmarks/queries.py index 3f659b3..5a29cce 100644 --- a/bookmarks/queries.py +++ b/bookmarks/queries.py @@ -29,17 +29,25 @@ def query_bookmarks(user: User, query_string: str): # Filter for user query_set = query_set.filter(owner=user) - # Split query into keywords + # Split query into search terms and tags keywords = query_string.strip().split(' ') keywords = [word for word in keywords if word] - # Filter for each keyword - for word in keywords: + search_terms = [word for word in keywords if word[0] != '#'] + tag_names = [word[1:] for word in keywords if word[0] == '#'] + + # Filter for search terms and tags + for term in search_terms: query_set = query_set.filter( - Q(title__contains=word) - | Q(description__contains=word) - | Q(website_title__contains=word) - | Q(website_description__contains=word) + Q(title__contains=term) + | Q(description__contains=term) + | Q(website_title__contains=term) + | Q(website_description__contains=term) + ) + + for tag_name in tag_names: + query_set = query_set.filter( + tags__name=tag_name ) # Sort by modification date diff --git a/bookmarks/styles/bookmarks.scss b/bookmarks/styles/bookmarks.scss index 3ea3055..7f3c456 100644 --- a/bookmarks/styles/bookmarks.scss +++ b/bookmarks/styles/bookmarks.scss @@ -1,3 +1,10 @@ +.bookmarks-page { + + .search input[type=search] { + width: 200px; + } +} + ul.bookmark-list { list-style: none; diff --git a/bookmarks/templates/bookmarks/index.html b/bookmarks/templates/bookmarks/index.html index 86eabe8..29c2f09 100644 --- a/bookmarks/templates/bookmarks/index.html +++ b/bookmarks/templates/bookmarks/index.html @@ -3,7 +3,7 @@ {% load bookmarks %} {% block content %} -
+
{# Bookmark list #}
@@ -13,7 +13,7 @@