mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 11:50:14 +00:00
use original sort order for playlist_id list
This commit is contained in:
parent
b9ddf6a299
commit
e3f0075132
@ -594,18 +594,22 @@ class PlaylistIdView(View):
|
||||
page_get = int(request.GET.get("page", 0))
|
||||
pagination_handler = Pagination(page_get, request.user.id)
|
||||
# get data
|
||||
playlist_info = self.get_playlist_info(
|
||||
playlist_id_detail, view_config["es_url"]
|
||||
)
|
||||
sort = {
|
||||
i["youtube_id"]: i["idx"]
|
||||
for i in playlist_info["playlist_entries"]
|
||||
}
|
||||
playlist_name = playlist_info["playlist_name"]
|
||||
url = view_config["es_url"] + "/ta_video/_search"
|
||||
data = self.build_data(
|
||||
pagination_handler, playlist_id_detail, view_config
|
||||
pagination_handler, playlist_id_detail, view_config, sort
|
||||
)
|
||||
|
||||
search = SearchHandler(url, data)
|
||||
videos_hits = search.get_data()
|
||||
max_hits = search.max_hits
|
||||
playlist_info = self.get_playlist_info(
|
||||
playlist_id_detail, view_config["es_url"]
|
||||
)
|
||||
playlist_name = playlist_info["playlist_name"]
|
||||
|
||||
if max_hits:
|
||||
source = videos_hits[0]["source"]
|
||||
@ -632,10 +636,9 @@ class PlaylistIdView(View):
|
||||
return context
|
||||
|
||||
@staticmethod
|
||||
def build_data(pagination_handler, playlist_id_detail, view_config):
|
||||
def build_data(pagination_handler, playlist_id_detail, view_config, sort):
|
||||
"""build data query for es"""
|
||||
sort_by = view_config["sort_by"]
|
||||
sort_order = view_config["sort_order"]
|
||||
|
||||
# overwrite sort_by to match key
|
||||
if sort_by == "views":
|
||||
@ -645,6 +648,12 @@ class PlaylistIdView(View):
|
||||
elif sort_by == "downloaded":
|
||||
sort_by = "date_downloaded"
|
||||
|
||||
script = (
|
||||
"if(params.scores.containsKey(doc['youtube_id'].value)) "
|
||||
+ "{return params.scores[doc['youtube_id'].value];} "
|
||||
+ "return 100000;"
|
||||
)
|
||||
|
||||
data = {
|
||||
"size": pagination_handler.pagination["page_size"],
|
||||
"from": pagination_handler.pagination["page_from"],
|
||||
@ -655,7 +664,19 @@ class PlaylistIdView(View):
|
||||
]
|
||||
}
|
||||
},
|
||||
"sort": [{sort_by: {"order": sort_order}}],
|
||||
"sort": [
|
||||
{
|
||||
"_script": {
|
||||
"type": "number",
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"source": script,
|
||||
"params": {"scores": sort},
|
||||
},
|
||||
"order": "asc",
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
if view_config["hide_watched"]:
|
||||
to_append = {"term": {"player.watched": {"value": False}}}
|
||||
|
Loading…
Reference in New Issue
Block a user