mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 11:50:14 +00:00
refacter DownloadView to use new inheritance structure, #116
This commit is contained in:
parent
6229d92333
commit
2ae25540d1
@ -58,9 +58,9 @@
|
||||
<div class="dl-list {{ view_style }}">
|
||||
{% if all_video_hits %}
|
||||
{% for video in all_video_hits %}
|
||||
<div class="dl-item {{ view_style }}" id="dl-{{ video.youtube_id }}">
|
||||
<div class="dl-item {{ view_style }}" id="dl-{{ video.source.youtube_id }}">
|
||||
<div class="dl-thumb {{ view_style }}">
|
||||
<img src="/cache/{{ video.vid_thumb_url }}" alt="video_thumb">
|
||||
<img src="/cache/{{ video.source.vid_thumb_url }}" alt="video_thumb">
|
||||
{% if show_ignored_only %}
|
||||
<span>ignored</span>
|
||||
{% else %}
|
||||
@ -68,19 +68,19 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="dl-desc {{ view_style }}">
|
||||
<h3>{{ video.title }}</h3>
|
||||
{% if video.channel_indexed %}
|
||||
<a href="{% url 'channel_id' video.channel_id %}">{{ video.channel_name }}</a>
|
||||
<h3>{{ video.source.title }}</h3>
|
||||
{% if video.source.channel_indexed %}
|
||||
<a href="{% url 'channel_id' video.source.channel_id %}">{{ video.source.channel_name }}</a>
|
||||
{% else %}
|
||||
<span>{{ video.channel_name }}</span>
|
||||
<span>{{ video.source.channel_name }}</span>
|
||||
{% endif %}
|
||||
<p>Published: {{ video.published }} | Duration: {{ video.duration }} | {{ video.youtube_id }}</p>
|
||||
<p>Published: {{ video.source.published }} | Duration: {{ video.source.duration }} | {{ video.source.youtube_id }}</p>
|
||||
{% if show_ignored_only %}
|
||||
<button data-id="{{ video.youtube_id }}" onclick="forgetIgnore(this)">Forget</button>
|
||||
<button data-id="{{ video.youtube_id }}" onclick="addSingle(this)">Add to queue</button>
|
||||
<button data-id="{{ video.source.youtube_id }}" onclick="forgetIgnore(this)">Forget</button>
|
||||
<button data-id="{{ video.source.youtube_id }}" onclick="addSingle(this)">Add to queue</button>
|
||||
{% else %}
|
||||
<button data-id="{{ video.youtube_id }}" onclick="toIgnore(this)">Ignore</button>
|
||||
<button id="{{ video.youtube_id }}" data-id="{{ video.youtube_id }}" onclick="downloadNow(this)">Download now</button>
|
||||
<button data-id="{{ video.source.youtube_id }}" onclick="toIgnore(this)">Ignore</button>
|
||||
<button id="{{ video.source.youtube_id }}" data-id="{{ video.source.youtube_id }}" onclick="downloadNow(this)">Download now</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -80,6 +80,12 @@ class ArchivistViewConfig(View):
|
||||
|
||||
return hide_watched
|
||||
|
||||
def _get_show_ignore_only(self):
|
||||
ignored_key = f"{self.user_id}:show_ignored_only"
|
||||
show_ignored_only = self.user_conf.get_message(ignored_key)["status"]
|
||||
|
||||
return show_ignored_only
|
||||
|
||||
def config_builder(self, user_id):
|
||||
"""build default context for every view"""
|
||||
self.user_id = user_id
|
||||
@ -92,6 +98,7 @@ class ArchivistViewConfig(View):
|
||||
context["sort_order"] = self._get_sort_order()
|
||||
context["view_style"] = self._get_view_style()
|
||||
context["hide_watched"] = self._get_hide_watched()
|
||||
context["show_ignored_only"] = self._get_show_ignore_only()
|
||||
|
||||
self.context = context
|
||||
|
||||
@ -158,6 +165,7 @@ class ArchivistResultsView(ArchivistViewConfig):
|
||||
search = SearchHandler(url, self.data)
|
||||
videos_hits = search.get_data()
|
||||
self.pagination_handler.validate(search.max_hits)
|
||||
self.context["max_hits"] = search.max_hits
|
||||
|
||||
return videos_hits
|
||||
|
||||
@ -267,88 +275,45 @@ class AboutView(View):
|
||||
return render(request, "home/about.html", context)
|
||||
|
||||
|
||||
class DownloadView(View):
|
||||
class DownloadView(ArchivistResultsView):
|
||||
"""resolves to /download/
|
||||
takes POST for downloading youtube links
|
||||
"""
|
||||
|
||||
view_origin = "downloads"
|
||||
es_search = "/ta_download/_search"
|
||||
|
||||
def get(self, request):
|
||||
"""handle get requests"""
|
||||
"""handle get request"""
|
||||
user_id = request.user.id
|
||||
view_config = self.read_config(user_id)
|
||||
|
||||
page_get = int(request.GET.get("page", 0))
|
||||
pagination_handler = Pagination(page_get, user_id)
|
||||
|
||||
url = view_config["es_url"] + "/ta_download/_search"
|
||||
data = self.build_data(
|
||||
pagination_handler, view_config["show_ignored_only"]
|
||||
)
|
||||
search = SearchHandler(url, data)
|
||||
self.config_builder(user_id)
|
||||
self.initiate_vars(page_get)
|
||||
self._update_view_data()
|
||||
|
||||
videos_hits = search.get_data()
|
||||
max_hits = search.max_hits
|
||||
|
||||
if videos_hits:
|
||||
all_video_hits = [i["source"] for i in videos_hits]
|
||||
pagination_handler.validate(max_hits)
|
||||
pagination = pagination_handler.pagination
|
||||
else:
|
||||
all_video_hits = False
|
||||
pagination = False
|
||||
|
||||
add_form = AddToQueueForm()
|
||||
context = {
|
||||
"add_form": add_form,
|
||||
"all_video_hits": all_video_hits,
|
||||
"max_hits": max_hits,
|
||||
"pagination": pagination,
|
||||
self.context.update(
|
||||
{
|
||||
"title": "Downloads",
|
||||
"colors": view_config["colors"],
|
||||
"show_ignored_only": view_config["show_ignored_only"],
|
||||
"view_style": view_config["view_style"],
|
||||
"add_form": AddToQueueForm(),
|
||||
"all_video_hits": self.find_video_hits(),
|
||||
"pagination": self.pagination_handler.pagination,
|
||||
}
|
||||
return render(request, "home/downloads.html", context)
|
||||
)
|
||||
return render(request, "home/downloads.html", self.context)
|
||||
|
||||
@staticmethod
|
||||
def read_config(user_id):
|
||||
"""read config vars"""
|
||||
config_handler = AppConfig(user_id)
|
||||
view_key = f"{user_id}:view:downloads"
|
||||
view_style = RedisArchivist().get_message(view_key)["status"]
|
||||
if not view_style:
|
||||
view_style = config_handler.config["default_view"]["downloads"]
|
||||
|
||||
ignored = RedisArchivist().get_message(f"{user_id}:show_ignored_only")
|
||||
show_ignored_only = ignored["status"]
|
||||
|
||||
es_url = config_handler.config["application"]["es_url"]
|
||||
|
||||
view_config = {
|
||||
"es_url": es_url,
|
||||
"colors": config_handler.colors,
|
||||
"view_style": view_style,
|
||||
"show_ignored_only": show_ignored_only,
|
||||
}
|
||||
return view_config
|
||||
|
||||
@staticmethod
|
||||
def build_data(pagination_handler, show_ignored_only):
|
||||
"""build data dict for search"""
|
||||
page_size = pagination_handler.pagination["page_size"]
|
||||
page_from = pagination_handler.pagination["page_from"]
|
||||
if show_ignored_only:
|
||||
def _update_view_data(self):
|
||||
"""update downloads view specific data dict"""
|
||||
if self.context["show_ignored_only"]:
|
||||
filter_view = "ignore"
|
||||
else:
|
||||
filter_view = "pending"
|
||||
|
||||
data = {
|
||||
"size": page_size,
|
||||
"from": page_from,
|
||||
self.data.update(
|
||||
{
|
||||
"query": {"term": {"status": {"value": filter_view}}},
|
||||
"sort": [{"timestamp": {"order": "asc"}}],
|
||||
}
|
||||
return data
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def post(request):
|
||||
|
Loading…
Reference in New Issue
Block a user