From b09ea26d6621a4cbd5de9cae1b5877272a1048f1 Mon Sep 17 00:00:00 2001 From: John Bintz <27256+johnbintz@users.noreply.github.com> Date: Fri, 8 Jan 2021 18:40:43 -0500 Subject: [PATCH] Add !untagged search to find untagged bookmarks * Add .nvmrc file for easier Node development environment setup --- .nvmrc | 1 + bookmarks/queries.py | 18 +++++++++++++++--- bookmarks/templates/bookmarks/tag_cloud.html | 2 ++ package-lock.json | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..8351c19 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +14 diff --git a/bookmarks/queries.py b/bookmarks/queries.py index bcce913..06652c6 100644 --- a/bookmarks/queries.py +++ b/bookmarks/queries.py @@ -40,11 +40,20 @@ def query_bookmarks(user: User, query_string: str): | Q(url__contains=term) ) - for tag_name in query['tag_names']: + if 'untagged' in query['special_searches']: + print(query_set) + query_set = query_set.filter( - tags__name__iexact=tag_name + tags=None ) + print(query_set) + else: + for tag_name in query['tag_names']: + query_set = query_set.filter( + tags__name__iexact=tag_name + ) + # Sort by modification date query_set = query_set.order_by('-date_modified') @@ -94,11 +103,14 @@ def _parse_query_string(query_string): keywords = query_string.strip().split(' ') keywords = [word for word in keywords if word] - search_terms = [word for word in keywords if word[0] != '#'] + search_terms = [word for word in keywords if (word[0] != '#' and word[0] != "!")] tag_names = [word[1:] for word in keywords if word[0] == '#'] tag_names = unique(tag_names, str.lower) + special_searches = [word[1:] for word in keywords if word[0] == "!"] + return { 'search_terms': search_terms, 'tag_names': tag_names, + 'special_searches': special_searches } diff --git a/bookmarks/templates/bookmarks/tag_cloud.html b/bookmarks/templates/bookmarks/tag_cloud.html index f15d8e2..2276a54 100644 --- a/bookmarks/templates/bookmarks/tag_cloud.html +++ b/bookmarks/templates/bookmarks/tag_cloud.html @@ -20,4 +20,6 @@ {% endfor %}
{% endfor %} +