From f26fbc0dc50bac0848d69981e0468f815cdff625 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Nov 2021 17:14:11 +0700 Subject: [PATCH] implement show_subed_only on playlist view --- tubearchivist/home/views.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index b2e0ad3..2631b7e 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -732,7 +732,7 @@ class PlaylistView(View): ) url = view_config["es_url"] + "/ta_playlist/_search" - data = self.build_data(pagination_handler, search_get) + data = self.build_data(pagination_handler, search_get, view_config) search = SearchHandler(url, data) playlist_hits = search.get_data() pagination_handler.validate(search.max_hits) @@ -742,6 +742,7 @@ class PlaylistView(View): "search_form": search_form, "title": "Playlists", "colors": view_config["colors"], + "show_subed_only": view_config["show_subed_only"], "pagination": pagination_handler.pagination, "playlists": playlist_hits, "view_style": view_config["view_style"], @@ -749,7 +750,7 @@ class PlaylistView(View): return render(request, "home/playlist.html", context) @staticmethod - def build_data(pagination_handler, search_get): + def build_data(pagination_handler, search_get, view_config): """build data object for query""" data = { "size": pagination_handler.pagination["page_size"], @@ -759,6 +760,8 @@ class PlaylistView(View): }, "sort": [{"playlist_name.keyword": {"order": "asc"}}], } + if view_config["show_subed_only"]: + data["query"] = {"term": {"playlist_subscribed": {"value": True}}} if search_get: data["query"] = { "bool": { @@ -791,10 +794,14 @@ class PlaylistView(View): if not view_style: view_style = config_handler.config["default_view"]["channel"] + sub_only_key = f"{user_id}:show_subed_only" + show_subed_only = RedisArchivist().get_message(sub_only_key)["status"] + view_config = { "es_url": config_handler.config["application"]["es_url"], "colors": config_handler.colors, "view_style": view_style, + "show_subed_only": show_subed_only, } return view_config