mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 20:00:15 +00:00
userspace gird-list view
This commit is contained in:
parent
21d55561a0
commit
b2ca7710cd
@ -44,7 +44,7 @@ class HomeView(View):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
"""return home search results"""
|
"""return home search results"""
|
||||||
view_config = self.read_config()
|
view_config = self.read_config(user_id=request.user.id)
|
||||||
# handle search
|
# handle search
|
||||||
search_get = request.GET.get("search", False)
|
search_get = request.GET.get("search", False)
|
||||||
if search_get:
|
if search_get:
|
||||||
@ -118,10 +118,14 @@ class HomeView(View):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read_config():
|
def read_config(user_id):
|
||||||
"""read needed values from redis"""
|
"""read needed values from redis"""
|
||||||
config_handler = AppConfig().config
|
config_handler = AppConfig().config
|
||||||
colors = config_handler["application"]["colors"]
|
colors = config_handler["application"]["colors"]
|
||||||
|
|
||||||
|
view_key = f"{user_id}:view:home"
|
||||||
|
view_style = RedisArchivist().get_message(view_key)["status"]
|
||||||
|
if not view_style:
|
||||||
view_style = config_handler["default_view"]["home"]
|
view_style = config_handler["default_view"]["home"]
|
||||||
|
|
||||||
sort_by = RedisArchivist().get_message("sort_by")
|
sort_by = RedisArchivist().get_message("sort_by")
|
||||||
@ -215,17 +219,15 @@ class DownloadView(View):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
"""handle get requests"""
|
"""handle get requests"""
|
||||||
config = AppConfig().config
|
view_config = self.read_config(user_id=request.user.id)
|
||||||
colors = config["application"]["colors"]
|
|
||||||
view_style = config["default_view"]["downloads"]
|
|
||||||
ignored = RedisArchivist().get_message("show_ignored_only")
|
|
||||||
show_ignored_only = ignored["status"]
|
|
||||||
|
|
||||||
page_get = int(request.GET.get("page", 0))
|
page_get = int(request.GET.get("page", 0))
|
||||||
pagination_handler = Pagination(page_get)
|
pagination_handler = Pagination(page_get)
|
||||||
|
|
||||||
url = config["application"]["es_url"] + "/ta_download/_search"
|
url = view_config["es_url"] + "/ta_download/_search"
|
||||||
data = self.build_data(pagination_handler, show_ignored_only)
|
data = self.build_data(
|
||||||
|
pagination_handler, view_config["show_ignored_only"]
|
||||||
|
)
|
||||||
search = SearchHandler(url, data)
|
search = SearchHandler(url, data)
|
||||||
|
|
||||||
videos_hits = search.get_data()
|
videos_hits = search.get_data()
|
||||||
@ -244,12 +246,36 @@ class DownloadView(View):
|
|||||||
"max_hits": max_hits,
|
"max_hits": max_hits,
|
||||||
"pagination": pagination,
|
"pagination": pagination,
|
||||||
"title": "Downloads",
|
"title": "Downloads",
|
||||||
"colors": colors,
|
"colors": view_config["colors"],
|
||||||
"show_ignored_only": show_ignored_only,
|
"show_ignored_only": view_config["show_ignored_only"],
|
||||||
"view_style": view_style,
|
"view_style": view_config["view_style"],
|
||||||
}
|
}
|
||||||
return render(request, "home/downloads.html", context)
|
return render(request, "home/downloads.html", context)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def read_config(user_id):
|
||||||
|
"""read config vars"""
|
||||||
|
config = AppConfig().config
|
||||||
|
colors = config["application"]["colors"]
|
||||||
|
|
||||||
|
view_key = f"{user_id}:view:downloads"
|
||||||
|
view_style = RedisArchivist().get_message(view_key)["status"]
|
||||||
|
if not view_style:
|
||||||
|
view_style = config["default_view"]["downloads"]
|
||||||
|
|
||||||
|
ignored = RedisArchivist().get_message("show_ignored_only")
|
||||||
|
show_ignored_only = ignored["status"]
|
||||||
|
|
||||||
|
es_url = config["application"]["es_url"]
|
||||||
|
|
||||||
|
view_config = {
|
||||||
|
"es_url": es_url,
|
||||||
|
"colors": colors,
|
||||||
|
"view_style": view_style,
|
||||||
|
"show_ignored_only": show_ignored_only
|
||||||
|
}
|
||||||
|
return view_config
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def build_data(pagination_handler, show_ignored_only):
|
def build_data(pagination_handler, show_ignored_only):
|
||||||
"""build data dict for search"""
|
"""build data dict for search"""
|
||||||
@ -429,7 +455,7 @@ class ChannelView(View):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
"""handle http get requests"""
|
"""handle http get requests"""
|
||||||
es_url, colors, view_style = self.read_config()
|
es_url, colors, view_style = self.read_config(user_id=request.user.id)
|
||||||
page_get = int(request.GET.get("page", 0))
|
page_get = int(request.GET.get("page", 0))
|
||||||
pagination_handler = Pagination(page_get)
|
pagination_handler = Pagination(page_get)
|
||||||
page_size = pagination_handler.pagination["page_size"]
|
page_size = pagination_handler.pagination["page_size"]
|
||||||
@ -461,12 +487,17 @@ class ChannelView(View):
|
|||||||
return render(request, "home/channel.html", context)
|
return render(request, "home/channel.html", context)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read_config():
|
def read_config(user_id):
|
||||||
"""read config file"""
|
"""read config file"""
|
||||||
config = AppConfig().config
|
config = AppConfig().config
|
||||||
es_url = config["application"]["es_url"]
|
es_url = config["application"]["es_url"]
|
||||||
colors = config["application"]["colors"]
|
colors = config["application"]["colors"]
|
||||||
|
|
||||||
|
view_key = f"{user_id}:view:channel"
|
||||||
|
view_style = RedisArchivist().get_message(view_key)["status"]
|
||||||
|
if not view_style:
|
||||||
view_style = config["default_view"]["channel"]
|
view_style = config["default_view"]["channel"]
|
||||||
|
|
||||||
return es_url, colors, view_style
|
return es_url, colors, view_style
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
@ -591,8 +622,9 @@ def progress(request):
|
|||||||
def process(request):
|
def process(request):
|
||||||
"""handle all the buttons calls via POST ajax"""
|
"""handle all the buttons calls via POST ajax"""
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
current_user = request.user.id
|
||||||
post_dict = json.loads(request.body.decode())
|
post_dict = json.loads(request.body.decode())
|
||||||
post_handler = PostData(post_dict)
|
post_handler = PostData(post_dict, current_user)
|
||||||
if post_handler.to_exec:
|
if post_handler.to_exec:
|
||||||
task_result = post_handler.run_task()
|
task_result = post_handler.run_task()
|
||||||
return JsonResponse(task_result)
|
return JsonResponse(task_result)
|
||||||
@ -606,9 +638,10 @@ class PostData:
|
|||||||
handover long running tasks to celery
|
handover long running tasks to celery
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, post_dict):
|
def __init__(self, post_dict, current_user):
|
||||||
self.post_dict = post_dict
|
self.post_dict = post_dict
|
||||||
self.to_exec, self.exec_val = list(post_dict.items())[0]
|
self.to_exec, self.exec_val = list(post_dict.items())[0]
|
||||||
|
self.current_user = current_user
|
||||||
|
|
||||||
def run_task(self):
|
def run_task(self):
|
||||||
"""execute and return task result"""
|
"""execute and return task result"""
|
||||||
@ -658,9 +691,9 @@ class PostData:
|
|||||||
def change_view(self):
|
def change_view(self):
|
||||||
"""process view changes in home, channel, and downloads"""
|
"""process view changes in home, channel, and downloads"""
|
||||||
origin, new_view = self.exec_val.split(":")
|
origin, new_view = self.exec_val.split(":")
|
||||||
print(f"change view on page {origin} to {new_view}")
|
key = f"{self.current_user}:view:{origin}"
|
||||||
update_dict = {f"default_view.{origin}": [new_view]}
|
print(f"change view: {key} to {new_view}")
|
||||||
AppConfig().update_config(update_dict)
|
RedisArchivist().set_message(key, {"status": new_view}, expire=False)
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user