diff --git a/requirements.txt b/requirements.txt index eec0d3c..96b407a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ httpx django-tastypie django-admin-list-filter-dropdown wikipedia-api +bs4 diff --git a/source/main/models.py b/source/main/models.py index 807f6ff..cd8b8dd 100644 --- a/source/main/models.py +++ b/source/main/models.py @@ -3,6 +3,7 @@ import shutil import random import time import wikipediaapi +from bs4 import BeautifulSoup from django.conf import settings from django.db import models from pathlib import Path @@ -114,7 +115,7 @@ class MovieQuerySet(models.QuerySet): "Mejor valorados": self.fix_all_data(self.top_random_pick("stars")), "Más descargados": self.fix_all_data(self.top_pick("count")), } - sections['genders'] = {} + sections["genders"] = {} return sections def fix_all_data(self, movies): @@ -129,7 +130,7 @@ class MovieQuerySet(models.QuerySet): movie["file_name"] = self.fix_path(movie["file_name"]) movie["cartel"] = self.fix_path(movie["cartel"]) if wikipedia: - movie['wiki'] = self.get_wiki(movie) + movie["wiki"] = self.get_wiki(movie) def fix_path(self, el): if settings.DEBUG: @@ -138,8 +139,11 @@ class MovieQuerySet(models.QuerySet): return settings.MEDIA_ROOT / el def fix_summ(self, raw): - # TODO: quitar .reference - return raw + html = BeautifulSoup(raw, "lxml") + for ref in html.find_all("sup", "reference"): + ref.decompose() + clean = list(map(lambda x: str(x), html.body.children)) + return " ".join(clean) def format_stars(self, num): stars = "★" * num @@ -155,17 +159,17 @@ class MovieQuerySet(models.QuerySet): return time.strftime("%H:%M", time.gmtime(secs)) def get_wiki(self, movie, again=True): - wiki = self.get_wiki_page(movie['original_name']) + wiki = self.get_wiki_page(movie["original_name"]) if not wiki: - wiki = self.get_wiki_page(movie['name']) + wiki = self.get_wiki_page(movie["name"]) return wiki - def get_wiki_page(self, title): try: - lang = settings.LANGUAGE_CODE.split('-')[0] - wiki = wikipediaapi.Wikipedia(lang, - extract_format=wikipediaapi.ExtractFormat.HTML) + lang = settings.LANGUAGE_CODE.split("-")[0] + wiki = wikipediaapi.Wikipedia( + lang, extract_format=wikipediaapi.ExtractFormat.HTML + ) page = wiki.page(title) if page.exists(): return { @@ -175,7 +179,7 @@ class MovieQuerySet(models.QuerySet): } else: return None - except NameError: + except: return None def get_movie(self, id): @@ -185,7 +189,6 @@ class MovieQuerySet(models.QuerySet): return movie - def upload_cartel(instance, filename): first = filename[0].upper() if first.isdigit(): diff --git a/source/main/views.py b/source/main/views.py index 90ac413..774907e 100644 --- a/source/main/views.py +++ b/source/main/views.py @@ -16,6 +16,21 @@ def search(request): return render(request, "search.html", context) +def about(request): + context = {} + return render(request, "about.html", context) + + +def bugs(request): + context = {} + return render(request, "bugs.html", context) + + def movie(request, id): context = {"movie": Movie.objects.get_movie(id)} return render(request, "movie.html", context) + + +def movies(request, key): + context = {"sections": {"Llave": "Valor"}} + return render(request, "movies.html", context) diff --git a/source/mauflix/urls.py b/source/mauflix/urls.py index 552e4be..89597c2 100644 --- a/source/mauflix/urls.py +++ b/source/mauflix/urls.py @@ -18,7 +18,9 @@ v1_api.register(ResourceMovies()) urlpatterns = [ path("", views.home, name="home"), path("search/", views.search, name="search"), - # path('movies/', views.movies, name='movies'), + path("about/", views.about, name="about"), + path("bugs/", views.bugs, name="bugs"), + path("movies/", views.movies, name="movies"), path("movie/", views.movie, name="movie"), path("ultimas/rss/", LatestMoviesFeed()), path("admin/", admin.site.urls), diff --git a/source/templates/about.html b/source/templates/about.html new file mode 100644 index 0000000..48e1247 --- /dev/null +++ b/source/templates/about.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} + +{% block content %} + +TODO: Acerca + +{% endblock %} diff --git a/source/templates/bugs.html b/source/templates/bugs.html new file mode 100644 index 0000000..c5e8159 --- /dev/null +++ b/source/templates/bugs.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} + +{% block content %} + +TODO: Reporta un problema + +{% endblock %} diff --git a/source/templates/info-body.html b/source/templates/info-body.html new file mode 100644 index 0000000..5f3fb90 --- /dev/null +++ b/source/templates/info-body.html @@ -0,0 +1,43 @@ +
+ {% if request.get_full_path == "/" %} +
+

