diff --git a/pypro/modulos/facade.py b/pypro/modulos/facade.py index e22b858..0bf7f11 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 Aula, Modulo 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: str): + 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..9b97617 --- /dev/null +++ b/pypro/modulos/migrations/0006_aula_vimeo_id.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.4 on 2024-04-14 18:50 + +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..d48a61d --- /dev/null +++ b/pypro/modulos/migrations/0007_alter_vimeo_obrigatorio.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.4 on 2024-04-14 18:50 + +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 e21c593..4726adf 100644 --- a/pypro/modulos/models.py +++ b/pypro/modulos/models.py @@ -24,6 +24,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..2b855f9 --- /dev/null +++ b/pypro/modulos/templates/modulos/aula_detalhe.html @@ -0,0 +1,15 @@ +{% extends 'base/base.html' %} +{% block title %}Python Pro - Aperitivo{% endblock title %} +{% block description %}Página com vídeo gratuito de Python{% endblock description %} +{% block body %} +
+
+
+

{{ aula.titulo | default:'Faltando título' }}

+ +
+
+
+{% endblock body %} \ No newline at end of file diff --git a/pypro/modulos/tests/test_aula_detalhe.py b/pypro/modulos/tests/test_aula_detalhe.py new file mode 100644 index 0000000..860c29d --- /dev/null +++ b/pypro/modulos/tests/test_aula_detalhe.py @@ -0,0 +1,30 @@ +from django.urls import reverse +import pytest +from pypro.django_assertions import assert_contains +from model_bakery import baker + +from pypro.modulos.models import Aula, Modulo + + +@pytest.fixture +def modulo(db): + return baker.make(Modulo) + + +@pytest.fixture +def aula(modulo): + return baker.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/views.py b/pypro/modulos/views.py index af8df4b..7be242d 100644 --- a/pypro/modulos/views.py +++ b/pypro/modulos/views.py @@ -10,4 +10,5 @@ def detalhe(request, slug): def aula(request, slug): - pass + aula = facade.encontrar_aula(slug) + return render(request, 'modulos/aula_detalhe.html', {'aula': aula})