send playlist hits to template

This commit is contained in:
simon 2021-11-10 17:29:11 +07:00
parent eaf107d0d2
commit 2550016ac8
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -548,17 +548,44 @@ class PlaylistView(View):
def get(self, request): def get(self, request):
"""handle http get requests""" """handle http get requests"""
view_config = self.read_config(user_id=request.user.id) user_id = request.user.id
context = {"title": "Playlists", "colors": view_config["colors"]} view_config = self.read_config(user_id=user_id)
page_get = int(request.GET.get("page", 0))
pagination_handler = Pagination(page_get, user_id)
url = view_config["es_url"] + "/ta_playlist/_search"
data = {
"size": pagination_handler.pagination["page_size"],
"from": pagination_handler.pagination["page_from"],
"query": {"match_all": {}},
"sort": [{"playlist_name.keyword": {"order": "asc"}}],
}
search = SearchHandler(url, data)
playlist_hits = search.get_data()
pagination_handler.validate(search.max_hits)
context = {
"title": "Playlists",
"colors": view_config["colors"],
"pagination": pagination_handler.pagination,
"playlists": playlist_hits,
"view_style": view_config["view_style"],
}
return render(request, "home/playlist.html", context) return render(request, "home/playlist.html", context)
@staticmethod @staticmethod
def read_config(user_id): def read_config(user_id):
"""read config file""" """read config file"""
config_handler = AppConfig(user_id) config_handler = AppConfig(user_id)
view_key = f"{user_id}:view:playlist"
view_style = RedisArchivist().get_message(view_key)["status"]
if not view_style:
view_style = config_handler.config["default_view"]["channel"]
view_config = { view_config = {
"es_url": config_handler.config["application"]["es_url"], "es_url": config_handler.config["application"]["es_url"],
"colors": config_handler.colors, "colors": config_handler.colors,
"view_style": view_style,
} }
return view_config return view_config