{{ movie.stars_icons }}

+

{{ movie.duration_formatted }}

+

{{ movie.count_formatted }}

+
+ {% else %} +
+
+
+

Cartel

+
+ +
+
+
+

Ficha técnica

+ + + + + + + + + + +
Título original{{ movie.original_name }}
Año{{ movie.year }}
País{{ movie.countries }}
Duración{{ movie.duration }} min
Dirección{{ movie.directors }}
Reparto{{ movie.actors }}
Género{{ movie.genders }}
+
+
+ {% if movie.wiki.summary %} +

Sinopsis de Wikipedia

+ {{ movie.wiki.summary | safe }} + {% endif %} +
+ {% if user.is_superuser %} + + {% endif %} + {% endif %} +
diff --git a/source/templates/info-foot.html b/source/templates/info-foot.html new file mode 100644 index 0000000..877ac2f --- /dev/null +++ b/source/templates/info-foot.html @@ -0,0 +1,12 @@ +
+ +
diff --git a/source/templates/info-head.html b/source/templates/info-head.html new file mode 100644 index 0000000..33462fd --- /dev/null +++ b/source/templates/info-head.html @@ -0,0 +1,10 @@ +
+

{{ movie.name }}

+ {% if request.get_full_path != "/" %} +

+ {{ movie.stars_icons }} + {{ movie.duration_formatted }} + {{ movie.count_formatted }} +

+ {% endif %} +
diff --git a/source/templates/info.html b/source/templates/info.html index cfda68b..c3107fd 100644 --- a/source/templates/info.html +++ b/source/templates/info.html @@ -1,88 +1,5 @@
-
-

{{ movie.name }}

- {% if request.get_full_path != "/" %} -

- {{ movie.stars_icons }} - {{ movie.duration_formatted }} - {{ movie.count_formatted }} -

- {% endif %} -
-
- {% if request.get_full_path == "/" %} -
-

{{ movie.stars_icons }}

-

{{ movie.duration_formatted }}

-

{{ movie.count_formatted }}

-
- {% else %} -
-
-
-

Cartel

-
- -
-
-
-

Ficha técnica

- - - - - - - - - - - - - - - - - - - - - - - - -
Título original{{ movie.original_name }} -
Año{{ movie.year }} -
País{{ movie.countries }} -
Duración{{ movie.duration }} min -
Dirección{{ movie.directors }} -
Reparto{{ movie.actors }} -
Género{{ movie.genders }} -
-
-
- {% if movie.wiki.summary %} -

Sinopsis de Wikipedia

- {{ movie.wiki.summary | safe }} - {% endif %} -
- {% if user.is_superuser %} - - {% endif %} - {% endif %} -
-
- -
+ {% include 'info-head.html' with movie=movie %} + {% include 'info-body.html' with movie=movie %} + {% include 'info-foot.html' with movie=movie %}
diff --git a/source/templates/movies.html b/source/templates/movies.html new file mode 100644 index 0000000..5a72bf4 --- /dev/null +++ b/source/templates/movies.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} +{% block content %} +{% for section, content in sections.items %} + {% include 'section.html' with section=section content=content %} +{% endfor %} +{% endblock %} diff --git a/source/templates/nav.html b/source/templates/nav.html index c69487b..6a007b2 100644 --- a/source/templates/nav.html +++ b/source/templates/nav.html @@ -12,24 +12,25 @@