refactor single video page to use SearchProcess
This commit is contained in:
parent
879f5ab52f
commit
a7fc7902f0
|
@ -39,7 +39,7 @@ class SearchProcess:
|
||||||
def _process_result(self, result):
|
def _process_result(self, result):
|
||||||
"""detect which type of data to process"""
|
"""detect which type of data to process"""
|
||||||
index = result["_index"]
|
index = result["_index"]
|
||||||
processed = {}
|
processed = False
|
||||||
if index == "ta_video":
|
if index == "ta_video":
|
||||||
processed = self._process_video(result["_source"])
|
processed = self._process_video(result["_source"])
|
||||||
if index == "ta_channel":
|
if index == "ta_channel":
|
||||||
|
@ -53,12 +53,13 @@ class SearchProcess:
|
||||||
if index == "ta_subtitle":
|
if index == "ta_subtitle":
|
||||||
processed = self._process_subtitle(result)
|
processed = self._process_subtitle(result)
|
||||||
|
|
||||||
processed.update(
|
if isinstance(processed, dict):
|
||||||
{
|
processed.update(
|
||||||
"_index": index,
|
{
|
||||||
"_score": round(result.get("_score") or 0, 2),
|
"_index": index,
|
||||||
}
|
"_score": round(result.get("_score") or 0, 2),
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return processed
|
return processed
|
||||||
|
|
||||||
|
|
|
@ -892,8 +892,9 @@ class VideoView(MinView):
|
||||||
def get(self, request, video_id):
|
def get(self, request, video_id):
|
||||||
"""get single video"""
|
"""get single video"""
|
||||||
config_handler = AppConfig(request.user.id)
|
config_handler = AppConfig(request.user.id)
|
||||||
look_up = SearchHandler(f"ta_video/_doc/{video_id}", config=False)
|
response, _ = ElasticWrap(f"ta_video/_doc/{video_id}").get()
|
||||||
video_data = look_up.get_data()[0]["source"]
|
video_data = SearchProcess(response).process()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rating = video_data["stats"]["average_rating"]
|
rating = video_data["stats"]["average_rating"]
|
||||||
video_data["stats"]["average_rating"] = self.star_creator(rating)
|
video_data["stats"]["average_rating"] = self.star_creator(rating)
|
||||||
|
|
Loading…
Reference in New Issue