Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make tag browsing case-insensitive and unique #1807

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions monitor/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_monitor_queries_stats_ajax_error(self, mock_get):
resp = self.client.get(reverse('monitor-queries-stats-ajax'))

self.assertEqual(resp.status_code, 500)
mock_get.assert_called_with('http://graylog/graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)
mock_get.assert_called_with('http://graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)

@override_settings(GRAYLOG_DOMAIN='http://graylog')
@mock.patch('requests.get')
Expand All @@ -29,7 +29,7 @@ def test_monitor_queries_stats_ajax_bad_data(self, mock_get):
resp = self.client.get(reverse('monitor-queries-stats-ajax'))

self.assertEqual(resp.status_code, 500)
mock_get.assert_called_with('http://graylog/graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)
mock_get.assert_called_with('http://graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)

@override_settings(GRAYLOG_DOMAIN='http://graylog')
@mock.patch('requests.get')
Expand All @@ -43,4 +43,4 @@ def test_monitor_queries_stats_ajax_ok(self, mock_get):

self.assertEqual(resp.status_code, 200)
self.assertJSONEqual(resp.content, {'response': 'ok'})
mock_get.assert_called_with('http://graylog/graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)
mock_get.assert_called_with('http://graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)
4 changes: 2 additions & 2 deletions search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def search_view_helper(request):
request.user.profile.use_compact_mode = request_preference
request.user.profile.save()

# Parpare variables for map view (prepare some URLs for loading sounds and providing links to map)
# Prepare variables for map view (prepare some URLs for loading sounds and providing links to map)
open_in_map_url = None
map_mode_query_results_cache_key = None
map_bytearray_url = ''
Expand Down Expand Up @@ -152,7 +152,7 @@ def search_view_helper(request):
'tags_mode': sqp.tags_mode_active(),
'query_time': results.q_time
}))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit pick: Consider setting your editor to trim all trailing whitespace automatically or use a code formatter

# Compile template variables
return {
'sqp': sqp,
Expand Down
7 changes: 4 additions & 3 deletions tags/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@


def tags(request, multiple_tags=None):

if multiple_tags:
multiple_tags = multiple_tags.split('/')
else:
multiple_tags = []
multiple_tags = sorted([x for x in multiple_tags if x])
#Make all tags lower-cased and unique to get a case-insensitive search filter and shortened browse url
multiple_tags = sorted({x.lower() for x in multiple_tags if x})
if multiple_tags:
# We re-write tags as query filter and redirect
search_filter = "+".join('tag:"' + tag + '"' for tag in multiple_tags)
Expand All @@ -51,7 +52,7 @@ def tags(request, multiple_tags=None):
if pack_flt is not None:
# If username is passed as a GET parameter, add it as well to the filter
search_filter += f'+grouping_pack:{pack_flt}'

return HttpResponseRedirect(f"{reverse('tags')}?f={search_filter}")
else:
# Share same view code as for the search view, but "tags mode" will be on
Expand Down
Loading