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>
<h3>Total videos: {{ max_hits }}</h3>
<div class="dl-list {{ view_style }}">
{% if all_video_hits %}
{% for video in all_video_hits %}
{% if results %}
{% for video in results %}
<div class="dl-item {{ view_style }}" id="dl-{{ video.source.youtube_id }}">
<div class="dl-thumb {{ view_style }}">
<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 class="boxed-content">
<div class="video-list {{ view_style }}">
{% if videos %}
{% for video in videos %}
{% if results %}
{% for video in results %}
<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)">
<div class="video-thumb-wrap {{ view_style }}">

View File

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