further consolidate by adding query results in parent class

This commit is contained in:
simon 2021-12-27 12:01:49 +07:00
parent 2ae25540d1
commit fb512b26ea
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 15 additions and 23 deletions

View File

@ -56,8 +56,8 @@
</div> </div>
<h3>Total videos: {{ max_hits }}</h3> <h3>Total videos: {{ max_hits }}</h3>
<div class="dl-list {{ view_style }}"> <div class="dl-list {{ view_style }}">
{% if all_video_hits %} {% if results %}
{% for video in all_video_hits %} {% for video in results %}
<div class="dl-item {{ view_style }}" id="dl-{{ video.source.youtube_id }}"> <div class="dl-item {{ view_style }}" id="dl-{{ video.source.youtube_id }}">
<div class="dl-thumb {{ view_style }}"> <div class="dl-thumb {{ view_style }}">
<img src="/cache/{{ video.source.vid_thumb_url }}" alt="video_thumb"> <img src="/cache/{{ video.source.vid_thumb_url }}" alt="video_thumb">

View File

@ -59,8 +59,8 @@
<div id="player" class="player-wrapper"></div> <div id="player" class="player-wrapper"></div>
<div class="boxed-content"> <div class="boxed-content">
<div class="video-list {{ view_style }}"> <div class="video-list {{ view_style }}">
{% if videos %} {% if results %}
{% for video in videos %} {% for video in results %}
<div class="video-item {{ view_style }}"> <div class="video-item {{ view_style }}">
<a href="#player" data-src="/media/{{ video.source.media_url }}" data-thumb="/cache/{{ video.source.vid_thumb_url }}" data-title="{{ video.source.title }}" data-channel="{{ video.source.channel.channel_name }}" data-channel-id="{{ video.source.channel.channel_id }}" data-id="{{ video.source.youtube_id }}" onclick="createPlayer(this)"> <a href="#player" data-src="/media/{{ video.source.media_url }}" data-thumb="/cache/{{ video.source.vid_thumb_url }}" data-title="{{ video.source.title }}" data-channel="{{ video.source.channel.channel_name }}" data-channel-id="{{ video.source.channel.channel_id }}" data-id="{{ video.source.youtube_id }}" onclick="createPlayer(this)">
<div class="video-thumb-wrap {{ view_style }}"> <div class="video-thumb-wrap {{ view_style }}">

View File

@ -149,8 +149,9 @@ class ArchivistResultsView(ArchivistViewConfig):
} }
self.data = data self.data = data
def initiate_vars(self, page_get, search_get=False): def initiate_vars(self, page_get, user_id, search_get=False):
"""search in es for vidoe hits""" """search in es for vidoe hits"""
self.user_id = user_id
self.config_builder(self.user_id) self.config_builder(self.user_id)
self.search_get = search_get self.search_get = search_get
self.pagination_handler = Pagination( self.pagination_handler = Pagination(
@ -159,15 +160,14 @@ class ArchivistResultsView(ArchivistViewConfig):
self.sort_by = self._sort_by_overwrite() self.sort_by = self._sort_by_overwrite()
self._initial_data() self._initial_data()
def find_video_hits(self): def find_results(self):
"""return videos list""" """add results and pagination to context"""
url = self.default_conf["application"]["es_url"] + self.es_search url = self.default_conf["application"]["es_url"] + self.es_search
search = SearchHandler(url, self.data) search = SearchHandler(url, self.data)
videos_hits = search.get_data() self.context["results"] = search.get_data()
self.pagination_handler.validate(search.max_hits) self.pagination_handler.validate(search.max_hits)
self.context["max_hits"] = search.max_hits self.context["max_hits"] = search.max_hits
self.context["pagination"] = self.pagination_handler.pagination
return videos_hits
class HomeView(ArchivistResultsView): class HomeView(ArchivistResultsView):
@ -184,17 +184,11 @@ class HomeView(ArchivistResultsView):
page_get = int(request.GET.get("page", 0)) page_get = int(request.GET.get("page", 0))
search_get = request.GET.get("search", False) search_get = request.GET.get("search", False)
self.config_builder(user_id) self.initiate_vars(page_get, user_id, search_get)
self.initiate_vars(page_get, search_get)
self._update_view_data() self._update_view_data()
self.find_results()
self.context.update( self.context.update({"search_form": VideoSearchForm()})
{
"search_form": VideoSearchForm(),
"videos": self.find_video_hits(),
"pagination": self.pagination_handler.pagination,
}
)
return render(request, "home/home.html", self.context) return render(request, "home/home.html", self.context)
@ -288,16 +282,14 @@ class DownloadView(ArchivistResultsView):
user_id = request.user.id user_id = request.user.id
page_get = int(request.GET.get("page", 0)) page_get = int(request.GET.get("page", 0))
self.config_builder(user_id) self.initiate_vars(page_get, user_id)
self.initiate_vars(page_get)
self._update_view_data() self._update_view_data()
self.find_results()
self.context.update( self.context.update(
{ {
"title": "Downloads", "title": "Downloads",
"add_form": AddToQueueForm(), "add_form": AddToQueueForm(),
"all_video_hits": self.find_video_hits(),
"pagination": self.pagination_handler.pagination,
} }
) )
return render(request, "home/downloads.html", self.context) return render(request, "home/downloads.html", self.context)