From 4aa1f016586b2a554884e2847e36371c6ec62a0c Mon Sep 17 00:00:00 2001 From: Matheus Lopes <96511087+matheuspdf@users.noreply.github.com> Date: Sun, 22 Oct 2023 12:26:03 -0300 Subject: [PATCH] =?UTF-8?q?Criado=20link=20para=20p=C3=A1ginas=20de=20aula?= =?UTF-8?q?s=20close=20#41=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pypro/modulos/facade.py | 6 +++- .../modulos/migrations/0006_aula_vimeo_id.py | 18 +++++++++++ .../0007_alter_vimeo_obrigatorio.py | 18 +++++++++++ pypro/modulos/models.py | 1 + .../templates/modulos/aula_detalhe.html | 18 +++++++++++ .../templates/modulos/modulo_detalhe.html | 2 +- pypro/modulos/tests/test_aula_detalhe.py | 30 +++++++++++++++++++ pypro/modulos/tests/test_modulo_detalhe.py | 5 ++++ pypro/modulos/urls.py | 1 + pypro/modulos/views.py | 5 ++++ 10 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 pypro/modulos/migrations/0006_aula_vimeo_id.py create mode 100644 pypro/modulos/migrations/0007_alter_vimeo_obrigatorio.py create mode 100644 pypro/modulos/templates/modulos/aula_detalhe.html create mode 100644 pypro/modulos/tests/test_aula_detalhe.py diff --git a/pypro/modulos/facade.py b/pypro/modulos/facade.py index b5824a8..0ca6c0e 100644 --- a/pypro/modulos/facade.py +++ b/pypro/modulos/facade.py @@ -1,6 +1,6 @@ from typing import List -from pypro.modulos.models import Modulo +from pypro.modulos.models import Modulo, Aula def listar_modulos_ordenados() -> List[Modulo]: @@ -18,3 +18,7 @@ def encontrar_modulo(slug: str) -> Modulo: def listar_aulas_de_modulo_ordenadas(modulo: Modulo): return list(modulo.aula_set.order_by('order').all()) + + +def encontrar_aula(slug): + return Aula.objects.get(slug=slug) diff --git a/pypro/modulos/migrations/0006_aula_vimeo_id.py b/pypro/modulos/migrations/0006_aula_vimeo_id.py new file mode 100644 index 0000000..f784f2a --- /dev/null +++ b/pypro/modulos/migrations/0006_aula_vimeo_id.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.6 on 2023-10-21 13:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("modulos", "0005_aula"), + ] + + operations = [ + migrations.AddField( + model_name="aula", + name="vimeo_id", + field=models.CharField(default="1", max_length=32), + ), + ] diff --git a/pypro/modulos/migrations/0007_alter_vimeo_obrigatorio.py b/pypro/modulos/migrations/0007_alter_vimeo_obrigatorio.py new file mode 100644 index 0000000..3ee1841 --- /dev/null +++ b/pypro/modulos/migrations/0007_alter_vimeo_obrigatorio.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.6 on 2023-10-21 13:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("modulos", "0006_aula_vimeo_id"), + ] + + operations = [ + migrations.AlterField( + model_name="aula", + name="vimeo_id", + field=models.CharField(max_length=32), + ), + ] diff --git a/pypro/modulos/models.py b/pypro/modulos/models.py index 9ca57e0..d057570 100644 --- a/pypro/modulos/models.py +++ b/pypro/modulos/models.py @@ -27,6 +27,7 @@ class Aula(OrderedModel): slug = models.SlugField(unique=True) modulo = models.ForeignKey('Modulo', on_delete=models.PROTECT) order_with_respect_to = 'modulo' + vimeo_id = models.CharField(max_length=32) class Meta(OrderedModel.Meta): pass diff --git a/pypro/modulos/templates/modulos/aula_detalhe.html b/pypro/modulos/templates/modulos/aula_detalhe.html new file mode 100644 index 0000000..39fa063 --- /dev/null +++ b/pypro/modulos/templates/modulos/aula_detalhe.html @@ -0,0 +1,18 @@ +{% extends 'base/base.html' %} +{% load static %} +{% block title %}Python Pro - Aperitivo{% endblock title %} +{% block description %}Página com vídeo gratuito de Python{% endblock description %} +{% block body %} +
+
+
+

{{ aula.titulo | default:"Título não encontrado" }}

+ +
+
+
+{% endblock body %} + diff --git a/pypro/modulos/templates/modulos/modulo_detalhe.html b/pypro/modulos/templates/modulos/modulo_detalhe.html index 0cc00f2..9dd67a9 100644 --- a/pypro/modulos/templates/modulos/modulo_detalhe.html +++ b/pypro/modulos/templates/modulos/modulo_detalhe.html @@ -16,7 +16,7 @@

{{ modulo.titulo }}

Aulas

    {% for aula in aulas %} -
  1. {{ aula.titulo }}
  2. +
  3. {{ aula.titulo }}
  4. {% endfor %}
diff --git a/pypro/modulos/tests/test_aula_detalhe.py b/pypro/modulos/tests/test_aula_detalhe.py new file mode 100644 index 0000000..2e647fe --- /dev/null +++ b/pypro/modulos/tests/test_aula_detalhe.py @@ -0,0 +1,30 @@ +import pytest +from django.urls import reverse +from pypro.django_assertions import assert_contains +from model_mommy import mommy + +from pypro.modulos.models import Modulo, Aula + + +@pytest.fixture +def modulo(db): + return mommy.make(Modulo) + + +@pytest.fixture +def aula(modulo): + return mommy.make(Aula, modulo=modulo) + + +@pytest.fixture +def resp(client, aula): + resp = client.get(reverse('modulos:aula', kwargs={'slug': aula.slug})) + return resp + + +def test_titulo(resp, aula: Aula): + assert_contains(resp, aula.titulo) + + +def test_vimeo(resp, aula: Aula): + assert_contains(resp, f'src="https://player.vimeo.com/video/{ aula.vimeo_id }"') diff --git a/pypro/modulos/tests/test_modulo_detalhe.py b/pypro/modulos/tests/test_modulo_detalhe.py index a49f790..4d8ca37 100644 --- a/pypro/modulos/tests/test_modulo_detalhe.py +++ b/pypro/modulos/tests/test_modulo_detalhe.py @@ -37,3 +37,8 @@ def test_publico(resp, modulo: Modulo): def test_aulas_titulos(resp, aulas): for aula in aulas: assert_contains(resp, aula.titulo) + + +def test_aulas_links(resp, aulas): + for aula in aulas: + assert_contains(resp, aula.get_absolute_url()) diff --git a/pypro/modulos/urls.py b/pypro/modulos/urls.py index 067f890..1df8ee4 100644 --- a/pypro/modulos/urls.py +++ b/pypro/modulos/urls.py @@ -5,4 +5,5 @@ app_name = 'modulos' urlpatterns = [ path('', views.detalhe, name='detalhe'), + path('aulas/', views.aula, name='aula'), ] diff --git a/pypro/modulos/views.py b/pypro/modulos/views.py index 555ecdb..7be242d 100644 --- a/pypro/modulos/views.py +++ b/pypro/modulos/views.py @@ -7,3 +7,8 @@ def detalhe(request, slug): modulo = facade.encontrar_modulo(slug) aulas = facade.listar_aulas_de_modulo_ordenadas(modulo) return render(request, 'modulos/modulo_detalhe.html', {'modulo': modulo, 'aulas': aulas}) + + +def aula(request, slug): + aula = facade.encontrar_aula(slug) + return render(request, 'modulos/aula_detalhe.html', {'aula': aula})