|
|
@ -20,6 +20,7 @@ from home.forms import (
|
|
|
|
ApplicationSettingsForm,
|
|
|
|
ApplicationSettingsForm,
|
|
|
|
ChannelSearchForm,
|
|
|
|
ChannelSearchForm,
|
|
|
|
CustomAuthForm,
|
|
|
|
CustomAuthForm,
|
|
|
|
|
|
|
|
PlaylistSearchForm,
|
|
|
|
SubscribeToChannelForm,
|
|
|
|
SubscribeToChannelForm,
|
|
|
|
UserSettingsForm,
|
|
|
|
UserSettingsForm,
|
|
|
|
VideoSearchForm,
|
|
|
|
VideoSearchForm,
|
|
|
@ -717,23 +718,28 @@ class PlaylistView(View):
|
|
|
|
"""handle http get requests"""
|
|
|
|
"""handle http get requests"""
|
|
|
|
user_id = request.user.id
|
|
|
|
user_id = request.user.id
|
|
|
|
view_config = self.read_config(user_id=user_id)
|
|
|
|
view_config = self.read_config(user_id=user_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# handle search
|
|
|
|
|
|
|
|
search_get = request.GET.get("search", False)
|
|
|
|
|
|
|
|
if search_get:
|
|
|
|
|
|
|
|
search_encoded = urllib.parse.quote(search_get)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
search_encoded = False
|
|
|
|
|
|
|
|
# define page size
|
|
|
|
page_get = int(request.GET.get("page", 0))
|
|
|
|
page_get = int(request.GET.get("page", 0))
|
|
|
|
pagination_handler = Pagination(page_get, user_id)
|
|
|
|
pagination_handler = Pagination(
|
|
|
|
|
|
|
|
page_get, user_id, search_get=search_encoded
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
url = view_config["es_url"] + "/ta_playlist/_search"
|
|
|
|
url = view_config["es_url"] + "/ta_playlist/_search"
|
|
|
|
data = {
|
|
|
|
data = self.build_data(pagination_handler, search_get)
|
|
|
|
"size": pagination_handler.pagination["page_size"],
|
|
|
|
|
|
|
|
"from": pagination_handler.pagination["page_from"],
|
|
|
|
|
|
|
|
"query": {
|
|
|
|
|
|
|
|
"term": {"playlist_entries.downloaded": {"value": True}}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"sort": [{"playlist_name.keyword": {"order": "asc"}}],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
search = SearchHandler(url, data)
|
|
|
|
search = SearchHandler(url, data)
|
|
|
|
playlist_hits = search.get_data()
|
|
|
|
playlist_hits = search.get_data()
|
|
|
|
pagination_handler.validate(search.max_hits)
|
|
|
|
pagination_handler.validate(search.max_hits)
|
|
|
|
|
|
|
|
search_form = PlaylistSearchForm()
|
|
|
|
|
|
|
|
|
|
|
|
context = {
|
|
|
|
context = {
|
|
|
|
|
|
|
|
"search_form": search_form,
|
|
|
|
"title": "Playlists",
|
|
|
|
"title": "Playlists",
|
|
|
|
"colors": view_config["colors"],
|
|
|
|
"colors": view_config["colors"],
|
|
|
|
"pagination": pagination_handler.pagination,
|
|
|
|
"pagination": pagination_handler.pagination,
|
|
|
@ -742,6 +748,40 @@ class PlaylistView(View):
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return render(request, "home/playlist.html", context)
|
|
|
|
return render(request, "home/playlist.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def build_data(pagination_handler, search_get):
|
|
|
|
|
|
|
|
"""build data object for query"""
|
|
|
|
|
|
|
|
data = {
|
|
|
|
|
|
|
|
"size": pagination_handler.pagination["page_size"],
|
|
|
|
|
|
|
|
"from": pagination_handler.pagination["page_from"],
|
|
|
|
|
|
|
|
"query": {
|
|
|
|
|
|
|
|
"term": {"playlist_entries.downloaded": {"value": True}}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"sort": [{"playlist_name.keyword": {"order": "asc"}}],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if search_get:
|
|
|
|
|
|
|
|
data["query"] = {
|
|
|
|
|
|
|
|
"bool": {
|
|
|
|
|
|
|
|
"should": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"multi_match": {
|
|
|
|
|
|
|
|
"query": search_get,
|
|
|
|
|
|
|
|
"fields": [
|
|
|
|
|
|
|
|
"playlist_channel_id",
|
|
|
|
|
|
|
|
"playlist_channel",
|
|
|
|
|
|
|
|
"playlist_name",
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"filter": [
|
|
|
|
|
|
|
|
{"term": {"playlist_entries.downloaded": True}}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"minimum_should_match": 1,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@staticmethod
|
|
|
|
def read_config(user_id):
|
|
|
|
def read_config(user_id):
|
|
|
|
"""read config file"""
|
|
|
|
"""read config file"""
|
|
|
@ -758,6 +798,18 @@ class PlaylistView(View):
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return view_config
|
|
|
|
return view_config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def post(request):
|
|
|
|
|
|
|
|
"""handle post from search form"""
|
|
|
|
|
|
|
|
search_form = PlaylistSearchForm(data=request.POST)
|
|
|
|
|
|
|
|
if search_form.is_valid():
|
|
|
|
|
|
|
|
search_query = request.POST.get("searchInput")
|
|
|
|
|
|
|
|
print(search_query)
|
|
|
|
|
|
|
|
search_url = "/playlist/?" + urlencode({"search": search_query})
|
|
|
|
|
|
|
|
return redirect(search_url, permanent=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return redirect("playlist")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VideoView(View):
|
|
|
|
class VideoView(View):
|
|
|
|
"""resolves to /video/<video-id>/
|
|
|
|
"""resolves to /video/<video-id>/
|
|
|
|