Skip to content

Commit

Permalink
Criado página de detalhe da aula
Browse files Browse the repository at this point in the history
close #88
  • Loading branch information
thiago-garcia committed Apr 14, 2024
1 parent ba5688b commit cd090e4
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pypro/modulos/facade.py
Original file line number Diff line number Diff line change
@@ -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]:
Expand All @@ -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)
18 changes: 18 additions & 0 deletions pypro/modulos/migrations/0006_aula_vimeo_id.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
18 changes: 18 additions & 0 deletions pypro/modulos/migrations/0007_alter_vimeo_obrigatorio.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
1 change: 1 addition & 0 deletions pypro/modulos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions pypro/modulos/templates/modulos/aula_detalhe.html
Original file line number Diff line number Diff line change
@@ -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 %}
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="mt-4 mb-3">{{ aula.titulo | default:'Faltando título' }}</h1>
<iframe src="https://player.vimeo.com/video/{{ aula.vimeo_id }}" width="640" height="360" frameborder="0"
allow="autoplay; fullscreen; picture-in-picture" allowfullscreen>
</iframe>
</div>
</div>
</div>
{% endblock body %}
30 changes: 30 additions & 0 deletions pypro/modulos/tests/test_aula_detalhe.py
Original file line number Diff line number Diff line change
@@ -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 }')
3 changes: 2 additions & 1 deletion pypro/modulos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

0 comments on commit cd090e4

Please sign in to comment.