From 0046f9da8d5ece7d438c1d4cf0ae062410c7eb53 Mon Sep 17 00:00:00 2001 From: el Mau Date: Mon, 13 Feb 2023 23:08:53 -0600 Subject: [PATCH] Fix #8 --- source/main/models.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/source/main/models.py b/source/main/models.py index c76a0af..7ee9f1c 100644 --- a/source/main/models.py +++ b/source/main/models.py @@ -1,6 +1,8 @@ import random import time import re +from pathlib import Path + import wikipediaapi from bs4 import BeautifulSoup from django.conf import settings @@ -170,12 +172,12 @@ class MovieQuerySet(models.QuerySet): movie["duration_formatted"] = self.format_duration(movie["duration"]) movie["count_formatted"] = self.format_count(movie["count"]) movie["stars_icons"] = self.format_stars(movie["stars"]) - movie["file_name"] = self.fix_path(movie["file_name"]) - movie["cartel"] = f"{settings.MEDIA_URL}{movie['cartel']}" + movie["file_name"] = self._fix_path_movie(movie["file_name"]) + movie["cartel"] = self._fix_path_cartel(movie['cartel']) if wikipedia: movie["wiki"] = self.get_wiki(movie) - def fix_path(self, file_name): + def _fix_path_movie(self, file_name): """ Enmienda ruta a medio. """ @@ -188,6 +190,17 @@ class MovieQuerySet(models.QuerySet): url = f"{settings.URL_CDN}/{letter}/{file_name}" return url + def _fix_path_cartel(self, file_name): + """ Si no existe el cartel regresa el default """ + url = f"{settings.MEDIA_URL}{file_name}" + + path = Path(f"{settings.MEDIA_ROOT}{file_name}") + if not path.exists(): + url = f"{settings.MEDIA_URL}default.png" + + return url + + def fix_summ(self, raw): """ Enmienda sinopsis de Wikipedia.