mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 11:50:14 +00:00
userspace show_subed_only in channel view
This commit is contained in:
parent
88f28a7d1e
commit
180a63d6dd
@ -455,21 +455,21 @@ 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(user_id=request.user.id)
|
user_id = request.user.id
|
||||||
|
view_config = self.read_config(user_id=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"]
|
||||||
page_from = pagination_handler.pagination["page_from"]
|
page_from = pagination_handler.pagination["page_from"]
|
||||||
# get
|
# get
|
||||||
url = es_url + "/ta_channel/_search"
|
url = view_config["es_url"] + "/ta_channel/_search"
|
||||||
data = {
|
data = {
|
||||||
"size": page_size,
|
"size": page_size,
|
||||||
"from": page_from,
|
"from": page_from,
|
||||||
"query": {"match_all": {}},
|
"query": {"match_all": {}},
|
||||||
"sort": [{"channel_name.keyword": {"order": "asc"}}],
|
"sort": [{"channel_name.keyword": {"order": "asc"}}],
|
||||||
}
|
}
|
||||||
show_subed_only = RedisArchivist().get_message("show_subed_only")
|
if view_config["show_subed_only"]:
|
||||||
if show_subed_only:
|
|
||||||
data["query"] = {"term": {"channel_subscribed": {"value": True}}}
|
data["query"] = {"term": {"channel_subscribed": {"value": True}}}
|
||||||
search = SearchHandler(url, data)
|
search = SearchHandler(url, data)
|
||||||
channel_hits = search.get_data()
|
channel_hits = search.get_data()
|
||||||
@ -479,10 +479,10 @@ class ChannelView(View):
|
|||||||
"channels": channel_hits,
|
"channels": channel_hits,
|
||||||
"max_hits": max_hits,
|
"max_hits": max_hits,
|
||||||
"pagination": pagination_handler.pagination,
|
"pagination": pagination_handler.pagination,
|
||||||
"show_subed_only": show_subed_only,
|
"show_subed_only": view_config["show_subed_only"],
|
||||||
"title": "Channels",
|
"title": "Channels",
|
||||||
"colors": colors,
|
"colors": view_config["colors"],
|
||||||
"view_style": view_style,
|
"view_style": view_config["view_style"],
|
||||||
}
|
}
|
||||||
return render(request, "home/channel.html", context)
|
return render(request, "home/channel.html", context)
|
||||||
|
|
||||||
@ -490,7 +490,6 @@ class ChannelView(View):
|
|||||||
def read_config(user_id):
|
def read_config(user_id):
|
||||||
"""read config file"""
|
"""read config file"""
|
||||||
config = AppConfig().config
|
config = AppConfig().config
|
||||||
es_url = config["application"]["es_url"]
|
|
||||||
colors = config["application"]["colors"]
|
colors = config["application"]["colors"]
|
||||||
|
|
||||||
view_key = f"{user_id}:view:channel"
|
view_key = f"{user_id}:view:channel"
|
||||||
@ -498,7 +497,17 @@ class ChannelView(View):
|
|||||||
if not view_style:
|
if not view_style:
|
||||||
view_style = config["default_view"]["channel"]
|
view_style = config["default_view"]["channel"]
|
||||||
|
|
||||||
return es_url, colors, view_style
|
sub_only_key = f"{user_id}:show_subed_only"
|
||||||
|
show_subed_only = RedisArchivist().get_message(sub_only_key)["status"]
|
||||||
|
|
||||||
|
view_config = {
|
||||||
|
"es_url": config["application"]["es_url"],
|
||||||
|
"view_style": view_style,
|
||||||
|
"show_subed_only": show_subed_only,
|
||||||
|
"colors": colors,
|
||||||
|
}
|
||||||
|
|
||||||
|
return view_config
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
"""handle http post requests"""
|
"""handle http post requests"""
|
||||||
@ -770,11 +779,10 @@ class PostData:
|
|||||||
|
|
||||||
def show_subed_only(self):
|
def show_subed_only(self):
|
||||||
"""show or hide subscribed channels only on channels page"""
|
"""show or hide subscribed channels only on channels page"""
|
||||||
show_subed_only = bool(int(self.exec_val))
|
key = f"{self.current_user}:show_subed_only"
|
||||||
print(f"show subed only: {show_subed_only}")
|
message = {"status": bool(int(self.exec_val))}
|
||||||
RedisArchivist().set_message(
|
print(f"show {key}: {message}")
|
||||||
"show_subed_only", show_subed_only, expire=False
|
RedisArchivist().set_message(key, message, expire=False)
|
||||||
)
|
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
def dlnow(self):
|
def dlnow(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user